Load CUDA library XOR CPU, as the latter contains a subset of symbols of the former.
()
| 346 | |
| 347 | |
| 348 | def get_native_library() -> BNBNativeLibrary: |
| 349 | """ |
| 350 | Load CUDA library XOR CPU, as the latter contains a subset of symbols of the former. |
| 351 | """ |
| 352 | cuda_specs = get_cuda_specs() |
| 353 | binary_path = PACKAGE_DIR / f"libbitsandbytes_cpu{DYNAMIC_LIBRARY_SUFFIX}" |
| 354 | |
| 355 | if cuda_specs: |
| 356 | cuda_binary_path = get_cuda_bnb_library_path(cuda_specs) |
| 357 | |
| 358 | if not cuda_binary_path.exists(): |
| 359 | raise RuntimeError(f"No compatible {BNB_BACKEND} binary found at {cuda_binary_path}") |
| 360 | |
| 361 | binary_path = cuda_binary_path |
| 362 | |
| 363 | if torch._C._has_xpu: |
| 364 | binary_path = get_xpu_bnb_library_path() |
| 365 | |
| 366 | logger.debug(f"Loading bitsandbytes native library from: {binary_path}") |
| 367 | |
| 368 | # Try to load the library - any errors will propagate up |
| 369 | dll = ct.cdll.LoadLibrary(str(binary_path)) |
| 370 | |
| 371 | if hasattr(dll, "get_context"): # only a CUDA-built library exposes this |
| 372 | return CudaBNBNativeLibrary(dll) |
| 373 | |
| 374 | if torch._C._has_xpu: |
| 375 | return XpuBNBNativeLibrary(dll) |
| 376 | |
| 377 | return BNBNativeLibrary(dll) |
| 378 | |
| 379 | |
| 380 | ROCM_GPU_ARCH = get_rocm_gpu_arch() |
no test coverage detected