From cd6d479c55e480317d06e48a1ae8d427040c252b Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Sat, 8 Feb 2025 12:43:42 +0000 Subject: [PATCH 1/7] fix intel cpu/xpu warning Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 2 +- docs/source/installation.mdx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index ec329cbb6..b54b20c7e 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -130,8 +130,8 @@ def get_native_library() -> BNBNativeLibrary: lib = get_native_library() except Exception as e: lib = None - logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) if torch.cuda.is_available(): + logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) logger.warning( f""" {BNB_BACKEND} Setup failed despite {BNB_BACKEND} being available. Please run the following command to get more information: diff --git a/docs/source/installation.mdx b/docs/source/installation.mdx index 79613856f..57962f4d6 100644 --- a/docs/source/installation.mdx +++ b/docs/source/installation.mdx @@ -331,10 +331,10 @@ pip install -e . # `-e` for "editable" install, when developing BNB (otherwise -#### Intel CPU +#### Intel CPU / XPU > [!TIP] -> Intel CPU backend only supports building from source; for now, please follow the instructions below. +> Intel CPU / XPU backend only supports building from source; for now, please follow the instructions below. Similar to the CUDA case, you can compile bitsandbytes from source for Linux and Windows systems. From eadf0f35719627bdfd588a9b9776c56df4d86036 Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Sat, 8 Feb 2025 12:53:52 +0000 Subject: [PATCH 2/7] fix error log Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index b54b20c7e..4f1020580 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -93,6 +93,11 @@ def __init__(self, lib: ct.CDLL): def get_native_library() -> BNBNativeLibrary: + from bitsandbytes.backends.cpu_xpu_common import ipex_cpu, ipex_xpu + + if ipex_cpu or ipex_xpu: + return None + binary_path = PACKAGE_DIR / f"libbitsandbytes_cpu{DYNAMIC_LIBRARY_SUFFIX}" cuda_specs = get_cuda_specs() if cuda_specs: @@ -130,8 +135,8 @@ def get_native_library() -> BNBNativeLibrary: lib = get_native_library() except Exception as e: lib = None + logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) if torch.cuda.is_available(): - logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) logger.warning( f""" {BNB_BACKEND} Setup failed despite {BNB_BACKEND} being available. Please run the following command to get more information: From b79837630ba38b499f98714715aa8c9da423cb4f Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Tue, 11 Feb 2025 17:32:41 +0000 Subject: [PATCH 3/7] fix lib Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 57 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index 3ab8eb4e4..6ef465cb1 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -6,6 +6,7 @@ import torch +from bitsandbytes.backends.cpu_xpu_common import ipex_cpu, ipex_xpu from bitsandbytes.consts import DYNAMIC_LIBRARY_SUFFIX, PACKAGE_DIR from bitsandbytes.cuda_specs import CUDASpecs, get_cuda_specs, get_rocm_gpu_arch from bitsandbytes.npu_specs import get_npu_specs @@ -98,30 +99,34 @@ def get_native_library() -> BNBNativeLibrary: ROCM_GPU_ARCH = get_rocm_gpu_arch() -try: - if torch.version.hip: - hip_major, hip_minor = map(int, torch.version.hip.split(".")[0:2]) - HIP_ENVIRONMENT, BNB_HIP_VERSION = True, hip_major * 100 + hip_minor - BNB_HIP_VERSION_SHORT = f"{hip_major}{hip_minor}" - BNB_BACKEND = "ROCm" - else: - HIP_ENVIRONMENT, BNB_HIP_VERSION = False, 0 - BNB_HIP_VERSION_SHORT = "" - BNB_BACKEND = "CUDA" - - lib = get_native_library() -except Exception as e: - lib = None - logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) - if torch.cuda.is_available(): - logger.warning( - f""" -{BNB_BACKEND} Setup failed despite {BNB_BACKEND} being available. Please run the following command to get more information: - -python -m bitsandbytes -Inspect the output of the command and see if you can locate {BNB_BACKEND} libraries. You might need to add them -to your LD_LIBRARY_PATH. If you suspect a bug, please take the information from python -m bitsandbytes -and open an issue at: https://github.com/bitsandbytes-foundation/bitsandbytes/issues -""", - ) +if ipex_cpu or ipex_xpu: + lib = None +else: + try: + if torch.version.hip: + hip_major, hip_minor = map(int, torch.version.hip.split(".")[0:2]) + HIP_ENVIRONMENT, BNB_HIP_VERSION = True, hip_major * 100 + hip_minor + BNB_HIP_VERSION_SHORT = f"{hip_major}{hip_minor}" + BNB_BACKEND = "ROCm" + else: + HIP_ENVIRONMENT, BNB_HIP_VERSION = False, 0 + BNB_HIP_VERSION_SHORT = "" + BNB_BACKEND = "CUDA" + + lib = get_native_library() + except Exception as e: + lib = None + logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) + if torch.cuda.is_available(): + logger.warning( + f""" + {BNB_BACKEND} Setup failed despite {BNB_BACKEND} being available. Please run the following command to get more information: + + python -m bitsandbytes + + Inspect the output of the command and see if you can locate {BNB_BACKEND} libraries. You might need to add them + to your LD_LIBRARY_PATH. If you suspect a bug, please take the information from python -m bitsandbytes + and open an issue at: https://github.com/bitsandbytes-foundation/bitsandbytes/issues + """, + ) From 540a717bbb4173624d97deb1e72cb1c6c63f57c8 Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Wed, 12 Feb 2025 08:44:43 +0000 Subject: [PATCH 4/7] rm return Nonr Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index 6ef465cb1..296cdde13 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -71,11 +71,6 @@ def __init__(self, lib: ct.CDLL): def get_native_library() -> BNBNativeLibrary: - from bitsandbytes.backends.cpu_xpu_common import ipex_cpu, ipex_xpu - - if ipex_cpu or ipex_xpu: - return None - binary_path = PACKAGE_DIR / f"libbitsandbytes_cpu{DYNAMIC_LIBRARY_SUFFIX}" cuda_specs = get_cuda_specs() if cuda_specs: From 63dbf45fb0f52e47aa7a2c62886d5edf12b430f7 Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Wed, 12 Feb 2025 08:46:54 +0000 Subject: [PATCH 5/7] error log only without ipex Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index 296cdde13..ffc88d276 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -95,23 +95,21 @@ def get_native_library() -> BNBNativeLibrary: ROCM_GPU_ARCH = get_rocm_gpu_arch() -if ipex_cpu or ipex_xpu: +try: + if torch.version.hip: + hip_major, hip_minor = map(int, torch.version.hip.split(".")[0:2]) + HIP_ENVIRONMENT, BNB_HIP_VERSION = True, hip_major * 100 + hip_minor + BNB_HIP_VERSION_SHORT = f"{hip_major}{hip_minor}" + BNB_BACKEND = "ROCm" + else: + HIP_ENVIRONMENT, BNB_HIP_VERSION = False, 0 + BNB_HIP_VERSION_SHORT = "" + BNB_BACKEND = "CUDA" + + lib = get_native_library() +except Exception as e: lib = None -else: - try: - if torch.version.hip: - hip_major, hip_minor = map(int, torch.version.hip.split(".")[0:2]) - HIP_ENVIRONMENT, BNB_HIP_VERSION = True, hip_major * 100 + hip_minor - BNB_HIP_VERSION_SHORT = f"{hip_major}{hip_minor}" - BNB_BACKEND = "ROCm" - else: - HIP_ENVIRONMENT, BNB_HIP_VERSION = False, 0 - BNB_HIP_VERSION_SHORT = "" - BNB_BACKEND = "CUDA" - - lib = get_native_library() - except Exception as e: - lib = None + if not ipex_cpu and not ipex_xpu: logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) if torch.cuda.is_available(): logger.warning( From ade64d0d33e187beb543ceae5963161e2fdc3f36 Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Thu, 20 Feb 2025 13:09:21 +0000 Subject: [PATCH 6/7] fix import eerror Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index ffc88d276..df553b3b4 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -6,7 +6,6 @@ import torch -from bitsandbytes.backends.cpu_xpu_common import ipex_cpu, ipex_xpu from bitsandbytes.consts import DYNAMIC_LIBRARY_SUFFIX, PACKAGE_DIR from bitsandbytes.cuda_specs import CUDASpecs, get_cuda_specs, get_rocm_gpu_arch from bitsandbytes.npu_specs import get_npu_specs @@ -94,6 +93,11 @@ def get_native_library() -> BNBNativeLibrary: ROCM_GPU_ARCH = get_rocm_gpu_arch() +try: + import intel_extension_for_pytorch + is_ipex_available = True +except: + is_ipex_available = False try: if torch.version.hip: @@ -109,7 +113,7 @@ def get_native_library() -> BNBNativeLibrary: lib = get_native_library() except Exception as e: lib = None - if not ipex_cpu and not ipex_xpu: + if not is_ipex_available: logger.error(f"Could not load bitsandbytes native library: {e}", exc_info=True) if torch.cuda.is_available(): logger.warning( From 30e33dcca58451ab13ac84b33787dd7a28513725 Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Thu, 20 Feb 2025 13:15:43 +0000 Subject: [PATCH 7/7] fix format Signed-off-by: jiqing-feng --- bitsandbytes/cextension.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/cextension.py b/bitsandbytes/cextension.py index df553b3b4..e2d8295b1 100644 --- a/bitsandbytes/cextension.py +++ b/bitsandbytes/cextension.py @@ -94,9 +94,11 @@ def get_native_library() -> BNBNativeLibrary: ROCM_GPU_ARCH = get_rocm_gpu_arch() try: - import intel_extension_for_pytorch + import intel_extension_for_pytorch as ipex + + assert ipex._C._has_cpu() or ipex._C._has_xpu() is_ipex_available = True -except: +except Exception: is_ipex_available = False try: