Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ipex duplicate importing check #11281

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading