Skip to content

Commit ac155f7

Browse files
committed
Merge branch 'main' into bugfixes
2 parents c00402f + e8df8d6 commit ac155f7

File tree

2 files changed

+5
-53
lines changed

2 files changed

+5
-53
lines changed

bitsandbytes/autograd/_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def forward(ctx, A, B, out=None, bias=None, state=MatmulLtState):
323323

324324
# 1. Quantize A
325325
if len(A.shape) == 3:
326-
A = A.view(-1, A.shape[-1]).contiguous()
326+
A = A.reshape(-1, A.shape[-1])
327327
CA, CAt, SCA, SCAt, coo_tensorA = F.double_quant(A.to(torch.float16), threshold=state.threshold)
328328

329329
if state.threshold > 0.0 and coo_tensorA is not None:

bitsandbytes/cuda_setup/main.py

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -280,37 +280,11 @@ def determine_cuda_runtime_lib_path() -> Union[Path, None]:
280280
return next(iter(cuda_runtime_libs)) if cuda_runtime_libs else None
281281

282282

283-
def check_cuda_result(cuda, result_val):
284-
# 3. Check for CUDA errors
285-
if result_val != 0:
286-
error_str = ct.c_char_p()
287-
cuda.cuGetErrorString(result_val, ct.byref(error_str))
288-
if error_str.value is not None:
289-
CUDASetup.get_instance().add_log_entry(f"CUDA exception! Error code: {error_str.value.decode()}")
290-
else:
291-
CUDASetup.get_instance().add_log_entry(f"Unknown CUDA exception! Please check your CUDA install. It might also be that your GPU is too old.")
292-
293-
294283
# https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART____VERSION.html#group__CUDART____VERSION
295284
def get_cuda_version(cuda, cudart_path):
296285
if cuda is None: return None
297286

298-
try:
299-
cudart = ct.CDLL(cudart_path)
300-
except OSError:
301-
CUDASetup.get_instance().add_log_entry(f'ERROR: libcudart.so could not be read from path: {cudart_path}!')
302-
return None
303-
304-
version = ct.c_int()
305-
try:
306-
check_cuda_result(cuda, cudart.cudaRuntimeGetVersion(ct.byref(version)))
307-
except AttributeError as e:
308-
CUDASetup.get_instance().add_log_entry(f'ERROR: {str(e)}')
309-
CUDASetup.get_instance().add_log_entry(f'CUDA SETUP: libcudart.so path is {cudart_path}')
310-
CUDASetup.get_instance().add_log_entry(f'CUDA SETUP: Is seems that your cuda installation is not in your path. See https://github.com/TimDettmers/bitsandbytes/issues/85 for more information.')
311-
version = int(version.value)
312-
major = version//1000
313-
minor = (version-(major*1000))//10
287+
major, minor = map(int, torch.version.cuda.split("."))
314288

315289
if major < 11:
316290
CUDASetup.get_instance().add_log_entry('CUDA SETUP: CUDA version lower than 11 are currently not supported for LLM.int8(). You will be only to use 8-bit optimizers and quantization routines!!')
@@ -325,37 +299,15 @@ def get_cuda_lib_handle():
325299
except OSError:
326300
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!')
327301
return None
328-
check_cuda_result(cuda, cuda.cuInit(0))
329302

330303
return cuda
331304

332305

333306
def get_compute_capabilities(cuda):
334-
"""
335-
1. find libcuda.so library (GPU driver) (/usr/lib)
336-
init_device -> init variables -> call function by reference
337-
2. call extern C function to determine CC
338-
(https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__DEVICE__DEPRECATED.html)
339-
3. Check for CUDA errors
340-
https://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api
341-
# bits taken from https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
342-
"""
343-
344-
nGpus = ct.c_int()
345-
cc_major = ct.c_int()
346-
cc_minor = ct.c_int()
347-
348-
device = ct.c_int()
349-
350-
check_cuda_result(cuda, cuda.cuDeviceGetCount(ct.byref(nGpus)))
351307
ccs = []
352-
for i in range(nGpus.value):
353-
check_cuda_result(cuda, cuda.cuDeviceGet(ct.byref(device), i))
354-
ref_major = ct.byref(cc_major)
355-
ref_minor = ct.byref(cc_minor)
356-
# 2. call extern C function to determine CC
357-
check_cuda_result(cuda, cuda.cuDeviceComputeCapability(ref_major, ref_minor, device))
358-
ccs.append(f"{cc_major.value}.{cc_minor.value}")
308+
for i in range(torch.cuda.device_count()):
309+
cc_major, cc_minor = torch.cuda.get_device_capability(torch.cuda.device(i))
310+
ccs.append(f"{cc_major}.{cc_minor}")
359311

360312
return ccs
361313

0 commit comments

Comments
 (0)