1919# MODELS_DIR default /workspace/models
2020# MMPROJ F16 to enable vision
2121# PORT, HOST default 8000, 127.0.0.1
22+ # LLAMA_CPP_REPO custom llama.cpp fork (default: ggml-org/llama.cpp)
23+ # LLAMA_CPP_REF branch/tag/commit to build from (default: master)
24+ # Use for models needing unmerged PRs, e.g. DeepSeek V4
2225
2326set -euo pipefail
2427
@@ -43,6 +46,10 @@ HOST="${HOST:-127.0.0.1}"
4346if [ " ${IMAGE_TYPE} " = " builder" ] && [ ! -x /usr/local/bin/llama-server ]; then
4447 log " ==> builder image: no pre-compiled llama-server — detecting GPU arch..."
4548
49+ # Custom repo/branch support (for models needing unmerged PRs)
50+ LLAMA_CPP_REPO=" ${LLAMA_CPP_REPO:- ggml-org/ llama.cpp} "
51+ LLAMA_CPP_REF=" ${LLAMA_CPP_REF:- master} "
52+
4653 # Get compute capability from nvidia-smi, strip the dot: "9.0" → "90"
4754 RAW_CAP=" $( nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2> /dev/null | head -1 | tr -d ' ' ) "
4855 if [ -z " ${RAW_CAP} " ]; then
@@ -60,10 +67,18 @@ if [ "${IMAGE_TYPE}" = "builder" ] && [ ! -x /usr/local/bin/llama-server ]; then
6067 SRC_DIR=" /opt/llama.cpp"
6168 BUILD_DIR=" ${SRC_DIR} /build"
6269
63- # Source was cloned into the image at build time — just run cmake
70+ # Source may be cached in image — re-clone if repo/branch differs or missing
6471 if [ ! -d " ${SRC_DIR} " ]; then
65- log " llama.cpp source not found in image — cloning..."
66- git clone --depth 1 https://github.com/ggml-org/llama.cpp.git " ${SRC_DIR} "
72+ log " cloning https://github.com/${LLAMA_CPP_REPO} .git (ref: ${LLAMA_CPP_REF} )..."
73+ git clone --depth 1 --branch " ${LLAMA_CPP_REF} " \
74+ " https://github.com/${LLAMA_CPP_REPO} .git" " ${SRC_DIR} "
75+ elif [ " ${LLAMA_CPP_REPO} " != " ggml-org/llama.cpp" ] || [ " ${LLAMA_CPP_REF} " != " master" ]; then
76+ # Custom repo/branch requested but image has default source — re-clone
77+ log " custom repo/branch requested — re-cloning..."
78+ log " repo: ${LLAMA_CPP_REPO} ref: ${LLAMA_CPP_REF} "
79+ rm -rf " ${SRC_DIR} "
80+ git clone --depth 1 --branch " ${LLAMA_CPP_REF} " \
81+ " https://github.com/${LLAMA_CPP_REPO} .git" " ${SRC_DIR} "
6782 fi
6883
6984 log " configuring for SM${SM} ..."
@@ -134,16 +149,21 @@ else
134149 log " model already present in ${TARGET_DIR} , skipping fetch"
135150fi
136151
137- # ── locate weights ─────────────────────────────────────────────────────────────
138- MODEL_FILE=" $( ls -1 " ${TARGET_DIR} " | grep -iE " ${MODEL_QUANT} .*\.gguf$" | grep -v ' mmproj' | sort | head -n1 || true) "
152+ # ── locate weights ─────────────────────────────────────────────────────────
153+ # Handles both single-file and split GGUFs.
154+ # Split files: llama-server needs the first shard (e.g. -00001-of-00023.gguf)
155+ # Some repos put shards in subdirectories (e.g. Q2_K/model-Q2_K.gguf-00001-of-N)
156+ MODEL_FILE=" $( find " ${TARGET_DIR} " -maxdepth 2 -name " *.gguf" \
157+ | grep -iE " ${MODEL_QUANT} " | grep -v ' mmproj' | sort | head -n1 || true) "
139158[ -n " ${MODEL_FILE} " ] || die " no .gguf matching '${MODEL_QUANT} ' in ${TARGET_DIR} "
140- MODEL_PATH=" ${TARGET_DIR} / ${ MODEL_FILE}"
159+ MODEL_PATH=" ${MODEL_FILE} " # find returns full path
141160
142161MMPROJ_ARGS=" "
143162if [ -n " ${MMPROJ:- } " ]; then
144- MMPROJ_FILE=" $( ls -1 " ${TARGET_DIR} " | grep -iE " mmproj-${MMPROJ} .*\.gguf$" | head -n1 || true) "
163+ MMPROJ_FILE=" $( find " ${TARGET_DIR} " -maxdepth 2 -name " *.gguf" \
164+ | grep -iE " mmproj-${MMPROJ} " | head -n1 || true) "
145165 [ -n " ${MMPROJ_FILE} " ] || die " MMPROJ requested but no mmproj file found"
146- MMPROJ_ARGS=" --mmproj ${TARGET_DIR} / ${ MMPROJ_FILE}"
166+ MMPROJ_ARGS=" --mmproj ${MMPROJ_FILE} "
147167fi
148168
149169# ── launch ─────────────────────────────────────────────────────────────────────
0 commit comments