Meteord commited on
Commit
27bd66f
·
verified ·
1 Parent(s): 5abb2fb

Sync from GitHub via hub-sync

Browse files
app/backend/minicpm_llama_cpp.py CHANGED
@@ -204,27 +204,43 @@ def _load_llama_cached(
204
 
205
 
206
  def _preload_cuda_runtime() -> str:
207
- candidates = _cuda_runtime_library_candidates()
 
208
  errors = []
209
  for candidate in candidates:
210
  try:
211
  ctypes.CDLL(str(candidate), mode=ctypes.RTLD_GLOBAL)
212
- return str(candidate)
213
  except OSError as exc:
214
  errors.append(f"{candidate}: {exc}")
215
  if errors:
216
  logger.debug("CUDA runtime preload attempts failed: %s", " | ".join(errors))
217
- return ""
218
 
219
 
220
- def _cuda_runtime_library_candidates() -> list[Path]:
221
  candidates: list[Path] = []
222
- spec = importlib.util.find_spec("nvidia.cuda_runtime")
223
- if spec and spec.submodule_search_locations:
224
- for location in spec.submodule_search_locations:
225
- candidates.append(Path(location) / "lib" / "libcudart.so.12")
 
 
 
 
 
 
 
226
  for root in [*site.getsitepackages(), site.getusersitepackages()]:
227
- candidates.append(Path(root) / "nvidia" / "cuda_runtime" / "lib" / "libcudart.so.12")
 
 
 
 
 
 
 
 
228
  return [candidate for candidate in candidates if candidate.exists()]
229
 
230
 
 
204
 
205
 
206
  def _preload_cuda_runtime() -> str:
207
+ candidates = _cuda_library_candidates()
208
+ loaded = []
209
  errors = []
210
  for candidate in candidates:
211
  try:
212
  ctypes.CDLL(str(candidate), mode=ctypes.RTLD_GLOBAL)
213
+ loaded.append(str(candidate))
214
  except OSError as exc:
215
  errors.append(f"{candidate}: {exc}")
216
  if errors:
217
  logger.debug("CUDA runtime preload attempts failed: %s", " | ".join(errors))
218
+ return os.pathsep.join(loaded)
219
 
220
 
221
+ def _cuda_library_candidates() -> list[Path]:
222
  candidates: list[Path] = []
223
+ package_libraries = [
224
+ ("nvidia.nvjitlink", "libnvJitLink.so.12"),
225
+ ("nvidia.cuda_runtime", "libcudart.so.12"),
226
+ ("nvidia.cublas", "libcublasLt.so.12"),
227
+ ("nvidia.cublas", "libcublas.so.12"),
228
+ ]
229
+ for package, library in package_libraries:
230
+ spec = importlib.util.find_spec(package)
231
+ if spec and spec.submodule_search_locations:
232
+ for location in spec.submodule_search_locations:
233
+ candidates.append(Path(location) / "lib" / library)
234
  for root in [*site.getsitepackages(), site.getusersitepackages()]:
235
+ base = Path(root) / "nvidia"
236
+ candidates.extend(
237
+ [
238
+ base / "nvjitlink" / "lib" / "libnvJitLink.so.12",
239
+ base / "cuda_runtime" / "lib" / "libcudart.so.12",
240
+ base / "cublas" / "lib" / "libcublasLt.so.12",
241
+ base / "cublas" / "lib" / "libcublas.so.12",
242
+ ]
243
+ )
244
  return [candidate for candidate in candidates if candidate.exists()]
245
 
246
 
requirements.txt CHANGED
@@ -7,4 +7,6 @@ pydantic-settings>=2.14.1
7
  huggingface-hub>=0.27.0
8
  spaces
9
  nvidia-cuda-runtime-cu12
 
 
10
  llama-cpp-python
 
7
  huggingface-hub>=0.27.0
8
  spaces
9
  nvidia-cuda-runtime-cu12
10
+ nvidia-cublas-cu12
11
+ nvidia-nvjitlink-cu12
12
  llama-cpp-python