Skip to content

Commit

Permalink
Remove duplicate check for ipex
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyuangong committed Jun 12, 2024
1 parent 10e480e commit efec14c
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions python/llm/src/ipex_llm/utils/ipex_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,6 @@
"imported. Please avoid importing it again!"


def get_calling_package():
"""
Return calling package name, e.g., ipex_llm.transformers
"""
# Get the current stack frame
frame = inspect.currentframe()
# Get the caller's frame
caller_frame = frame.f_back.f_back
# Get the caller's module
module = inspect.getmodule(caller_frame)
if module:
# Return the module's package name
return module.__package__
return None


def custom_ipex_import(name, globals=None, locals=None, fromlist=(), level=0):
"""
Custom import function to avoid importing ipex again
"""
# check import calling pacage
calling_package = get_calling_package()
if calling_package is not None:
return original_import(name, globals, locals, fromlist, level)
# Only check ipex for main thread
if name == "ipex" or name == "intel_extension_for_pytorch":
log4Error.invalidInputError(False,
ipex_duplicate_import_error)
return original_import(name, globals, locals, fromlist, level)


class IPEXImporter:
"""
Auto import Intel Extension for PyTorch as ipex,
Expand Down Expand Up @@ -102,8 +71,6 @@ def import_ipex(self):
ipex_duplicate_import_error)
self.directly_import_ipex()
self.ipex_version = ipex.__version__
# Replace default importer
builtins.__import__ = custom_ipex_import
logging.info("intel_extension_for_pytorch auto imported")

def directly_import_ipex(self):
Expand All @@ -127,13 +94,6 @@ def get_ipex_version(self):
Raises ImportError if cannot import Intel Extension for PyTorch
"""
if self.ipex_version is not None:
return self.ipex_version
# try to import Intel Extension for PyTorch and get version
self.directly_import_ipex()
self.ipex_version = ipex.__version__
# Replace default importer
builtins.__import__ = custom_ipex_import
return self.ipex_version


Expand Down

0 comments on commit efec14c

Please sign in to comment.