From 67f0ab592ecf918e0a8b7ea3661fbf70e063dcc8 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Tue, 17 Mar 2026 01:12:55 +0000 Subject: [PATCH] studio: add CUDA lib paths to LD_LIBRARY_PATH for llama-server When llama-server is built with shared libs (setup.sh default), it needs libcudart.so.12 and other CUDA runtime libs. Add /usr/local/cuda/lib64 and targets path to LD_LIBRARY_PATH so the server starts correctly even when CUDA isn't on the system path. --- studio/backend/core/inference/llama_cpp.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index 3a137b8b63..fe7c045df1 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -888,9 +888,18 @@ class LlamaCppBackend: env["PATH"] = ";".join(path_dirs) + ";" + existing_path else: # Linux: set LD_LIBRARY_PATH for shared libs next to the binary + # and CUDA runtime libs (libcudart, libcublas, etc.) + lib_dirs = [binary_dir] + for cuda_lib in [ + "/usr/local/cuda/lib64", + "/usr/local/cuda/targets/x86_64-linux/lib", + ]: + if os.path.isdir(cuda_lib): + lib_dirs.append(cuda_lib) existing_ld = env.get("LD_LIBRARY_PATH", "") + new_ld = ":".join(lib_dirs) env["LD_LIBRARY_PATH"] = ( - f"{binary_dir}:{existing_ld}" if existing_ld else binary_dir + f"{new_ld}:{existing_ld}" if existing_ld else new_ld ) # Pin to selected GPU(s) via CUDA_VISIBLE_DEVICES