Preload nvidia CUDA libs (RTLD_GLOBAL) so libllama.so finds libcudart on ZeroGPU; eager model download; duration=120
Browse files
app.py
CHANGED
|
@@ -76,26 +76,37 @@ impl Point {
|
|
| 76 |
]
|
| 77 |
|
| 78 |
_llm = None
|
| 79 |
-
_model_path = None
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
|
| 93 |
def get_llm():
|
| 94 |
global _llm
|
| 95 |
if _llm is None:
|
|
|
|
| 96 |
from llama_cpp import Llama
|
| 97 |
_llm = Llama(
|
| 98 |
-
model_path=
|
| 99 |
n_gpu_layers=N_GPU_LAYERS,
|
| 100 |
n_ctx=CTX,
|
| 101 |
n_batch=512,
|
|
@@ -115,7 +126,7 @@ def clean(text: str) -> str:
|
|
| 115 |
return text.rstrip()
|
| 116 |
|
| 117 |
|
| 118 |
-
@gpu(duration=
|
| 119 |
def complete(code, temperature, max_tokens, top_p):
|
| 120 |
if code.strip() == "":
|
| 121 |
return "", code, "*Empty input.*"
|
|
|
|
| 76 |
]
|
| 77 |
|
| 78 |
_llm = None
|
|
|
|
| 79 |
|
| 80 |
+
_model_path = hf_hub_download(
|
| 81 |
+
repo_id=MODEL_REPO,
|
| 82 |
+
filename=MODEL_FILE,
|
| 83 |
+
token=os.environ.get("HF_TOKEN"),
|
| 84 |
+
)
|
| 85 |
|
| 86 |
+
|
| 87 |
+
def _preload_cuda():
|
| 88 |
+
import ctypes
|
| 89 |
+
import glob
|
| 90 |
+
import site
|
| 91 |
+
|
| 92 |
+
dirs = []
|
| 93 |
+
for sp in site.getsitepackages():
|
| 94 |
+
dirs += glob.glob(sp + "/nvidia/*/lib")
|
| 95 |
+
for d in sorted(dirs):
|
| 96 |
+
for so in sorted(glob.glob(d + "/*.so*")):
|
| 97 |
+
try:
|
| 98 |
+
ctypes.CDLL(so, mode=ctypes.RTLD_GLOBAL)
|
| 99 |
+
except OSError:
|
| 100 |
+
pass
|
| 101 |
|
| 102 |
|
| 103 |
def get_llm():
|
| 104 |
global _llm
|
| 105 |
if _llm is None:
|
| 106 |
+
_preload_cuda()
|
| 107 |
from llama_cpp import Llama
|
| 108 |
_llm = Llama(
|
| 109 |
+
model_path=_model_path,
|
| 110 |
n_gpu_layers=N_GPU_LAYERS,
|
| 111 |
n_ctx=CTX,
|
| 112 |
n_batch=512,
|
|
|
|
| 126 |
return text.rstrip()
|
| 127 |
|
| 128 |
|
| 129 |
+
@gpu(duration=120)
|
| 130 |
def complete(code, temperature, max_tokens, top_p):
|
| 131 |
if code.strip() == "":
|
| 132 |
return "", code, "*Empty input.*"
|