packaging: llama rebuild stage checks with ldd (libcuda is a runtime library),...

packaging: llama rebuild stage checks with ldd (libcuda is a runtime library), rpc-server script needs no import
Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKm7Z56iKjHgNkHc6VhWKz
parent 22dc3785
......@@ -29,8 +29,10 @@ while [ $# -gt 0 ]; do
shift
done
VER=$("$PYTHON" -c "import llama_cpp; print(llama_cpp.__version__)")
LIBDIR=$("$PYTHON" -c "import llama_cpp, os; print(os.path.join(os.path.dirname(llama_cpp.__file__), 'lib'))")
# Version and lib dir WITHOUT importing the package: a wheel installed
# --no-deps (as the image builds do) cannot be imported before its deps are.
VER=$("$PYTHON" -c "from importlib.metadata import version; print(version('llama-cpp-python'))")
LIBDIR=$("$PYTHON" -c "import importlib.util, os; s=importlib.util.find_spec('llama_cpp'); print(os.path.join(os.path.dirname(s.origin), 'lib'))")
BINDIR=$("$PYTHON" -c "import sys, os; print(os.path.dirname(sys.executable))")
DEST="${DEST:-$BINDIR}"
if [ -z "$CUDA$VULKAN" ]; then
......
......@@ -30,7 +30,7 @@ ENV DEBIAN_FRONTEND=noninteractive FORCE_CMAKE=1 CMAKE_BUILD_PARALLEL_LEVEL=8 MA
CC=gcc CXX=g++ CUDAHOSTCXX=g++
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential ca-certificates cmake curl git libgomp1 libvulkan-dev \
ninja-build pkg-config vulkan-tools glslang-tools glslc \
ninja-build pkg-config vulkan-tools glslang-tools glslc spirv-headers spirv-tools \
&& rm -rf /var/lib/apt/lists/*
RUN set -eux; \
curl -fsSL -o /tmp/python.tar.gz \
......@@ -58,21 +58,26 @@ RUN set -eux; \
--force-reinstall /tmp/llama-wheels/llama_cpp_python-*.whl; \
install -m 755 /tmp/llama-wheels/rpc-server /opt/coderai/python/bin/rpc-server; \
rm -rf /tmp/llama-wheels; \
# The wheel must load in THIS image (its CUDA runtime is on local-libs) and
# carry the RPC backend — a wheel that links a library the image lacks is
# exactly the failure this stage exists to catch before the flatten.
# The wheel must link against THIS image (its CUDA runtime is on local-libs)
# and carry the RPC backend. libcuda.so is the driver — present only at run
# time, mounted by the NVIDIA container runtime — so it is the one library
# that may legitimately be missing here, and the check is ldd, not import.
LD_LIBRARY_PATH=/opt/coderai/local-libs:/usr/local/nvidia/lib64 \
/opt/coderai/python/bin/python3 - <<'PY'
import ctypes, glob, os, llama_cpp
d = os.path.join(os.path.dirname(llama_cpp.__file__), "lib")
libs = [ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL) for p in
(glob.glob(d + "/libggml.so")[:1] + glob.glob(d + "/libggml-base.so")[:1])]
fn = next(getattr(l, "ggml_backend_reg_by_name") for l in libs if hasattr(l, "ggml_backend_reg_by_name"))
fn.restype = ctypes.c_void_p; fn.argtypes = [ctypes.c_char_p]
try:
getattr(libs[0], "ggml_backend_load_all")()
except Exception:
pass
assert fn(b"RPC"), "RPC backend missing from the rebuilt llama-cpp-python"
print("llama-cpp-python", llama_cpp.__version__, "with RPC backend: OK")
import glob, os, re, subprocess, importlib.util
d = os.path.join(os.path.dirname(importlib.util.find_spec("llama_cpp").origin), "lib")
bad = []
for lib in sorted(glob.glob(d + "/lib*.so")):
out = subprocess.run(["ldd", lib], capture_output=True, text=True).stdout
for line in out.splitlines():
if "not found" in line and not re.search(r"libcuda\.so|libnvidia-ml\.so", line):
bad.append(f"{os.path.basename(lib)}: {line.strip()}")
assert not bad, "unresolved libraries: " + "; ".join(bad)
names = " ".join(os.path.basename(x) for x in glob.glob(d + "/lib*"))
syms = subprocess.run(["nm", "-D", "--defined-only"] + glob.glob(d + "/libggml*.so"),
capture_output=True, text=True).stdout
assert "libggml-rpc" in names or "ggml_backend_rpc" in syms, \
"RPC backend missing from the rebuilt llama-cpp-python"
print("llama-cpp-python links cleanly and carries the RPC backend: OK")
PY
RUN /opt/coderai/python/bin/rpc-server --help | head -2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment