From 164307c3894398b3c7bd5f01380a687ec574b219 Mon Sep 17 00:00:00 2001 From: leonardozcm Date: Tue, 21 Jan 2025 15:28:00 +0800 Subject: [PATCH 1/2] Intercept ocl environment variables before running --- python/llm/scripts/activate-unset-ocl.sh | 3 +++ python/llm/setup.py | 27 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 python/llm/scripts/activate-unset-ocl.sh diff --git a/python/llm/scripts/activate-unset-ocl.sh b/python/llm/scripts/activate-unset-ocl.sh new file mode 100644 index 00000000000..8d6d54ce57b --- /dev/null +++ b/python/llm/scripts/activate-unset-ocl.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +unset OCL_ICD_VENDORS \ No newline at end of file diff --git a/python/llm/setup.py b/python/llm/setup.py index d4c27a4bd32..f18a0ba22b8 100644 --- a/python/llm/setup.py +++ b/python/llm/setup.py @@ -211,6 +211,30 @@ def download_libs(url: str, change_permission=False): if change_permission: os.chmod(libso_file, 0o775) +from setuptools.command.install import install + +class IPEXLLMInstallCommand(install): + def run(self): + install.run(self) + self.copy_activate_script() + + def copy_activate_script(self): + conda_prefix = os.environ.get('CONDA_PREFIX') + if conda_prefix: + activate_d_dir = os.path.join(conda_prefix, 'etc', 'conda', 'activate.d') + if not os.path.exists(activate_d_dir): + os.makedirs(activate_d_dir) + script_src = os.path.join(os.path.dirname(__file__), 'scripts', 'activate-unset-ocl.sh') + script_dst = os.path.join(activate_d_dir, 'activate-unset-ocl.sh') + self.copy_file(script_src, script_dst) + else: + print("CONDA_PREFIX environment variable is not set. Are you sure you're in a conda environment?") + + def copy_file(self, src, dst): + import shutil + shutil.copy(src, dst) + print(f"Copied {src} to {dst}") + def setup_package(): package_data = {} @@ -389,6 +413,9 @@ def setup_package(): 'Linux': ['src/ipex_llm/cli/llm-cli', 'src/ipex_llm/cli/llm-chat', 'scripts/ipex-llm-init'], 'Windows': ['src/ipex_llm/cli/llm-cli.ps1', 'src/ipex_llm/cli/llm-chat.ps1', 'scripts/ipex-llm-init.bat'], }[platform_name], + cmdclass={ + 'install': IPEXLLMInstallCommand, + }, platforms=['windows'] ) From 806c240acd3ca4f63782463fe21e5967849bc959 Mon Sep 17 00:00:00 2001 From: leonardozcm Date: Tue, 21 Jan 2025 15:43:54 +0800 Subject: [PATCH 2/2] Intercept ocl environment variables before running --- python/llm/setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/llm/setup.py b/python/llm/setup.py index f18a0ba22b8..aecd9078f2d 100644 --- a/python/llm/setup.py +++ b/python/llm/setup.py @@ -216,7 +216,8 @@ def download_libs(url: str, change_permission=False): class IPEXLLMInstallCommand(install): def run(self): install.run(self) - self.copy_activate_script() + if not platform.platform().startswith('Windows'): + self.copy_activate_script() def copy_activate_script(self): conda_prefix = os.environ.get('CONDA_PREFIX')