bitsandbytes-rocm/bitsandbytes/cextension.py

43 lines
1.6 KiB
Python
Raw Normal View History

2022-07-01 14:16:10 +00:00
import ctypes as ct
import os
2022-10-27 11:15:21 +00:00
import torch
from pathlib import Path
from warnings import warn
2022-07-01 14:16:10 +00:00
from bitsandbytes.cuda_setup.main import CUDASetup
setup = CUDASetup.get_instance()
if setup.initialized != True:
setup.run_cuda_setup()
lib = setup.lib
2022-07-01 14:16:10 +00:00
try:
if lib is None and torch.cuda.is_available():
CUDASetup.get_instance().generate_instructions()
CUDASetup.get_instance().print_log_stack()
raise RuntimeError('''
CUDA Setup failed despite GPU 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 CUDA 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/TimDettmers/bitsandbytes/issues''')
lib.cadam32bit_grad_fp32 # runs on an error if the library could not be found -> COMPILED_WITH_CUDA=False
2022-07-22 21:41:05 +00:00
lib.get_context.restype = ct.c_void_p
lib.get_cusparse.restype = ct.c_void_p
2023-05-06 18:14:06 +00:00
lib.cget_managed_ptr.restype = ct.c_void_p
2022-07-01 14:16:10 +00:00
COMPILED_WITH_CUDA = True
except AttributeError as ex:
2022-11-01 01:04:49 +00:00
warn("The installed version of bitsandbytes was compiled without GPU support. "
"8-bit optimizers, 8-bit multiplication, and GPU quantization are unavailable.")
2022-07-01 14:16:10 +00:00
COMPILED_WITH_CUDA = False
print(str(ex))
2023-04-11 19:10:20 +00:00
# print the setup details after checking for errors so we do not print twice
if 'BITSANDBYTES_NOWELCOME' not in os.environ or str(os.environ['BITSANDBYTES_NOWELCOME']) == '0':
setup.print_log_stack()