First pass
Browse files- llm.py +20 -8
- requirements.txt +6 -0
llm.py
CHANGED
|
@@ -47,19 +47,31 @@ _llm = None
|
|
| 47 |
|
| 48 |
|
| 49 |
def _preload_cuda_libs():
|
| 50 |
-
"""
|
| 51 |
-
CUDA wheel can resolve
|
|
|
|
|
|
|
| 52 |
import ctypes
|
| 53 |
import glob
|
|
|
|
|
|
|
| 54 |
|
|
|
|
| 55 |
try:
|
| 56 |
-
import
|
|
|
|
| 57 |
except Exception:
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
try:
|
| 64 |
ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL)
|
| 65 |
except OSError:
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
def _preload_cuda_libs():
|
| 50 |
+
"""Load the CUDA runtime libs (libcudart.so.12, libcublas*, ...) RTLD_GLOBAL by full path
|
| 51 |
+
so the prebuilt llama.cpp CUDA wheel can resolve them. They ship in the nvidia-*-cu12 pip
|
| 52 |
+
packages and inside torch/lib, but neither is on the dynamic loader's search path. No-op
|
| 53 |
+
for anything not found. Order matters: cudart before cublasLt before cublas."""
|
| 54 |
import ctypes
|
| 55 |
import glob
|
| 56 |
+
import os
|
| 57 |
+
import site
|
| 58 |
|
| 59 |
+
dirs = []
|
| 60 |
try:
|
| 61 |
+
import torch
|
| 62 |
+
dirs.append(os.path.join(os.path.dirname(torch.__file__), "lib"))
|
| 63 |
except Exception:
|
| 64 |
+
pass
|
| 65 |
+
site_dirs = []
|
| 66 |
+
if hasattr(site, "getsitepackages"):
|
| 67 |
+
site_dirs += site.getsitepackages()
|
| 68 |
+
site_dirs.append(os.path.dirname(os.path.dirname(os.__file__))) # fallback
|
| 69 |
+
for sp in dict.fromkeys(site_dirs):
|
| 70 |
+
dirs += glob.glob(os.path.join(sp, "nvidia", "*", "lib"))
|
| 71 |
+
|
| 72 |
+
for prefix in ("libcudart", "libnvrtc", "libcublasLt", "libcublas", "libcudnn"):
|
| 73 |
+
for d in dict.fromkeys(dirs):
|
| 74 |
+
for lib in sorted(glob.glob(os.path.join(d, prefix + "*.so*"))):
|
| 75 |
try:
|
| 76 |
ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL)
|
| 77 |
except OSError:
|
requirements.txt
CHANGED
|
@@ -7,6 +7,12 @@ spaces
|
|
| 7 |
transformers>=4.44.2
|
| 8 |
accelerate
|
| 9 |
torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pillow
|
| 11 |
hf-transfer
|
| 12 |
huggingface-hub
|
|
|
|
| 7 |
transformers>=4.44.2
|
| 8 |
accelerate
|
| 9 |
torch
|
| 10 |
+
# CUDA runtime libs the prebuilt cu124 llama-cpp-python wheel links against (libcudart.so.12,
|
| 11 |
+
# libcublas.so.12, ...). Installed explicitly so the .so files definitely exist on disk; llm.py
|
| 12 |
+
# then preloads them by full path. (libcudart.so.12 is ABI-compatible across all CUDA 12.x.)
|
| 13 |
+
nvidia-cuda-runtime-cu12
|
| 14 |
+
nvidia-cublas-cu12
|
| 15 |
+
nvidia-cuda-nvrtc-cu12
|
| 16 |
pillow
|
| 17 |
hf-transfer
|
| 18 |
huggingface-hub
|