From badb0978ebfa1a6aad88d1f34347c7e3285f6702 Mon Sep 17 00:00:00 2001 From: James Wyatt Date: Mon, 25 Sep 2023 01:25:24 +1000 Subject: [PATCH 1/4] fix library loading Signed-off-by: Won-Kyu Park --- bitsandbytes/cuda_setup/main.py | 24 +++++++++++++++--------- setup.py | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bitsandbytes/cuda_setup/main.py b/bitsandbytes/cuda_setup/main.py index 6fa671e63..935d782c9 100644 --- a/bitsandbytes/cuda_setup/main.py +++ b/bitsandbytes/cuda_setup/main.py @@ -114,7 +114,9 @@ def manual_override(self): 'For example by adding the following to your .bashrc: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: Date: Wed, 15 Nov 2023 08:44:30 +0900 Subject: [PATCH 2/4] fixed library loading * use os.pathsep --- bitsandbytes/__main__.py | 2 +- bitsandbytes/cuda_setup/env_vars.py | 2 +- bitsandbytes/cuda_setup/main.py | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bitsandbytes/__main__.py b/bitsandbytes/__main__.py index ebbf2653e..6a7136ef6 100644 --- a/bitsandbytes/__main__.py +++ b/bitsandbytes/__main__.py @@ -67,7 +67,7 @@ def generate_bug_report_information(): 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(':')): + for path in set(lib_path.split(os.pathsep)): try: if isdir(path): print_header(f"{path} CUDA PATHS") diff --git a/bitsandbytes/cuda_setup/env_vars.py b/bitsandbytes/cuda_setup/env_vars.py index e8268fcaa..4b2549653 100644 --- a/bitsandbytes/cuda_setup/env_vars.py +++ b/bitsandbytes/cuda_setup/env_vars.py @@ -26,7 +26,7 @@ def to_be_ignored(env_var: str, value: str) -> bool: def might_contain_a_path(candidate: str) -> bool: - return "/" in candidate + return os.sep in candidate def is_active_conda_env(env_var: str) -> bool: diff --git a/bitsandbytes/cuda_setup/main.py b/bitsandbytes/cuda_setup/main.py index 935d782c9..af32819df 100644 --- a/bitsandbytes/cuda_setup/main.py +++ b/bitsandbytes/cuda_setup/main.py @@ -19,6 +19,7 @@ import ctypes as ct import os import errno +import platform import torch from warnings import warn from itertools import product @@ -31,7 +32,11 @@ # 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: list = ["libcudart.so", 'libcudart.so.11.0', 'libcudart.so.12.0', 'libcudart.so.12.1', 'libcudart.so.12.2'] +system = platform.system() +if system == 'Windows': + CUDA_RUNTIME_LIBS: list = ["nvcuda.dll"] +else: # Linux or other + CUDA_RUNTIME_LIBS: list = ["libcudart.so", 'libcudart.so.11.0', 'libcudart.so.12.0', 'libcudart.so.12.1', 'libcudart.so.12.2'] # this is a order list of backup paths to search CUDA in, if it cannot be found in the main environmental paths backup_paths = [] @@ -193,7 +198,7 @@ def is_cublasLt_compatible(cc): return has_cublaslt def extract_candidate_paths(paths_list_candidate: str) -> Set[Path]: - return {Path(ld_path) for ld_path in paths_list_candidate.split(":") if ld_path} + return {Path(ld_path) for ld_path in paths_list_candidate.split(os.pathsep) if ld_path} def remove_non_existent_dirs(candidate_paths: Set[Path]) -> Set[Path]: From 6812e68ffced64c32421a76b096b2203041b62c0 Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Thu, 16 Nov 2023 22:58:14 +0900 Subject: [PATCH 3/4] use glob(), search CUDA_PATH --- bitsandbytes/__main__.py | 45 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/bitsandbytes/__main__.py b/bitsandbytes/__main__.py index 6a7136ef6..05dce5ac7 100644 --- a/bitsandbytes/__main__.py +++ b/bitsandbytes/__main__.py @@ -11,34 +11,18 @@ HEADER_WIDTH = 60 -def execute_and_return(command_string: str) -> Tuple[str, str]: - def _decode(subprocess_err_out_tuple): - return tuple( - to_decode.decode("UTF-8").strip() - for to_decode in subprocess_err_out_tuple - ) - - def execute_and_return_decoded_std_streams(command_string): - return _decode( - subprocess.Popen( - shlex.split(command_string), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ).communicate() - ) - - std_out, std_err = execute_and_return_decoded_std_streams(command_string) - return std_out, std_err def find_file_recursive(folder, filename): - folder = shlex.quote(folder) - filename = shlex.quote(filename) - cmd = f'find {folder} -name {filename}' - out, err = execute_and_return(cmd) - if len(err) > 0: - raise RuntimeError('Something when wrong when trying to find file. Maybe you do not have a linux system?') + 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. {e}') - return out + return outs def generate_bug_report_information(): @@ -48,18 +32,23 @@ def generate_bug_report_information(): print('') if 'CONDA_PREFIX' in os.environ: - paths = find_file_recursive(os.environ['CONDA_PREFIX'], '*cuda*so') + 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*so') + 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*so') + paths = find_file_recursive(os.getcwd(), '*cuda*') print_header("WORKING DIRECTORY CUDA PATHS") print(paths) print('') From 3ede454d42b3286b13bda81627857961e124f728 Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Tue, 2 Jan 2024 17:03:21 +0900 Subject: [PATCH 4/4] call find_file_recursive() without ext --- bitsandbytes/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitsandbytes/__main__.py b/bitsandbytes/__main__.py index 05dce5ac7..8f58e1665 100644 --- a/bitsandbytes/__main__.py +++ b/bitsandbytes/__main__.py @@ -60,7 +60,7 @@ def generate_bug_report_information(): try: if isdir(path): print_header(f"{path} CUDA PATHS") - paths = find_file_recursive(path, '*cuda*so') + paths = find_file_recursive(path, '*cuda*') print(paths) except: print(f'Could not read LD_LIBRARY_PATH: {path}')