Upload lora-scripts/sd-scripts/bitsandbytes_windows/cextension.py with huggingface_hub
Browse files
lora-scripts/sd-scripts/bitsandbytes_windows/cextension.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes as ct
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from warnings import warn
|
| 4 |
+
|
| 5 |
+
from .cuda_setup.main import evaluate_cuda_setup
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class CUDALibrary_Singleton(object):
|
| 9 |
+
_instance = None
|
| 10 |
+
|
| 11 |
+
def __init__(self):
|
| 12 |
+
raise RuntimeError("Call get_instance() instead")
|
| 13 |
+
|
| 14 |
+
def initialize(self):
|
| 15 |
+
binary_name = evaluate_cuda_setup()
|
| 16 |
+
package_dir = Path(__file__).parent
|
| 17 |
+
binary_path = package_dir / binary_name
|
| 18 |
+
|
| 19 |
+
if not binary_path.exists():
|
| 20 |
+
print(f"CUDA SETUP: TODO: compile library for specific version: {binary_name}")
|
| 21 |
+
legacy_binary_name = "libbitsandbytes.so"
|
| 22 |
+
print(f"CUDA SETUP: Defaulting to {legacy_binary_name}...")
|
| 23 |
+
binary_path = package_dir / legacy_binary_name
|
| 24 |
+
if not binary_path.exists():
|
| 25 |
+
print('CUDA SETUP: CUDA detection failed. Either CUDA driver not installed, CUDA not installed, or you have multiple conflicting CUDA libraries!')
|
| 26 |
+
print('CUDA SETUP: If you compiled from source, try again with `make CUDA_VERSION=DETECTED_CUDA_VERSION` for example, `make CUDA_VERSION=113`.')
|
| 27 |
+
raise Exception('CUDA SETUP: Setup Failed!')
|
| 28 |
+
# self.lib = ct.cdll.LoadLibrary(binary_path)
|
| 29 |
+
self.lib = ct.cdll.LoadLibrary(str(binary_path)) # $$$
|
| 30 |
+
else:
|
| 31 |
+
print(f"CUDA SETUP: Loading binary {binary_path}...")
|
| 32 |
+
# self.lib = ct.cdll.LoadLibrary(binary_path)
|
| 33 |
+
self.lib = ct.cdll.LoadLibrary(str(binary_path)) # $$$
|
| 34 |
+
|
| 35 |
+
@classmethod
|
| 36 |
+
def get_instance(cls):
|
| 37 |
+
if cls._instance is None:
|
| 38 |
+
cls._instance = cls.__new__(cls)
|
| 39 |
+
cls._instance.initialize()
|
| 40 |
+
return cls._instance
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
lib = CUDALibrary_Singleton.get_instance().lib
|
| 44 |
+
try:
|
| 45 |
+
lib.cadam32bit_g32
|
| 46 |
+
lib.get_context.restype = ct.c_void_p
|
| 47 |
+
lib.get_cusparse.restype = ct.c_void_p
|
| 48 |
+
COMPILED_WITH_CUDA = True
|
| 49 |
+
except AttributeError:
|
| 50 |
+
warn(
|
| 51 |
+
"The installed version of bitsandbytes was compiled without GPU support. "
|
| 52 |
+
"8-bit optimizers and GPU quantization are unavailable."
|
| 53 |
+
)
|
| 54 |
+
COMPILED_WITH_CUDA = False
|