diff --git a/bitsandbytes/__main__.py b/bitsandbytes/__main__.py index af5c1c523..61b42e78f 100644 --- a/bitsandbytes/__main__.py +++ b/bitsandbytes/__main__.py @@ -1,5 +1,5 @@ +import glob import os -from os.path import isdir import sys from warnings import warn @@ -8,17 +8,9 @@ HEADER_WIDTH = 60 -def find_file_recursive(folder, filename): - import glob - outs = [] - try: - for ext in ["so", "dll", "dylib"]: - out = glob.glob(os.path.join(folder, "**", filename + ext)) - outs.extend(out) - except Exception as e: - raise RuntimeError('Error: Something when wrong when trying to find file.') from e - - return outs +def find_dynamic_library(folder, filename): + for ext in ("so", "dll", "dylib"): + yield from glob.glob(os.path.join(folder, "**", filename + ext)) def generate_bug_report_information(): @@ -27,40 +19,25 @@ def generate_bug_report_information(): print_header("") print('') - if 'CONDA_PREFIX' in os.environ: - paths = find_file_recursive(os.environ['CONDA_PREFIX'], '*cuda*') - print_header("ANACONDA CUDA PATHS") - print(paths) - print('') - if isdir('/usr/local/'): - paths = find_file_recursive('/usr/local', '*cuda*') - print_header("/usr/local CUDA PATHS") - print(paths) - print('') - if 'CUDA_PATH' in os.environ and isdir(os.environ['CUDA_PATH']): - paths = find_file_recursive(os.environ['CUDA_PATH'], '*cuda*') - print_header("CUDA PATHS") - print(paths) - print('') - - if isdir(os.getcwd()): - paths = find_file_recursive(os.getcwd(), '*cuda*') - print_header("WORKING DIRECTORY CUDA PATHS") - print(paths) - print('') - - print_header("LD_LIBRARY CUDA PATHS") - if 'LD_LIBRARY_PATH' in os.environ: - lib_path = os.environ['LD_LIBRARY_PATH'].strip() - for path in set(lib_path.split(os.pathsep)): - try: - if isdir(path): - print_header(f"{path} CUDA PATHS") - paths = find_file_recursive(path, '*cuda*') - print(paths) - except Exception as e: - print(f'Could not read LD_LIBRARY_PATH: {path} ({e})') - print('') + path_sources = [ + ("ANACONDA CUDA PATHS", os.environ.get("CONDA_PREFIX")), + ("/usr/local CUDA PATHS", "/usr/local"), + ("CUDA PATHS", os.environ.get("CUDA_PATH")), + ("WORKING DIRECTORY CUDA PATHS", os.getcwd()), + ] + try: + ld_library_path = os.environ.get("LD_LIBRARY_PATH") + if ld_library_path: + for path in set(ld_library_path.strip().split(os.pathsep)): + path_sources.append((f"LD_LIBRARY_PATH {path} CUDA PATHS", path)) + except Exception as e: + print(f"Could not parse LD_LIBRARY_PATH: {e}") + + for name, path in path_sources: + if path and os.path.isdir(path): + print_header(name) + print(list(find_dynamic_library(path, '*cuda*'))) + print("") def print_header( diff --git a/bitsandbytes/cuda_setup/main.py b/bitsandbytes/cuda_setup/main.py index a34385b1f..1669b08e1 100644 --- a/bitsandbytes/cuda_setup/main.py +++ b/bitsandbytes/cuda_setup/main.py @@ -28,19 +28,17 @@ from .env_vars import get_potentially_lib_path_containing_env_vars -# these are the most common libs names -# libcudart.so is missing by default for a conda install with PyTorch 2.0 and instead -# we have libcudart.so.11.0 which causes a lot of errors before -# not sure if libcudart.so.12.0 exists in pytorch installs, but it does not hurt -system = platform.system() -if system == 'Windows': +if platform.system() == 'Windows': # Windows CUDA_RUNTIME_LIBS = ["nvcuda.dll"] -else: # Linux or other - CUDA_RUNTIME_LIBS = ["libcudart.so", 'libcudart.so.11.0', 'libcudart.so.12.0', 'libcudart.so.12.1', 'libcudart.so.12.2'] + DYNAMIC_LIBRARY_SUFFIX = ".dll" +else: # Linux or other + # these are the most common libs names + # libcudart.so is missing by default for a conda install with PyTorch 2.0 and instead + # we have libcudart.so.11.0 which causes a lot of errors before + # not sure if libcudart.so.12.0 exists in pytorch installs, but it does not hurt + CUDA_RUNTIME_LIBS = ["libcudart.so", "libcudart.so.11.0", "libcudart.so.12.0", "libcudart.so.12.1", "libcudart.so.12.2"] + DYNAMIC_LIBRARY_SUFFIX = ".so" -# this is a order list of backup paths to search CUDA in, if it cannot be found in the main environmental paths -backup_paths = [] -backup_paths.append('$CONDA_PREFIX/lib/libcudart.so.11.0') class CUDASetup: _instance = None @@ -108,22 +106,30 @@ def initialize(self): self.error = False def manual_override(self): - if torch.cuda.is_available(): - if 'BNB_CUDA_VERSION' in os.environ: - if len(os.environ['BNB_CUDA_VERSION']) > 0: - warn( - f'\n\n{"=" * 80}\n' - 'WARNING: Manual override via BNB_CUDA_VERSION env variable detected!\n' - 'BNB_CUDA_VERSION=XXX can be used to load a bitsandbytes version that is different from the PyTorch CUDA version.\n' - 'If this was unintended set the BNB_CUDA_VERSION variable to an empty string: export BNB_CUDA_VERSION=\n' - 'If you use the manual override make sure the right libcudart.so is in your LD_LIBRARY_PATH\n' - 'For example by adding the following to your .bashrc: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: