2022-07-01 14:16:10 +00:00
|
|
|
import ctypes as ct
|
2023-01-04 11:50:53 +00:00
|
|
|
import os
|
2022-10-27 11:15:21 +00:00
|
|
|
import torch
|
|
|
|
|
2023-01-02 11:31:43 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from warnings import warn
|
2022-07-01 14:16:10 +00:00
|
|
|
|
2023-01-02 11:31:43 +00:00
|
|
|
from bitsandbytes.cuda_setup.main import CUDASetup
|
2022-08-01 00:47:44 +00:00
|
|
|
|
|
|
|
|
2023-01-02 11:31:43 +00:00
|
|
|
setup = CUDASetup.get_instance()
|
|
|
|
if setup.initialized != True:
|
|
|
|
setup.run_cuda_setup()
|
2022-08-01 00:47:44 +00:00
|
|
|
|
2023-01-02 11:31:43 +00:00
|
|
|
lib = setup.lib
|
2022-07-01 14:16:10 +00:00
|
|
|
try:
|
2022-10-25 15:01:19 +00:00
|
|
|
if lib is None and torch.cuda.is_available():
|
|
|
|
CUDASetup.get_instance().generate_instructions()
|
|
|
|
CUDASetup.get_instance().print_log_stack()
|
|
|
|
raise RuntimeError('''
|
2023-04-12 14:56:52 +00:00
|
|
|
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''')
|
2023-05-07 20:34:03 +00:00
|
|
|
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
|
2023-05-07 20:34:03 +00:00
|
|
|
except AttributeError as ex:
|
2022-11-01 01:04:49 +00:00
|
|
|
warn("The installed version of bitsandbytes was compiled without GPU support. "
|
2023-04-12 14:56:52 +00:00
|
|
|
"8-bit optimizers, 8-bit multiplication, and GPU quantization are unavailable.")
|
2022-07-01 14:16:10 +00:00
|
|
|
COMPILED_WITH_CUDA = False
|
2023-05-07 20:34:03 +00:00
|
|
|
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()
|