Skip to content

Commit 30f28b9

Browse files
authored
Merge branch 'main' into cleanup
2 parents 2a91e15 + 8d87c0b commit 30f28b9

File tree

5 files changed

+59
-43
lines changed

5 files changed

+59
-43
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,20 @@ Features:
138138

139139
Bug fixes:
140140
- Fixed a problem where warning messages would be displayed even though everything worked correctly.
141+
142+
143+
### 0.35.2
144+
145+
Bug fixes:
146+
- Fixed a bug where the CUDA setup failed due to a wrong function call.
147+
148+
### 0.35.3
149+
150+
Bug fixes:
151+
- Fixed a bug in the CUDA Setup which led to an incomprehensible error if no GPU was detected.
152+
153+
### 0.35.4
154+
155+
Bug fixes:
156+
- Fixed a bug in the CUDA Setup failed with the cuda runtime was found, but not the cuda library.
157+
- Fixed a bug where not finding the cuda runtime led to an incomprehensible error.

bitsandbytes/cextension.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,14 @@ def get_instance(cls):
116116
CUDASetup.get_instance().generate_instructions()
117117
CUDASetup.get_instance().print_log_stack()
118118
raise RuntimeError('''
119-
CUDA Setup failed despite GPU being available. Inspect the CUDA SETUP outputs to fix your environment!
119+
CUDA Setup failed despite GPU being available. Inspect the CUDA SETUP outputs aboveto fix your environment!
120120
If you cannot find any issues and suspect a bug, please open an issue with detals about your environment:
121121
https://github.com/TimDettmers/bitsandbytes/issues''')
122122
lib.cadam32bit_g32
123123
lib.get_context.restype = ct.c_void_p
124124
lib.get_cusparse.restype = ct.c_void_p
125125
COMPILED_WITH_CUDA = True
126126
except AttributeError:
127-
warn(
128-
"The installed version of bitsandbytes was compiled without GPU support. "
129-
"8-bit optimizers and GPU quantization are unavailable."
130-
)
127+
warn("The installed version of bitsandbytes was compiled without GPU support. "
128+
"8-bit optimizers and GPU quantization are unavailable.")
131129
COMPILED_WITH_CUDA = False

bitsandbytes/cuda_setup/main.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"""
1818

1919
import ctypes
20+
import torch
2021

2122
from bitsandbytes.cextension import CUDASetup
2223

@@ -28,14 +29,17 @@ def check_cuda_result(cuda, result_val):
2829
if result_val != 0:
2930
error_str = ctypes.c_char_p()
3031
cuda.cuGetErrorString(result_val, ctypes.byref(error_str))
31-
CUDASetup.get_instance.add_log_entry(f"CUDA exception! Error code: {error_str.value.decode()}")
32+
CUDASetup.get_instance().add_log_entry(f"CUDA exception! Error code: {error_str.value.decode()}")
3233

34+
35+
# https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART____VERSION.html#group__CUDART____VERSION
3336
def get_cuda_version(cuda, cudart_path):
34-
# https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART____VERSION.html#group__CUDART____VERSION
37+
if cuda is None: return None
38+
3539
try:
3640
cudart = ctypes.CDLL(cudart_path)
3741
except OSError:
38-
CUDASetup.get_instance.add_log_entry(f'ERROR: libcudart.so could not be read from path: {cudart_path}!')
42+
CUDASetup.get_instance().add_log_entry(f'ERROR: libcudart.so could not be read from path: {cudart_path}!')
3943
return None
4044

4145
version = ctypes.c_int()
@@ -55,7 +59,7 @@ def get_cuda_lib_handle():
5559
try:
5660
cuda = ctypes.CDLL("libcuda.so")
5761
except OSError:
58-
CUDA_RUNTIME_LIB.get_instance().add_log_entry('CUDA SETUP: WARNING! libcuda.so not found! Do you have a CUDA driver installed? If you are on a cluster, make sure you are on a CUDA machine!')
62+
CUDASetup.get_instance().add_log_entry('CUDA SETUP: WARNING! libcuda.so not found! Do you have a CUDA driver installed? If you are on a cluster, make sure you are on a CUDA machine!')
5963
return None
6064
check_cuda_result(cuda, cuda.cuInit(0))
6165

@@ -73,7 +77,6 @@ def get_compute_capabilities(cuda):
7377
# bits taken from https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
7478
"""
7579

76-
7780
nGpus = ctypes.c_int()
7881
cc_major = ctypes.c_int()
7982
cc_minor = ctypes.c_int()
@@ -87,9 +90,7 @@ def get_compute_capabilities(cuda):
8790
ref_major = ctypes.byref(cc_major)
8891
ref_minor = ctypes.byref(cc_minor)
8992
# 2. call extern C function to determine CC
90-
check_cuda_result(
91-
cuda, cuda.cuDeviceComputeCapability(ref_major, ref_minor, device)
92-
)
93+
check_cuda_result(cuda, cuda.cuDeviceComputeCapability(ref_major, ref_minor, device))
9394
ccs.append(f"{cc_major.value}.{cc_minor.value}")
9495

