From 9537726649f2406299150d5208beac754752b24c Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Mon, 22 Jun 2026 11:54:51 +0000 Subject: [PATCH] fix(llama-cpp/paged): stop double-applying the paged patches in prepare.sh The Makefile llama.cpp target git-applies the paged series at checkout; prepare.sh then re-applied with patch, fuzzily duplicating hunks (redefinition errors -> the grpc-server CUDA build failed under LLAMA_PAGED=on). Guard prepare.sh's apply with a sentinel (skip when llama.cpp/src/paged-kv-manager.cpp already exists) + -N/-r flags, so it only does work against an unpatched checkout. Found by the GPU/full-build verification (PAGED_GPU_VERIFY.md). Assisted-by: Claude:opus-4.8 [Claude Code] Signed-off-by: Ettore Di Giacinto --- backend/cpp/llama-cpp/prepare.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/cpp/llama-cpp/prepare.sh b/backend/cpp/llama-cpp/prepare.sh index 75aaa8875..2a8a88f66 100644 --- a/backend/cpp/llama-cpp/prepare.sh +++ b/backend/cpp/llama-cpp/prepare.sh @@ -3,21 +3,28 @@ ## Patches ## Apply patches: the base `patches/` series, then the gated `patches/paged/` -## series (default on; LLAMA_PAGED=off skips it). Runs before `set -e` so a -## re-apply on rebuild is tolerated. Only *.patch files are applied (docs/dirs -## like patches/paged/ and *.md are skipped). +## series (default on; LLAMA_PAGED=off skips it). Only *.patch files are applied +## (docs/dirs like patches/paged/ and *.md are skipped). The Makefile `llama.cpp` +## target already `git apply`s these at checkout, so each apply is guarded by a +## sentinel and skipped when already present - re-applying git-format patches with +## `patch` fuzzily duplicates hunks (redefinition errors). This block only does +## real work if prepare.sh is run against an unpatched checkout. if [ -d "patches" ]; then for patch in patches/*.patch; do [ -e "$patch" ] || continue echo "Applying patch $patch" - patch -d llama.cpp/ -p1 < "$patch" + patch -d llama.cpp/ -p1 -N -r - < "$patch" || true done if [ "${LLAMA_PAGED:-on}" != "off" ] && [ -d "patches/paged" ]; then - for patch in patches/paged/*.patch; do - [ -e "$patch" ] || continue - echo "Applying paged patch $patch" - patch -d llama.cpp/ -p1 < "$patch" - done + if [ -f llama.cpp/src/paged-kv-manager.cpp ]; then + echo "paged-attention patch series already applied (sentinel present) - skipping re-apply" + else + for patch in patches/paged/*.patch; do + [ -e "$patch" ] || continue + echo "Applying paged patch $patch" + patch -d llama.cpp/ -p1 -N -r - < "$patch" || true + done + fi fi fi