Skip to content

Commit c02a50f

Browse files
authored
feat(llama-cpp): bump to d775992 and adapt to spec params refactor (#9618)
Bumps backend/cpp/llama-cpp/Makefile LLAMA_VERSION from 665abc6 to d775992, picking up upstream PR ggml-org/llama.cpp#22397 which splits common_params_speculative into nested draft / ngram_simple / ngram_mod sub-structs. Renames every grpc-server.cpp reference to match: speculative.mparams_dft.path -> speculative.draft.mparams.path speculative.{n_max,n_min} -> speculative.draft.{n_max,n_min} speculative.{p_min,p_split} -> speculative.draft.{p_min,p_split} speculative.{n_gpu_layers,n_ctx} -> speculative.draft.{n_gpu_layers,n_ctx} speculative.ngram_size_n -> speculative.ngram_simple.size_n speculative.ngram_size_m -> speculative.ngram_simple.size_m speculative.ngram_min_hits -> speculative.ngram_simple.min_hits The "speculative.n_max" JSON key sent to the upstream server stays unchanged — server-task.cpp still reads it and routes the value into draft.n_max internally. The turboquant fork (TheTom/llama-cpp-turboquant @ 11a241d) branched before #22397 and still exposes the flat layout. Since turboquant reuses the shared backend/cpp/llama-cpp/grpc-server.cpp, extend patch-grpc-server.sh with an idempotent sed block that reverts the ten field references back to the legacy flat names on the build copy only — the original under backend/cpp/llama-cpp/ stays compiling against vanilla upstream. Drop the block once the fork rebases. ik-llama-cpp has its own grpc-server.cpp with no speculative refs (0/2661 lines), so it is unaffected. Validated locally with `make docker-build-llama-cpp` (avx, avx2, avx512, fallback, grpc + rpc-server all built; image exported). Assisted-by: Claude:claude-opus-4-7 [Bash Read Edit] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 76971fb commit c02a50f

3 files changed

Lines changed: 45 additions & 14 deletions

File tree

backend/cpp/llama-cpp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
LLAMA_VERSION?=665abc609740d397d30c0d8ef4157dbf900bd1a3
2+
LLAMA_VERSION?=d77599234ea6e498775aeadbce665eece5bd98cd
33
LLAMA_REPO?=https://github.com/ggerganov/llama.cpp
44

55
CMAKE_ARGS?=

backend/cpp/llama-cpp/grpc-server.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static void params_parse(server_context& /*ctx_server*/, const backend::ModelOpt
442442

443443
// Draft model for speculative decoding
444444
if (!request->draftmodel().empty()) {
445-
params.speculative.mparams_dft.path = request->draftmodel();
445+
params.speculative.draft.mparams.path = request->draftmodel();
446446
// Default to draft type if a draft model is set but no explicit type
447447
if (params.speculative.type == COMMON_SPECULATIVE_TYPE_NONE) {
448448
params.speculative.type = COMMON_SPECULATIVE_TYPE_DRAFT;
@@ -679,39 +679,39 @@ static void params_parse(server_context& /*ctx_server*/, const backend::ModelOpt
679679
}
680680
} else if (!strcmp(optname, "spec_n_max") || !strcmp(optname, "draft_max")) {
681681
if (optval != NULL) {
682-
try { params.speculative.n_max = std::stoi(optval_str); } catch (...) {}
682+
try { params.speculative.draft.n_max = std::stoi(optval_str); } catch (...) {}
683683
}
684684
} else if (!strcmp(optname, "spec_n_min") || !strcmp(optname, "draft_min")) {
685685
if (optval != NULL) {
686-
try { params.speculative.n_min = std::stoi(optval_str); } catch (...) {}
686+
try { params.speculative.draft.n_min = std::stoi(optval_str); } catch (...) {}
687687
}
688688
} else if (!strcmp(optname, "spec_p_min") || !strcmp(optname, "draft_p_min")) {
689689
if (optval != NULL) {
690-
try { params.speculative.p_min = std::stof(optval_str); } catch (...) {}
690+
try { params.speculative.draft.p_min = std::stof(optval_str); } catch (...) {}
691691
}
692692
} else if (!strcmp(optname, "spec_p_split")) {
693693
if (optval != NULL) {
694-
try { params.speculative.p_split = std::stof(optval_str); } catch (...) {}
694+
try { params.speculative.draft.p_split = std::stof(optval_str); } catch (...) {}
695695
}
696696
} else if (!strcmp(optname, "spec_ngram_size_n") || !strcmp(optname, "ngram_size_n")) {
697697
if (optval != NULL) {
698-
try { params.speculative.ngram_size_n = (uint16_t)std::stoi(optval_str); } catch (...) {}
698+
try { params.speculative.ngram_simple.size_n = (uint16_t)std::stoi(optval_str); } catch (...) {}
699699
}
700700
} else if (!strcmp(optname, "spec_ngram_size_m") || !strcmp(optname, "ngram_size_m")) {
701701
if (optval != NULL) {
702-
try { params.speculative.ngram_size_m = (uint16_t)std::stoi(optval_str); } catch (...) {}
702+
try { params.speculative.ngram_simple.size_m = (uint16_t)std::stoi(optval_str); } catch (...) {}
703703
}
704704
} else if (!strcmp(optname, "spec_ngram_min_hits") || !strcmp(optname, "ngram_min_hits")) {
705705
if (optval != NULL) {
706-
try { params.speculative.ngram_min_hits = (uint16_t)std::stoi(optval_str); } catch (...) {}
706+
try { params.speculative.ngram_simple.min_hits = (uint16_t)std::stoi(optval_str); } catch (...) {}
707707
}
708708
} else if (!strcmp(optname, "draft_gpu_layers")) {
709709
if (optval != NULL) {
710-
try { params.speculative.n_gpu_layers = std::stoi(optval_str); } catch (...) {}
710+
try { params.speculative.draft.n_gpu_layers = std::stoi(optval_str); } catch (...) {}
711711
}
712712
} else if (!strcmp(optname, "draft_ctx_size")) {
713713
if (optval != NULL) {
714-
try { params.speculative.n_ctx = std::stoi(optval_str); } catch (...) {}
714+
try { params.speculative.draft.n_ctx = std::stoi(optval_str); } catch (...) {}
715715
}
716716
}
717717
}
@@ -933,8 +933,8 @@ class BackendServiceImpl final : public backend::Backend::Service {
933933
if (!params.mmproj.path.empty()) {
934934
error_msg += " (with mmproj: " + params.mmproj.path + ")";
935935
}
936-
if (params.speculative.has_dft() && !params.speculative.mparams_dft.path.empty()) {
937-
error_msg += " (with draft model: " + params.speculative.mparams_dft.path + ")";
936+
if (params.speculative.has_dft() && !params.speculative.draft.mparams.path.empty()) {
937+
error_msg += " (with draft model: " + params.speculative.draft.mparams.path + ")";
938938
}
939939

940940
// Add captured error details if available

backend/cpp/turboquant/patch-grpc-server.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# Patch the shared backend/cpp/llama-cpp/grpc-server.cpp *copy* used by the
3-
# turboquant build to account for two gaps between upstream and the fork:
3+
# turboquant build to account for the gaps between upstream and the fork:
44
#
55
# 1. Augment the kv_cache_types[] allow-list so `LoadModel` accepts the
66
# fork-specific `turbo2` / `turbo3` / `turbo4` cache types.
@@ -11,6 +11,14 @@
1111
# "<__media__>", and Go-side tooling falls back to that sentinel when the
1212
# backend does not expose media_marker, so substituting the literal keeps
1313
# behavior identical on the turboquant path.
14+
# 3. Revert the `common_params_speculative` field references to the
15+
# pre-refactor flat layout. Upstream ggml-org/llama.cpp#22397 split the
16+
# struct into nested `draft` / `ngram_simple` / `ngram_mod` / etc. members;
17+
# the turboquant fork branched before that PR and still exposes the flat
18+
# `n_max`, `mparams_dft`, `ngram_size_n`, ... fields. The substitutions
19+
# below map the new nested paths back to the legacy flat names so the
20+
# shared grpc-server.cpp keeps compiling against the fork's common.h.
21+
# Drop this block once the fork rebases past #22397.
1422
#
1523
# We patch the *copy* sitting in turboquant-<flavor>-build/, never the original
1624
# under backend/cpp/llama-cpp/, so the stock llama-cpp build keeps compiling
@@ -77,4 +85,27 @@ else
7785
echo "==> $SRC has no get_media_marker() call, skipping media-marker patch"
7886
fi
7987

88+
if grep -q 'params\.speculative\.draft\.\|params\.speculative\.ngram_simple\.' "$SRC"; then
89+
echo "==> patching $SRC to revert common_params_speculative refs to pre-#22397 flat layout"
90+
# Each substitution is the exact post-refactor path → legacy flat field.
91+
# Order doesn't matter because the source paths are disjoint, but we keep
92+
# the most-specific (mparams.path) first for readability.
93+
sed -E \
94+
-e 's/params\.speculative\.draft\.mparams\.path/params.speculative.mparams_dft.path/g' \
95+
-e 's/params\.speculative\.draft\.n_max/params.speculative.n_max/g' \
96+
-e 's/params\.speculative\.draft\.n_min/params.speculative.n_min/g' \
97+
-e 's/params\.speculative\.draft\.p_min/params.speculative.p_min/g' \
98+
-e 's/params\.speculative\.draft\.p_split/params.speculative.p_split/g' \
99+
-e 's/params\.speculative\.draft\.n_gpu_layers/params.speculative.n_gpu_layers/g' \
100+
-e 's/params\.speculative\.draft\.n_ctx/params.speculative.n_ctx/g' \
101+
-e 's/params\.speculative\.ngram_simple\.size_n/params.speculative.ngram_size_n/g' \
102+
-e 's/params\.speculative\.ngram_simple\.size_m/params.speculative.ngram_size_m/g' \
103+
-e 's/params\.speculative\.ngram_simple\.min_hits/params.speculative.ngram_min_hits/g' \
104+
"$SRC" > "$SRC.tmp"
105+
mv "$SRC.tmp" "$SRC"
106+
echo "==> speculative field rename OK"
107+
else
108+
echo "==> $SRC has no post-#22397 speculative field refs, skipping spec rename patch"
109+
fi
110+
80111
echo "==> all patches applied"

0 commit comments

Comments
 (0)