9596
return ccs
@@ -102,11 +103,11 @@ def get_compute_capability(cuda):
102103
capabilities are downwards compatible. If no GPUs are detected, it returns
103104
None.
104105
"""
106+
if cuda is None: return None
107+
108+
# TODO: handle different compute capabilities; for now, take the max
105109
ccs = get_compute_capabilities(cuda)
106-
if ccs:
107-
# TODO: handle different compute capabilities; for now, take the max
108-
return ccs[-1]
109-
return None
110+
if ccs: return ccs[-1]
110111

111112

112113
def evaluate_cuda_setup():
@@ -116,28 +117,31 @@ def evaluate_cuda_setup():
116117
#print('Welcome to bitsandbytes. For bug reports, please submit your error trace to: https://github.com/TimDettmers/bitsandbytes/issues')
117118
#print('For effortless bug reporting copy-paste your error into this form: https://docs.google.com/forms/d/e/1FAIpQLScPB8emS3Thkp66nvqwmjTEgxp8Y9ufuWTzFyr9kJ5AoI47dQ/viewform?usp=sf_link')
118119
#print('='*80)
119-
#if not torch.cuda.is_available():
120-
#print('No GPU detected. Loading CPU library...')
121-
#return binary_name
122-
123-
binary_name = "libbitsandbytes_cpu.so"
120+
if not torch.cuda.is_available(): return 'libsbitsandbytes_cpu.so', None, None, None, None
124121

125122
cuda_setup = CUDASetup.get_instance()
126123
cudart_path = determine_cuda_runtime_lib_path()
127-
if cudart_path is None:
128-
cuda_setup.add_log_entry("WARNING: No libcudart.so found! Install CUDA or the cudatoolkit package (anaconda)!", is_warning=True)
129-
return binary_name
130-
131-
cuda_setup.add_log_entry(f"CUDA SETUP: CUDA runtime path found: {cudart_path}")
132124
cuda = get_cuda_lib_handle()
133125
cc = get_compute_capability(cuda)
134-
cuda_setup.add_log_entry(f"CUDA SETUP: Highest compute capability among GPUs detected: {cc}")
135126
cuda_version_string = get_cuda_version(cuda, cudart_path)
136127

128+
failure = False
129+
if cudart_path is None:
130+
failure = True
131+
cuda_setup.add_log_entry("WARNING: No libcudart.so found! Install CUDA or the cudatoolkit package (anaconda)!", is_warning=True)
132+
else:
133+
cuda_setup.add_log_entry(f"CUDA SETUP: CUDA runtime path found: {cudart_path}")
134+
135+
if cc == '' or cc is None:
136+
failure = True
137+
cuda_setup.add_log_entry("WARNING: No GPU detected! Check your CUDA paths. Proceeding to load CPU-only library...", is_warning=True)
138+
else:
139+
cuda_setup.add_log_entry(f"CUDA SETUP: Highest compute capability among GPUs detected: {cc}")
137140

138-
if cc == '':
139-
cuda_setup.add_log_entry("WARNING: No GPU detected! Check your CUDA paths. Processing to load CPU-only library...", is_warning=True)
140-
return binary_name
141+
if cuda is None:
142+
failure = True
143+
else:
144+
cuda_setup.add_log_entry(f'CUDA SETUP: Detected CUDA version {cuda_version_string}')
141145

142146
# 7.5 is the minimum CC vor cublaslt
143147
has_cublaslt = cc in ["7.5", "8.0", "8.6"]
@@ -148,16 +152,13 @@ def evaluate_cuda_setup():
148152

149153
# we use ls -l instead of nvcc to determine the cuda version
150154
# since most installations will have the libcudart.so installed, but not the compiler
151-
cuda_setup.add_log_entry(f'CUDA SETUP: Detected CUDA version {cuda_version_string}')
152155

153-
def get_binary_name():
156+
if failure:
157+
binary_name = "libbitsandbytes_cpu.so"
158+
elif has_cublaslt:
159+
binary_name = f"libbitsandbytes_cuda{cuda_version_string}.so"
160+
else:
154161
"if not has_cublaslt (CC < 7.5), then we have to choose _nocublaslt.so"
155-
bin_base_name = "libbitsandbytes_cuda"
156-
if has_cublaslt:
157-
return f"{bin_base_name}{cuda_version_string}.so"
158-
else:
159-
return f"{bin_base_name}{cuda_version_string}_nocublaslt.so"
160-
161-
binary_name = get_binary_name()
162+
binary_name = f"libbitsandbytes_cuda{cuda_version_string}_nocublaslt.so"
162163

163164
return binary_name, cudart_path, cuda, cc, cuda_version_string

bitsandbytes/cuda_setup/paths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def warn_in_case_of_duplicates(results_paths: Set[Path]) -> None:
6262
"If you get `CUDA error: invalid device function` errors, the above "
6363
"might be the cause and the solution is to make sure only one "
6464
f"{CUDA_RUNTIME_LIB} in the paths that we search based on your env.")
65-
CUDASetup.get_instance.add_log_entry(warning_msg, is_warning=True)
65+
CUDASetup.get_instance().add_log_entry(warning_msg, is_warning=True)
6666

6767

6868
def determine_cuda_runtime_lib_path() -> Union[Path, None]:
@@ -88,7 +88,7 @@ def determine_cuda_runtime_lib_path() -> Union[Path, None]:
8888
if conda_cuda_libs:
8989
return next(iter(conda_cuda_libs))
9090

91-
CUDASetup.get_instance.add_log_entry(f'{candidate_env_vars["CONDA_PREFIX"]} did not contain '
91+
CUDASetup.get_instance().add_log_entry(f'{candidate_env_vars["CONDA_PREFIX"]} did not contain '
9292
f'{CUDA_RUNTIME_LIB} as expected! Searching further paths...', is_warning=True)
9393

9494
if "LD_LIBRARY_PATH" in candidate_env_vars:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def read(fname):
1818

1919
setup(
2020
name=f"bitsandbytes",
21-
version=f"0.35.1",
21+
version=f"0.35.4",
2222
author="Tim Dettmers",
2323
author_email="[email protected]",
2424
description="8-bit optimizers and matrix multiplication routines.",

0 commit comments

Comments
 (0)