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

IPEX Duplicate importer V2 #11310

Merged
merged 10 commits into from
Jun 19, 2024
2 changes: 1 addition & 1 deletion python/llm/src/ipex_llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import sys
import types

# Default is false, set to true to auto importing Intel Extension for PyTorch.
# Default is True, set to False to disable auto importing Intel Extension for PyTorch.
USE_NPU = os.getenv("BIGDL_USE_NPU", 'False').lower() in ('true', '1', 't')
BIGDL_IMPORT_IPEX = os.getenv("BIGDL_IMPORT_IPEX", 'True').lower() in ('true', '1', 't')
BIGDL_IMPORT_IPEX = not USE_NPU and BIGDL_IMPORT_IPEX
Expand Down
8 changes: 7 additions & 1 deletion python/llm/src/ipex_llm/utils/ipex_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
import logging
import builtins
import sys
import os
import inspect
from ipex_llm.utils.common import log4Error


# Default is True, set to False to disable IPEX duplicate checker
IPEX_DUPLICATE_CHECKER = os.getenv("IPEX_DUPLICATE_CHECKER", 'True').lower() in ('true', '1', 't')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to BIGDL_CHECK_DUPLICATE_IMPORT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

RAW_IMPORT = None
IS_IMPORT_REPLACED = False
ipex_duplicate_import_error = "intel_extension_for_pytorch has already been automatically " + \
Expand All @@ -39,6 +42,8 @@ def replace_import():


def revert_import():
if not IPEX_DUPLICATE_CHECKER:
return
global RAW_IMPORT, IS_IMPORT_REPLACED
# Only revert once
if RAW_IMPORT is not None and IS_IMPORT_REPLACED:
Expand Down Expand Up @@ -124,7 +129,8 @@ def import_ipex(self):
self.directly_import_ipex()
self.ipex_version = ipex.__version__
# Replace builtin import to avoid duplicate ipex import
replace_import()
if IPEX_DUPLICATE_CHECKER:
replace_import()
logging.info("intel_extension_for_pytorch auto imported")

def directly_import_ipex(self):
Expand Down
Loading