Files
llama.cpp/docs/fork-rebase-runbook.md
T

881 lines
62 KiB
Markdown

# Fork rebase and deploy runbook (RX 580 fork)
Step-by-step procedure for moving the fork onto a new upstream and putting it into production, as it
has evolved over the 2026-09-09, 2026-10-09, 2026-10-24 and 2026-11-21 rebases. Read [FORK.md](../FORK.md) first:
it lists every fork feature with its invariants and rebase hazards, and this runbook refers to it.
Ground rules:
- **Never build on the workstation.** All builds run on the RX 580 pod. Locally, rely on careful reading.
- **Never resolve a conflict with `-X theirs` or `-X ours`.** Resolve every hunk by hand.
- **"Applied cleanly" is not "correct".** Re-read every clean pick against the new upstream.
- **Never `pkill -f` on the pod.** It matches the `kubectl exec` shell and kills it. Kill by explicit PID.
- **Never leave the pod not serving.** Anything that stops llama-swap must restart it from a trap.
- Keep the previous production branch untouched as the safety net. Do not push for the owner; the owner
reviews and pushes.
Contents: 1. Survey; 2. Trial rebase; 3. The real rebase; 4. Checks without a compiler; 5. Build on
the pod; 6. Validate; 7. Deploy; 8. Post-deploy checks; 9. Rollback; 10. Recovering a hung GPU;
11. Operations reference.
**Redeploying a new tip on the same upstream base (no rebase)**, e.g. new fork commits on the
production branch (2026-10-25: `6c480f7e7` -> `2fc9f9c35`, same branch, same base):
- Skip sections 1-3. Of section 4 only the ASCII check (on `git diff <prod>..<tip>`) and a careful
read of that diff apply; `<prod>` is `git -C /root/llama.cpp rev-parse HEAD` on the pod. There is
nothing to range-diff.
- Do sections 5-9 as written: build the tip in a scratch worktree, validate it with `--ref` = the
production build, then deploy.
- The branch name stays the same, so deploy step 2's `git checkout -B <same branch> <tip>` moves the
production branch on the pod to the tip. After that the rollback pointer file is the only record
of the old production commit on the pod, so write it first (deploy step 1).
---
## 1. Survey upstream
Local remotes: `origin` is upstream (github.com/ggerganov/llama.cpp), `gitea` is the fork
(git@gitea.lumpiasty.xyz:Lumpiasty/llama.cpp.git, SSH push from the workstation). On the pod,
`origin` is the same gitea repository over HTTPS (fetch only).
```sh
git fetch origin
OLD_BASE=$(git merge-base origin/master HEAD) # the old upstream base (still an ancestor of the new master)
OLD_TIP=$(git rev-parse HEAD)
git log --oneline "$OLD_BASE"..HEAD # the fork commits, oldest last
git log --oneline "$OLD_BASE"..origin/master | wc -l # size of the upstream delta
```
Then look at upstream changes in the areas FORK.md lists as hazards:
```sh
git log --oneline "$OLD_BASE"..origin/master -- \
src/llama-context.cpp src/llama-context.h src/llama-model.cpp src/llama-model.h \
src/llama-kv-cache.cpp src/llama-kv-cache.h src/llama-kv-cache-iswa.cpp \
src/llama-memory.h src/llama-memory-recurrent.cpp src/llama-memory-hybrid.cpp \
src/llama-moe-cache.cpp src/llama-moe-cache.h src/models/delta-net-base.cpp \
ggml/src/ggml-vulkan/ ggml/src/ggml-backend.cpp ggml/src/ggml-backend-impl.h ggml/include/ggml-backend.h \
tools/server/server-queue.cpp tools/server/server-queue.h tools/server/server-context.cpp tools/server/server.cpp \
tools/mtmd/clip.cpp tools/mtmd/mtmd.cpp common/arg.cpp tools/llama-bench/
```
**Temporary upstream carries (FORK.md F12)** come first: `git log --oneline --grep '^upstream-carry'
"$OLD_BASE"..HEAD`. For each: merged into the new upstream -> do not cherry-pick it (check that the
merged version is the carried head or newer); still open -> re-fetch the PR head and re-carry it if
it moved; closed -> ask the owner. A PR head can also shrink: on 2026-11-22 #32740 dropped the Vulkan part the fork needs, so the old
head stayed carried (FORK.md F12). Compare `git diff --stat` of the old and new head before re-carrying.
To carry a PR (2026-11-21: #32735, #32740; 2026-11-22: #32777):
```sh
git fetch https://github.com/ggml-org/llama.cpp pull/<N>/head:pr-<N>
git cherry-pick $(git merge-base pr-<N> HEAD)..pr-<N> # the PR's commits, oldest first; resolve by hand
# squash them into one commit with the PR author, subject "upstream-carry #<N>: <PR title>", and a
# body with the PR URL, the carried head and any conflict resolution (git commit-tree on the final tree)
diff <(git diff $(git merge-base pr-<N> HEAD) pr-<N> | grep '^[+-]') <(git diff HEAD~1 HEAD | grep '^[+-]')
```
The last diff shows only the lines you changed while resolving conflicts (for #32740: none, the F2
line differs only in context). Validate a carry like any compiled change (sections 5-6), plus the
PR's own tests.
For each fork commit decide: still needed, needs a semantic merge, or obsolete. Examples of past
decisions:
- 2026-09-09: dropped the weight-pinning chain, the expert prefetch and fractional `-ncmoe` (all measured
losses or no win on this card, FORK.md section 4).
- 2026-10-09: the routing-ids readback skip had nothing to apply to (upstream #29943 deleted its block
in `ggml-backend.cpp`); it was re-authored in `llama_context::sched_copy_experts`. Upstream's new MoE
cache (#29887) needed a new fork commit so the VRAM arbiter releases and invalidates it.
- Also check CLI changes that break production config or the scripts (upstream #28334 removed
`--no-mmap`/`--mmap`/`--mlock` and llama-bench `-mmp`; the default `--port` changed to 9931).
## 2. Trial rebase in a scratch worktree
Measure the conflicts before doing the real thing:
```sh
git worktree add /tmp/trial-rebase origin/master
cd /tmp/trial-rebase
git cherry-pick "$OLD_BASE".."$OLD_TIP" # stop at each conflict, note file + hunk, then:
git cherry-pick --abort # or resolve roughly to see the next one
cd - && git worktree remove --force /tmp/trial-rebase
```
Write down, per commit: clean / conflict (which file, which hunk, what both sides did). That list
becomes the brief for the real rebase.
## 3. The real rebase
```sh
NEW=fable5/vram-ondemand-rebase-$(date +%Y%m%d)
git switch -c "$NEW" origin/master
git cherry-pick <first-fork-commit> # one at a time, in the original order
```
**A rebase is not done until `fork-validate.sh` phases 1 and 2 (section 6) pass on a pod build of
the new branch.** A rebased branch that is only picked, checked by reading, or built is unfinished
work, whatever the cherry-picks looked like. Report it as unfinished until both phases pass.
Rules:
- Cherry-pick in the original order, keep authors and messages. New commits you author get the
fork's trailer (`Co-Authored-By: Claude ...` for agent-written commits, FORK.md status block),
unless the owner asks for something else.
- Resolve every conflict by hand. Union both sides where both added code; keep upstream's new terms.
- Fold each fix into the commit it belongs to so every commit builds on its own:
`git commit --fixup=<sha>` then `GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash origin/master`.
- Leave the previous production branch untouched.
**What `-X theirs` silently broke in a trial (2026-10-09).** It "applied" every commit and produced
broken code:
- resurrected the scheduler readback block upstream had deleted from `ggml-backend.cpp`;
- dropped `!use_sparse` from the GCN `use_mask_opt` condition;
- dropped upstream's `copy_experts_info` (compile error);
- dropped upstream's `is_empty()` in the recurrent memory;
- dropped upstream's MoE-cache memory breakdown block;
- left a static/extern mismatch with the new `ggml-vulkan-common.h` declarations (compile error).
The correct resolutions in that rebase: keep upstream's `n_embd` width check plus our decode
auto-restore; `copy_experts_info` plus our `kv_device_evicted`; `is_empty()` plus our `dev_shadows`;
upstream's `if (moe_cache)` breakdown block outside our `if (sched)` guard; make `ggml_vk_concat` and
`ggml_backend_vk_free` non-static to match the new header while our helpers stay static.
**Clean picks that were wrong (2026-10-24).**
- Concat fast path (3df719e1e): applied cleanly, did not compile. Upstream `733f57a99` renamed
`pipeline_cpy_f32_f32`/`pipeline_cpy_f16_f16` to `pipeline_cpy_32`/`pipeline_cpy_16` (bitwise copies,
same push constants).
- MoE cache release/restore (7ac2014a8): applied cleanly, did not compile (upstream `33d6135cb` changed
LRU to SLRU, `g.lru` -> `g.slru`) and had a runtime bug: `moe_cache_slru::init()` resets only the
probation segment, so re-initialising a used cache corrupts its lists. `invalidate()` now assigns a
fresh `moe_cache_slru()` first.
- VRAM sharing core (481be8b28): besides its one conflict, upstream's new `load_tensors_hadamard()`
pushes two more entries into `pimpl->ctxs_bufs`. Without matching `weight_release.emplace_back()`
calls, `release_device_weights()` reads past the end of `weight_release`. Nothing conflicted.
- Conflicts that round: `ctx_buf_maps.emplace_back` replaced upstream by `ctx_bufs.emplace_back(ctx,
std::move(buf_ptrs))` (keep upstream's line, our release-slot block before it); `llama-context.h`
(keep upstream's `n_reallocs_same/diff` beside our `kv_device_evicted`); `recv_with_timeout`
(upstream `4e201388c` uses a fixed deadline: keep our order "check `!running`, return null", then
`wait_until(lock, deadline)`).
**What the 2026-11-21 rebase (upstream `e6d624b9a`, 757 commits past `3f03b1772`) changed** (nothing
built or run locally; every item below is by reading only and needs the pod build):
- Upstream refactors that moved fork code (hand ports, not conflicts of one hunk):
- `clip.cpp`/`clip.h` are gone (#31865). The encoder release/restore (F5) is now
`mtmd_model_release_device`/`mtmd_model_restore_device` on `mtmd_model` (`mtmd-model.cpp`), called
from `mtmd_release_device`/`mtmd_restore_device` under `compute_mutex` after syncing the shared
scheduler; the page-cache drop of F10 moved to `mtmd_model_loader::load_tensors`.
- `server_prompt_cache` moved to `server-slot-sched.{h,cpp}` and `get_available_slot()` was replaced
by `server_slot_sched::select()`. The disk prompt cache (F11) lives there now
(`server_prompt_disk_cache`), is called from the task dispatch after `update_prompt_cache()`, and
uses `common_state_data` and `shared_ptr<const common_prompt_checkpoint>`. Only prompts made with
the server lora config are saved, and a restored prompt gets that config in `prompt.lora`.
- Upstream's `llama_memory_bufs` replaced the raw `ctxs_bufs` vectors of the KV cache and the recurrent
memory: the null-buffer guard moved into `llama_memory_bufs::memory_breakdown()`, and the release
code indexes `ctxs_bufs.bufs[i]`. Those two did not compile after a clean pick.
- The MoE cache is now a ClassLRU (`moe_cache_lru`, `g.lru`) with `no_alloc` as a constructor
argument and `cpu_share`. `invalidate()` rebuilds `g.lru`, refills every slot map with
`g.lru.empty` (not -1), clears the CPU maps and `cpu_experts`.
- `server.cpp` was split into `server_run_instance` and friends: the self-pipe shutdown thread
(F7) is started in `server_run_instance` only, just before `server_install_signal_handlers()`.
- `server_queue` got `n_inflight` (#32133). `should_sleep` checks it first, so a response that is still
open also blocks the want-lock yield. This is a decision, not an accident: check it with `--arbiter`.
- Upstream added its own tiled-transpose concat (#30591) with no size gate. The fork path still runs
first (`ne0 >= 32`); the gate and the `GGML_VK_CONCAT_FASTPATH` knob were added to upstream's selector
(`ggml_vk_concat_is_transposed`), otherwise decode would take upstream's tiled path again (F3).
(2026-11-23: the fork path and then the gate were both removed; upstream's tiled path is not slower
at decode, FORK.md F3.)
- Memory types with no release override (stay in VRAM when cold, not used in production):
`llama_kv_cache_dsa`, `_dsa_iswa`, `_dsv4`, `_msa`, `llama_memory_hybrid_iswa`. The KV rotation
tensors (`attn_rot_bufs`, #31073) are small and are not released either.
**What the 2026-11-22 rebase (upstream `5bacb7c86`, 19 commits past `e6d624b9a`) changed.** Branch
`fable5/vram-ondemand-rebase-20261122`. The 64 picks (65 fork commits minus the #32735 carry) all
applied cleanly; the range-diff against the old branch is identical except for that dropped carry and
the new commits at the end. Reading checks:
- #32735 merged as `8a97fa98a`, patch identical to the carried head `0ea4ffd00`: carry dropped.
- #32740 is still open but was split: its head `8c6f0c0ca` is now only the GGML contract (op API,
CPU reference, test-backend-ops cases); the Vulkan kernel, the `kv_rows` support and the Inkling
graph use were removed from it and are in no open PR (Metal is #32808). Carrying that head would
drop Inkling's in-kernel bias (back to the 15.8 GiB compute buffer at ctx 65536, FORK.md F12). The
validated carry of head `808fd1c4e` is kept as is (FORK.md F12 has the owner decision).
- #32807 (`5bacb7c86`) adds an `LLM_ARCH_INKLING2_LOOP` guard to `sched_copy_experts` (whole-tensor
copies), upstream's fix for #32755. It sits beside F1 in the same function; no conflict. It does
not remove the held per-pass copies, so F13 stays (FORK.md F13, "Upstream #32807").
- #32713 (non-causal prompts fit in one ubatch) touches `update_slots` near the F14 loop but not
the user-start break; F14 unchanged by it.
- #32799 (`ignore_merges` for inkling2) changes Inkling's tokenization: Inkling prompts cached by
the previous build no longer match. The disk cache key holds the build commit, so nothing stale is
restored.
- New commits: the F14 first-user-message break (FORK.md F14), the `LLAMA_LOOP_FULL_COPY` knob
(F13) and the carry of #32777 (F12).
**The 2026-11-23 slimming (branch `fable5/vram-ondemand-rebase-20261123`, same upstream
`5bacb7c86`).** Not a rebase onto new upstream: the 74 commits of `-20261122` were rebuilt as one
commit per feature (FORK.md section 2) and the features without a measured benefit were dropped
(F1, F3's fast path and gate, F15, the #32777 carry, the `rx580-bench` harness). Procedure, for the next time it is needed: `git cherry-pick -n` each feature's
commits in their original order, then commit them as one with a message that keeps every original
message under a `---- <subject> (was <hash>)` line; the VRAM commits, which mixed library and server
hunks, were picked together and committed by path (`git add ggml src include`, then `tools/mtmd`,
then `tools/server`). Checks: `git diff <old tip> <new tip> -- . ':!*.md'` must be exactly the
removals (compare each removed file's hunks with the reverse of the dropped commit), and the build,
`fork-validate.sh` phases 1 and 2 and the A/B against production must pass like any compiled change.
A future rebase now cherry-picks 10 code and script commits plus the documentation.
Open questions from the 2026-11-21 rebase:
- Is the fork's own concat fast path (F3) now redundant with upstream's tiled concat (#30591)? Yes:
measured on 2026-11-23 and dropped (FORK.md section 2, "Removed on 2026-11-23").
- Does `n_inflight` blocking the want-lock yield delay handoffs? Validation says no: handoff median
candidate 692 ms vs reference 1068 ms (`a-handoff-latency`, 2026-11-21).
**Semantic re-checks to do for every rebase, clean or not** (details in FORK.md):
- F2: `use_mask_opt` still contains upstream's terms plus our `>= 256` (and `!bias &&` from #32740, carried as F12 or merged upstream).
- Upstream's tiled concat (no fork code since 2026-11-23, FORK.md F3): `build_conv_state` still
emits `ggml_concat(conv_states, ggml_transpose(qkv_mixed), 0)` with `qkv_mixed` contiguous; if a
`ggml_cont` appears there, the 35B loses about 13% prefill and only `--perf` shows it.
- F13 with `LLAMA_LOOP_FULL_COPY=0`: `sched_copy_experts` still keys its routing readback on the ids
of the split's first node (per pass, which the per-pass views rely on).
- F4: every `ctxs_bufs` push in `src/llama-model.cpp` has a `weight_release` push
(`git grep -n "ctxs_bufs.emplace_back\|weight_release" src/llama-model.cpp`); list memory types
(`git grep -n "public llama_memory_i" src/`) and note any without a release override; MoE-cache
internals; `sched_reserve()` still goes through `sched_new()` and re-registers callbacks;
`free_scratch` still the last `ggml_backend_i` member; Vulkan prealloc fields match `ggml_vk_cleanup`.
- F6/F7: `server_queue::start_loop` still evaluates `should_sleep()` only from the idle branch, never
inside `yield_to_queue()`; `handle_sleeping_state`, `server_res_generator`, `load_model` ordering;
signal setup in `server.cpp`.
- F8: new iterators over `ctxs_bufs` or users of `sched` on teardown paths.
- Scripts: flag spellings used by `scripts/fork-validate.sh` and the window scripts in `/root/arms/`, and the log
lines `fork-validate.sh` greps for (FORK.md F9).
- Production config: every flag in `/root/config.yaml` still exists in `common/arg.cpp`.
## 4. Checks without a compiler
Before handing the branch over for a build:
```sh
git diff origin/master..HEAD | grep -n '^[+-]\(<<<<<<<\|=======\|>>>>>>>\)' # no conflict markers
git diff origin/master..HEAD | grep -nP '^\+.*[^\x00-\x7F]' # ASCII only in added lines
git range-diff "$OLD_BASE".."$OLD_TIP" origin/master..HEAD # patch vs patch
```
- The range-diff must show only the edits you made on purpose. In 2026-10-24 the whole patch was
identical to the old one except for 4 deliberate edits.
- Brace balance per changed file: the change in `{`/`}` balance from new base to new tip should equal
the change from old base to old tip.
- Every identifier in added lines must exist on the new master or be defined by the fork. This catches
a renamed function but not a renamed member (like `lru` -> `slru`); re-read member accesses by hand.
- Write down every spot where you would normally lean on the compiler and hand that list to whoever
builds.
Then the owner pushes the branch to gitea, and the pod fetches it from there (section 5).
**If you were told not to push**, do not stop at an unbuilt branch. Unless the task says otherwise, a
rebase task continues through the build and validation (sections 5 and 6) and reports the results;
the owner pushes afterwards. Get the branch onto the pod with a git bundle:
```sh
# workstation; <base> is a commit the pod already has, e.g. production's HEAD
git bundle create /tmp/x.bundle <base>..<branch>
export KUBECONFIG=/home/user/Projects/klaster/talos/generated/kubeconfig
kubectl -n llama exec -i deploy/supervisord -- sh -c 'cat > /root/x.bundle' < /tmp/x.bundle
kubectl -n llama exec deploy/supervisord -- sh -c 'cd /root/llama.cpp && git fetch /root/x.bundle <branch>:<branch>'
```
The branch is then local in `/root/llama.cpp`: in section 5 skip the `git fetch origin` and use
`git worktree add "$W" <branch>`. Delete `/root/x.bundle` afterwards (disk is tight). Deploy step 2
likewise uses the local branch instead of fetching from origin.
## 5. Build on the pod, in a scratch worktree
Production keeps serving during this step.
```sh
export KUBECONFIG=/home/user/Projects/klaster/talos/generated/kubeconfig
kubectl -n llama exec -i deploy/supervisord -- sh -c '
set -e
B=fable5/vram-ondemand-rebase-YYYYMMDD
W=/root/arms/rebYYYYMMDD
git -C /root/llama.cpp fetch origin "$B"
git -C /root/llama.cpp worktree add "$W" FETCH_HEAD
cd "$W"
export HF_UI_VERSION=b11906 # production's: cut -d'|' -f2 /root/llama.cpp/build/tools/ui/.ui-stamp
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DGGML_VULKAN=1 -DGGML_NATIVE=ON -DLLAMA_BUILD_UI=OFF
nice -n 19 cmake --build build --target llama-server llama-bench test-backend-ops -j 8
'
```
- Build only the targets you need; the full `all` target fails on the UI assets (needs npm/network).
If a tree has a stale `tools/ui/dist` with a stub `index.html`, remove it (it breaks llama-ui-embed).
- `nice -n 19 -j 8` leaves the serving models CPU. A full build takes about 3.5 minutes.
- Report compile errors verbatim against the list from step 4.
- Do not overlap a build with a large benchmark (host OOM). Disk is tight: `/root` had about 13 GB
free (97% full) on 2026-10-25, so check `df -h /root` first. Each build tree is about 700 MB;
remove scratch worktrees you no longer need with `git -C /root/llama.cpp worktree remove <dir>`.
- `-DLLAMA_BUILD_UI=OFF` does NOT make the UI asset step harmless. The `llama-ui-assets` step still
runs, and when the build number has no HF tag it falls back to `latest`. On 2026-11-21 `latest`
broke the build (missing `bundle[hash].js`, `.css` and `workbox[hash].js`). Set
`HF_UI_VERSION=<stamp>` for both `cmake -B build` and `cmake --build`, where the stamp is
production's current one in `build/tools/ui/.ui-stamp` (b11906 on 2026-11-21). The file holds
`ggml-org/llama-ui|b11906` and CMake requires `^[A-Za-z0-9._-]+$`, so take only the tag with
`cut -d'|' -f2 build/tools/ui/.ui-stamp`; never pass `$(cat ...)`. The validated
worktree's UI assets may then differ from the deployed ones (the code is identical).
- Long runs: launch detached (`setsid nohup sh X > X.log 2>&1 </dev/null &`) and poll, rather than
holding a `kubectl exec` open for hours.
- The validated build must contain all three targets: `llama-server`, `llama-bench` and
`test-backend-ops` (`--perf` and `--ops` run the last two from `--build`). A build script that
makes only `llama-server` (as the 2026-10-25 `diskcache-build.sh` first did) is not a validated
build.
- Detach only one script. Upload it first (`kubectl exec -i ... sh -c 'cat > /root/arms/X.sh' <
X.sh`), then start it alone: `setsid nohup sh /root/arms/X.sh > X.log 2>&1 </dev/null &`. Do not
background a chain such as `cat > X && sh -n X && setsid ... &` inside the `kubectl exec` shell. The
chain is a child of that session, and it can die with the session before `setsid` runs.
## 6. Validate with `scripts/fork-validate.sh`
Copy the script from the candidate tree (it is in the repo) and run it in two phases. The header of
the script describes each check.
Rule: any test of a production model must use production's exact command line: the `cmd` of its
`/root/config.yaml` entry with the macros expanded, including the mmproj that `-hf` pulls (production
never passes `--no-mmproj` to the 35B or gemma), and supervisord's `environment=`. Change only
`--port`, the arena and scratch paths. The 2026-10-25 deploy of the disk prompt cache aborted on the
first request: every test had used `--no-mmproj`, which hid a `GGML_ASSERT(!has_mtmd)`, and it was
rolled back (FORK.md F11).
```sh
# phase 1, beside production
# production driver environment (supervisord environment=, FORK.md section 5); fork-validate.sh keeps
# GGML_VK_ASYNC_USE_TRANSFER_QUEUE (it unsets every other inherited GGML_*), so both arms run on it
export VK_ICD_FILENAMES=/opt/mesa-26.3.1/share/vulkan/icd.d/radeon_icd.x86_64.json RADV_EXPERIMENTAL=transfer_queue GGML_VK_ASYNC_USE_TRANSFER_QUEUE=1
bash /root/arms/rebYYYYMMDD/scripts/fork-validate.sh \
--build /root/arms/rebYYYYMMDD/build --ref /root/llama.cpp/build --ops --diskcache
```
Add `--arbiter` to phase 1 only if the card has >= 1536 MiB free (8192 MiB minus the bytes in
`cat /sys/class/drm/card*/device/mem_info_vram_used`); below that it FAILs at once. With gemma-26B
warm in production only about 1.2 GiB is free and nothing frees it without downtime; then run
`--arbiter` in the phase-2 swapdown window instead (about 2 minutes more downtime), as below.
**Page cache before and after phase 2.** The `--ref` build may lack F10 (FORK.md), and `--perf`
loads the 35B many times: during a reference arm on 2026-10-25 MemAvailable fell to 27 GB. Run the
eviction snippet of deploy step 3 before phase 2 and again after it (swapdown does not), and check
`/proc/meminfo`.
```sh
# phase 2, with llama-swap stopped: run it under the swapdown wrapper, whose trap restarts llama-swap
cat > /root/arms/fv-perf.sh <<'EOF'
export VK_ICD_FILENAMES=/opt/mesa-26.3.1/share/vulkan/icd.d/radeon_icd.x86_64.json RADV_EXPERIMENTAL=transfer_queue GGML_VK_ASYNC_USE_TRANSFER_QUEUE=1
HUB=/root/.cache/huggingface/hub
Q35=$HUB/models--unsloth--Qwen3.6-35B-A3B-GGUF/snapshots/a483e9e6cbd595906af30beda3187c2663a1118c/Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf
G26=$HUB/models--SC117--gemma-4-26B-A4B-it-qat-heretic-GGUF/snapshots/e6759b29958180a998f62f991e4c741fe9b4d452/gemma-4-26B-A4B-it-qat-heretic-UD-Q4_K_XL.gguf
bash /root/arms/rebYYYYMMDD/scripts/fork-validate.sh \
--build /root/arms/rebYYYYMMDD/build --ref /root/llama.cpp/build \
--arbiter --perf --moecache "$G26" --keep
EOF
setsid nohup sh /root/bench/moe/swapdown.sh /root/arms/fv-perf.sh > /root/arms/fv-perf.log 2>&1 </dev/null &
```
- `G26` is the production SC117 gemma-26B, the `refs/main` snapshot (`e6759b29...` on 2026-10-25;
an older snapshot `82c751632...` is also on disk). If it moves, read the snapshot name from
`$HUB/models--SC117--gemma-4-26B-A4B-it-qat-heretic-GGUF/refs/main`.
- `/root/bench/moe/swapdown.sh <script>` (pod-only helper, not in the repo) stops llama-swap, waits for
an idle GPU, runs the script, and restarts llama-swap from an EXIT/INT/TERM/HUP trap. It prints
`SWAPDOWN_DONE` at the end. Afterwards confirm llama-swap is RUNNING and `/v1/models` returns 200.
- `--moecache` needs a cache that actually hits (default 2048 MiB; at 256 MiB gemma-26B had 0 hits,
which proves nothing).
- `--arbiter` also checks that a cold server really frees its VRAM (`v-vram-release`,
`v-vram-restore`; SKIPs if production's VRAM moved during the measurement, then rerun) and A/Bs
ordinary handoff latency against `--ref` (`a-handoff-latency`). `--ref` must be the build currently
in production, so both comparisons are against what serves today.
- Phase 2 downtime, measured 2026-10-25: about 32 minutes in all (`--arbiter` about 2 min, `--perf`
about 28 min, `--moecache` under 30 s). The `--concat` and `--moe-exact` checks were removed on 2026-11-23
with F3 and F1 (the history entries below still list them).
- `--perf` gates on medians of all repetition samples (since 2512290f9); the samples are in
`<scratch>/perf.tsv`, and `fork-validate.sh --perf-report <file>` re-aggregates them offline. A pod
restart empties `/tmp`, so copy a scratch dir you want to keep to `/root/arms/` (the 2026-10-24
scratch dirs were lost that way).
- Overlayfs (since the persistent rootfs, 2026-11-22): `/tmp` is on overlayfs, where `stat`
reports another device than `/proc/locks` prints, so a scratch arena under `/tmp` made every
token check fail (`arbiter/start: A serves but does not hold token.lock` while A held the lock).
`fork-validate.sh` from `70d39bdbc` on keeps its arenas on `/dev/shm`. Use the script of that
commit or later, also for a `--ref` run of an older build.
- Phase 1 of the 2026-11-22 rebase (candidate build `/root/arms/reb20261122/build`, code
`6c895a491`, scripts `70d39bdbc`, vs production `f3397cded`, beside production with 3579 MiB
free; logs `/root/arms/reb20261122-p1.log`, `-p1b.log`): `--ops --concat --diskcache` 23 PASS
(ops 5/5 with FLASH_ATTN_EXT 5693/5693, concat off/cand 5.3x, diskcache 15/15 including the GPU
legs), `--arbiter` 16 PASS on the rerun with the fixed script (handoff median cand 789.5 / ref
768 ms; the first run's single FAIL was the overlayfs mismatch above). F12: test-backend-ops
SCALE and FLASH_ATTN_EXT OK, `test-flash-attn-indexed-bias` 16 Vulkan0 cases, max error 1.3e-4.
Still to run in the window: phase 2 (`--arbiter --perf --moe-exact --moecache`, the runbook
command with this build path) and the Inkling/F14 items below.
- Overnight window 2026-11-23 (the plan below, run in full; queue runner
`/root/arms/overnight2/runner.sh` with one swapdown window per script, progress log
`/root/arms/overnight2/STATUS.md`): phase 2 `--arbiter --perf --moe-exact --moecache` on
`27c23d20f` vs production `f3397cded`, 29 PASS, 0 FAIL, 0 SKIP in 33 minutes (log
`done/10-win1.log`, scratch copied to `fv-phase2-scratch/`). Perf medians ref -> cand: pp2048
286.29 -> 286.60, d16384 207.77 -> 208.06, d32768 161.48 -> 162.17, tg256@d4096 14.87 -> 14.29
(not gated); handoff median ref 710.5 / cand 699.5 ms; peak VRAM 5478 MiB both. Items 2-5 passed
(FORK.md F12 `--fit` result, F13 window A/B result, F14 items 5-7, F15 window result); Inkling
answers on both entries correct, tool calls work on both (no #32800 HTTP 500, no #32818 grammar
crash). Deployed `ec3bf13f6` (`27c23d20f` + F15) with `LLAMA_LOOP_FULL_COPY=0` on the Inkling
entries; deploy script `/root/arms/overnight2/deploy.sh` (pointer, build copy, config backup,
in-place build, probe, automatic rollback on a failed build or probe), downtime 225 s. Later in the window
(config and environment only, each with its backup): Mesa 26.3.1 with the transfer queue for
llama-swap (`/root/arms/overnight2/mesa-switch.sh on|off`, backup
`/root/supervisord.conf.bak-20261123-mesa`), and `moe_offload_args` `-t 4 -b 4096 -ub 4096`
(backup `/root/config.yaml.bak-20261123-prefinal`); FORK.md section 5. Post-deploy checks of
section 8 passed after the deploy and again after the Mesa switch (`post.log`, `post-mesa.log`).
Two traps: `llama-fit-params` rejects `--mmproj` and `--jinja`, and llama-bench separates
`-ot` overrides with `;` (`,` starts a new test group), unlike llama-server.
- Slimming, 2026-11-23 day windows (status log `/root/arms/run3/STATUS.md`, scripts and logs in
`/root/arms/run3/`, each window under swapdown). Window 1 (09:50-11:26 UTC): candidate C
(`fa89f2cb3`, F1 and F3's gate still in) vs production `ec3bf13f6`, `--ops --concat --arbiter
--perf --moe-exact --moecache --diskcache` 52 PASS, 0 FAIL, 0 SKIP (`fv.log`), plus the ablations
that removed F1 and the gate (FORK.md section 2). Window 3 (11:31-11:57): candidate S
(`ccb58a3dc`, F1 and F3 removed) `--ops --arbiter --moecache --diskcache --perf`: 26 PASS, 2 FAIL
(`fv3.log`). Both FAILs and a silently skipped `--perf` were a script bug, not the code: removing
`--moe-exact` had also removed `gpu_exclusive` and the `--diskcache` prompt helper (FORK.md F9).
Fixed in `a1eb757ea` (script only). Window 4 (11:58-12:53): `--perf --diskcache` with the fixed
script, 19 PASS, 0 FAIL, 0 SKIP (`fv4.log`): pp2048 307.40 -> 321.20 t/s (+4.5%), d16384 220.59
-> 225.22 (+2.1%), d32768 169.86 -> 174.81 (+2.9%), tg256@d4096 11.69 -> 12.74 (not gated), peak
VRAM candidate 5700 MiB; handoff median 635.5 ms both (window 3). Gate check (decode of the other
delta-net / short-conv models without F3's gate, C vs S, `win3.log`, `gate4.log`): Qwen3.5-4B tg256@d4096 -0.4%, Inkling +2.8% (medians of 9 samples, S C C S S C), Inkling concat kernels +0.3 ms per token (perf logger); the gate stays removed. Inkling tool request
(251 tokens, fresh prompt, production command line, S): `-tb 12` 10612 / 9961 ms median prompt
time against `-tb 6` 5231 / 5278 ms, decode unchanged, `get_weather` with city Warsaw in every arm (arguments cut by `max_tokens` 64)
(`inktb-s/`); llama-bench Inkling pp256 and pp2048 with 12 and 6 threads, arms 12 6 6 12: 83.7 / 128.9 t/s either way, so `-tb 6` costs no prefill (FORK.md section 5).
Deployed `92fe769a0` (code of `a1eb757ea` plus the docs) with `/root/arms/run3/deploy.sh`
(pointer 18 = `ec3bf13f6`, build copy `/root/arms/build-ec3bf13f6`, config backup
`/root/config.yaml.bak-20261123-run3`, automatic rollback). The first try rolled itself back at
the checkout: the scratch worktree `/root/arms/reb20261123` had the new branch name checked out
(`fatal: ... is already used by worktree`), production stayed on `ec3bf13f6` with its build
restored from the copy, `/v1/models` 200 (`deploy-try1.log`). After `git checkout --detach` in
that worktree the second try built and probed fine: downtime 129 s, `system_fingerprint`
`b12653-92fe769a0` (`deploy.log`). Section 8 checks (`post.sh`, `post.log`): 35B, 4B task and gemma answers correct with `holder` on the answering PID across 35B/4B/gemma handoffs, gemma image red, both Inkling entries correct on the 59-token first prompt, short, image, tool (`get_weather`, city Warsaw) and a 29.4K-token Pan Tadeusz prompt (94.4 / 92.1 t/s prefill), disk cache saved and restored (1157 tokens, restored in 172 ms), log scan 0 asserts or Vulkan errors, Mesa 26.3.1 variables in every llama-server environ, power cap 120 W, children on llama-swap ports, pod restarts 0; dmesg shows a memory-cgroup OOM kill of nginx-ingress processes (their own cgroup limit, no llama process) during the checks.
- What the 2026-11-22 window must run, in this order (GPU to itself under swapdown; about 75-90
minutes in all):
1. Phase 2 as written above with `W=/root/arms/reb20261122` (about 32 minutes).
2. F13 vs upstream's #32807 (FORK.md F13, "Window A/B to run": memory, `kld48.sh`, speed with
`LLAMA_LOOP_HOST_VIEWS=0` and `LLAMA_LOOP_FULL_COPY=0`).
3. `--fit` vs the k=4 `-ot` for Inkling (FORK.md F12, "How to use it for Inkling"). Smoke run
beside production (3.5 GiB free, so not a placement result; `/root/arms/reb20261122-fit-smoke.log`):
fit's loop path runs on Inkling; the probing took 27.8 s, which every Inkling cold start would
pay with `--fit` in the config (freeze the printed `-ot` instead); the projected memory is not
monotonic in `n_layer` (5173 MiB at 44, 6736 at 43) and fit still reported success with -3116
MiB free. Check both with the full card.
4. F14 refinement (FORK.md F14, validation plan items 5-7): the new-chat checkpoint, its disk-cache
variant and the M-only TTFT table, with the 35B think entry's exact command line.
5. The Inkling post-deploy items of section 8 step 8 against a scratch server of the candidate:
#32799 changed Inkling's tokenization, so judge the answer text.
- F14 run (2026-11-22, candidate `f3397cded` = `166ec22e2` (docs on `b13c41355`) + F14, server-only change; one
swapdown window, `/root/arms/usw-window.sh`, log `/root/arms/usw-window.log`, about 15 minutes):
the 35B TTFT A/B with and without `LLAMA_USERSTART_MERGE=0` (FORK.md F14, M U U M, production 35B
think command line with the mmproj), `--diskcache` 15 PASS, 0 FAIL, 0 SKIP, and the
`diskcache-window3.sh` 35B legs (all passed). The full `--perf`/`--arbiter` set was not rerun: the
change touches only the server prompt-batch loop. Deploy downtime 33 s (incremental in-place
build).
- Last full run (2026-11-22, candidate `b13c41355` = `3621025e8` + F13 vs reference `3621025e8`, one
swapdown window, `--ops --concat --diskcache --arbiter --perf --moe-exact --moecache`, log
`/root/arms/overnight/fv.log`): 52 PASS, 0 FAIL, 0 SKIP in 41 minutes. Perf medians ref -> cand:
pp2048 286.61 -> 284.94 (-0.6%), d16384 207.93 -> 207.96, d32768 161.93 -> 162.12, tg256@d4096
14.11 -> 14.47; handoff median ref 715 / cand 706.5 ms; peak VRAM ref 5478 / cand 7771 MiB (the
first-arm spike of FORK.md F9, this time in a candidate arm). With the card free, phase 1 and 2
can run as one invocation like this.
- Previous full run (2026-11-22, candidate `3621025e8` = `3bf6b55b3` + the F12 carries, vs reference
`3bf6b55b3`; logs `/root/arms/carry1122-p1.log`, `-p2.log`): phase 1 `--ops --concat --diskcache`
20 PASS, 1 FAIL (`concat/candidate-timing` beside a full card, see above), 1 SKIP (diskcache GPU
leg); phase 2 `--concat --arbiter --diskcache --perf --moe-exact --moecache` 47 PASS, 0 FAIL, 0
SKIP. Perf medians ref -> cand: pp2048 286.97 -> 286.32, d16384 208.31 -> 208.21, d32768 162.25 ->
162.37; handoff median ref 696 / cand 700 ms; peak VRAM ref 7771 / cand 5502 MiB. Plus SCALE
15/15 and `test-flash-attn-indexed-bias` (FORK.md F12). Window about 30 minutes.
- Earlier full run (2026-11-21, candidate `3bf6b55b3` vs reference `adc2aa3ec`): phase 1 39 PASS, phase 2
9 PASS plus the 35B disk-cache legs (`q35.py`, mmproj loaded). Perf medians ref -> cand: pp2048
259.39 -> 286.61 (+10.5%), d16384 199.26 -> 207.63 (+4.2%), d32768 156.61 -> 157.51 (+0.6%),
tg256@d4096 9.17 -> 8.85 t/s (noisy, not gated). Handoff median: candidate 692 ms, reference
1068 ms. Downtime: about 42 minutes of validation and about 7 minutes of deploy.
- Earlier full run (2026-10-25, candidate `2fc9f9c35` vs reference `6c480f7e7`, logs
`/root/arms/dep-2fc9f9c35-fv1.log` and `-fv2.log`): phase 1 `--ops --concat` 8 PASS, phase 2
`--arbiter --perf --moe-exact --moecache` 29 PASS; 37 PASS, 0 FAIL. Perf medians ref/cand: pp2048
274.53/273.82, d16384 200.52/200.37, d32768 157.60/157.57, tg256@d4096 16.82/16.66 t/s. Handoff
median ref 693.5 / cand 678 ms. `--moe-exact`: 39 skips logged, identical to the reference and to
the skip forced off. Peak VRAM per arm ref 5476, cand 7062, cand 5767, ref 5476 MiB: the ~1.6 GiB
spike in the first candidate arm has now been seen twice (open question, FORK.md F9).
- Any arbiter change: `a-handoff-latency` is the ordinary-handoff A/B that two lost deploys showed
is needed. For a change aimed at latency itself, also run more blocks by hand; 25%/200 ms is a
regression gate, not a measurement.
- Disk prompt cache (FORK.md F11, from `fable5/disk-prompt-cache`): add `--diskcache` to phase 1. It
is CPU only and runs beside production (about 2 minutes). Its GPU leg SKIPs below 1536 MiB of free
VRAM; then run `--diskcache` again in the phase-2 window. A 35B measurement driver is on the pod:
`/root/arms/diskcache-test/q35.py [CHARS]` (scratch port 8095, scratch arena and cache dir, the
production 35B flags, a pan-tadeusz conversation; about 6 minutes). The 2026-10-25 window script
`/root/arms/diskcache-window.sh` (page-cache evictions, `--diskcache --arbiter`, `q35.py`) runs
under swapdown (run 2026-10-25: 29 PASS). `/root/arms/diskcache-window3.sh` runs `q35.py`
with production's exact 35B command line (mmproj loaded): save/restore, cold save, the
same-reuse-point identity and an image request (FORK.md F11). Run 2026-11-21 on adc2aa3ec: all
legs passed (18.8k-token chat, prefill 84.6 s -> turn 2 4.7 s after the restart, identical
output; save 557 MB in 1.0 s, token free 0.34 s, peak RSS +430 MB; cold save identity; image
answered and not saved; log `/root/arms/diskcache-test/q35-mm.log`). It supersedes
`diskcache-window2.sh` (`cmp.py` runs with `--no-mmproj`).
`q35.py` and the window scripts live only on the pod (not in the repo) and hard-code a build path.
Before each use, edit them to point at the candidate build (`/root/arms/rebYYYYMMDD/build`), not
production's `/root/llama.cpp/build`, or you validate the wrong binary.
On any FAIL: stop and report; the scratch dir (`/tmp/fork-validate.*`) is kept with all logs.
## 7. Deploy
Deploy exactly the validated commit. Downtime: 6 minutes for the 2026-10-24 redeploy. The deploy
rebuilds the production tree in place (step 6) from the same commit and with the same cmake flags as
the validated worktree build, so nothing is copied over; compare
`grep -E 'GGML_NATIVE|LLAMA_BUILD_UI|BUILD_SHARED_LIBS|CMAKE_BUILD_TYPE' build/CMakeCache.txt` in both
trees if in doubt.
Run the stop, build and start (steps 4-7) as one script on the pod, started with `setsid nohup sh
<script> > <log> 2>&1 </dev/null &`, never as a backgrounded `cat && sh -n && setsid` chain from the
`kubectl exec` shell (see section 9).
1. **Rollback pointer.** Record the current production commit in the next free pointer file, as the
full SHA alone on line 1 (older files mix full SHAs, short SHAs and extra text; see section 9):
```sh
ls /root/DEPLOY-ROLLBACK-commit-*.txt # last used: 18 (holds ec3bf13f6)
git -C /root/llama.cpp rev-parse HEAD > /root/DEPLOY-ROLLBACK-commit-19.txt
git -C /root/llama.cpp status --short # must be clean
```
2. **Check out the candidate** in the production tree (fetch first; the branch must be on gitea, or already local after a bundle fetch, section 3):
```sh
cd /root/llama.cpp
git fetch origin fable5/vram-ondemand-rebase-YYYYMMDD
git checkout -B fable5/vram-ondemand-rebase-YYYYMMDD <validated-commit>
```
On a redeploy with the same branch name this moves the production branch to the new commit.
`git checkout -B` refuses a branch that a scratch worktree has checked out (`git worktree list`);
detach that worktree first (`git -C <worktree> checkout --detach`). The 2026-11-23 deploy rolled
back once on this.
3. **Evict the page cache.** The pod is BestEffort QoS on a shared 62 GB node, so it is the first OOM
victim, and benchmarks, mmap loads and builds without F10 leave tens of GB of model files cached.
During the first 2026-10-24 deploy the Talos OOM controller killed the whole pod 17 s into
verification (cause likely, not proven, memory pressure). Evict while production still runs
(unprivileged and safe: `-lm none` servers hold their weights in anonymous memory, and pages
mapped by an mmap model are not dropped). The same snippet is used before and after validation
phase 2:
```sh
python3 - <<'EOF'
import glob, os
n = 0
for root in ('/root/.cache/huggingface/hub', '/root/models'):
for p in glob.glob(root + '/**/*.gguf', recursive=True):
fd = os.open(p, os.O_RDONLY)
try:
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)
n += 1
finally:
os.close(fd)
print('evicted', n, 'files')
EOF
```
F10 (FORK.md) drops the cache of every `-lm none` load by itself (verified in production on a 35B
GPU load: node page cache stayed at 4.2-5.3 GB instead of growing by about 20 GB), but files cached
by mmap loads, benchmarks or older builds still need this step. `/sys/fs/cgroup/memory.stat`
inside the container is the HOST root cgroup; the pod's own cgroup is under
`/sys/fs/cgroup/kubepods/besteffort/pod<uid>/`.
4. **Back up the current build, then stop llama-swap and reap orphans.** The deploy rebuilds
`/root/llama.cpp/build` in place, so copy it first (production keeps serving during the copy);
rollback (section 9) is then a copy, not a rebuild. Check `df -h /root` first (about 850 MB; the
2026-11-21 deploy made `/root/arms/build-adc2aa3ec`, 851 MB):
```sh
cp -a /root/llama.cpp/build /root/arms/build-<oldsha> # <oldsha>: the HEAD recorded in step 1
```
Delete the copy once the deploy is confirmed stable. Then:
```sh
supervisorctl -c /root/supervisord.conf stop llama-swap
ps -eo pid,ppid,etimes,args | grep '[l]lama-server'
kill -TERM <pid> <pid> # explicit PIDs only, never pkill -f
ps -eo pid,args | grep '[l]lama-server' # must be empty
```
`supervisorctl stop llama-swap` has left its llama-server children running as orphans (ppid 1),
one still generating for a client for a minute. They exit within about 1-2 s of a SIGTERM. Keep
this check even when it finds nothing (2026-10-25: no orphans).
5. **Check memory**, now that the running models are gone: `grep -E 'MemAvailable|MemFree'
/proc/meminfo`. Proceed only with MemAvailable >= 25 GB. In 2026-10-24 the eviction took node-wide
file cache from 15.6 to 4.9 GB and MemAvailable to 45.8 GB.
6. **Build in place**, now that nothing runs from `/root/llama.cpp/build/bin` (llama-swap's
`LD_LIBRARY_PATH` points there, so do not rebuild it under running servers):
```sh
cd /root/llama.cpp && HF_UI_VERSION=$(cut -d'|' -f2 build/tools/ui/.ui-stamp) \
cmake --build build --target llama-server llama-bench test-backend-ops -j 12
ls -lL build/bin/llama-server build/bin/libllama-server-impl.so build/bin/libllama-common.so \
build/bin/libllama.so build/bin/libmtmd.so build/bin/libggml.so build/bin/libggml-base.so \
build/bin/libggml-cpu.so build/bin/libggml-vulkan.so
```
All must have fresh mtimes. Use `-L` (follow the symlinks): `build/bin` keeps every old versioned
`libggml-*.so.0.x` and `libmtmd.so.0.x`, so a plain `ls` lists stale files beside the new ones.
`llama-server` is a 17 KB stub. The server code is in `libllama-server-impl.so`, the common code
(arguments, sampling) in `libllama-common.so`; a server change shows only in their mtimes.
7. **Start and probe.**
```sh
supervisorctl -c /root/supervisord.conf start llama-swap
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080/v1/models # 200
```
Sample `/proc/meminfo` every few seconds during the first model loads. Confirm the running commit
from the first chat response (section 8): `system_fingerprint` is `b<build number>-<short sha>`
(the build number changes with each rebase; the sha is the deployed commit). The first 35B request after that deploy took 34 s including
the model load and the answer.
8. **Disk prompt cache** (FORK.md F11), only once `--cache-disk-path` is in `/root/config.yaml`:
- Every deploy empties the cache: the key holds the build commit, so the previous build's files are
never restored. They stay in the directory as "other files" until the size limit evicts them.
To free the space at once, `rm /root/prompt-cache/*.lpcd` while llama-swap is stopped (step 4).
- Check `/root` free space (`df -h /root`; 11-13 GB on 2026-10-25). The cap (`--cache-disk-size`)
plus a 1 GiB floor bounds the cache, but builds and model downloads share the PVC.
- Stopping llama-swap takes longer: each large model writes its slot state on SIGTERM, about 1 s
per GB of state, before it exits (FORK.md F7, F11).
## 8. Post-deploy checks
All through llama-swap on :8080. A request helper:
```sh
ask() { curl -s -m 300 http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' \
-d "{\"model\":\"$1\",\"messages\":[{\"role\":\"user\",\"content\":\"$2\"}],\"max_tokens\":32,\"temperature\":0}"; echo; }
holder() { ino=$(stat -c %i /dev/shm/llama-vram/token.lock); grep "FLOCK.* WRITE .*:$ino " /proc/locks; }
# image request body: a 64x64 solid red binary PPM, no image tools needed (like fork-validate.sh)
img() { python3 - "$1" <<'EOF'
import base64, json, sys
ppm = b'P6\n64 64\n255\n' + b'\xff\x00\x00' * (64 * 64)
url = 'data:image/x-portable-pixmap;base64,' + base64.b64encode(ppm).decode()
print(json.dumps({'model': sys.argv[1], 'max_tokens': 32, 'temperature': 0, 'messages': [{'role': 'user',
'content': [{'type': 'image_url', 'image_url': {'url': url}},
{'type': 'text', 'text': 'What is the main colour of this image? One word.'}]}]}))
EOF
}
# img MODEL | curl -s -m 300 http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' -d @-
```
Use the `-nothink` aliases with these `max_tokens: 32` helpers. A thinking alias spends the 32 tokens
on `reasoning_content` and returns an empty `content`; for one, raise `max_tokens` to >= 512.
1. `ask 'unsloth/Qwen3.6-35B-A3B-GGUF-nothink:UD-Q4_K_XL' 'Capital of France? One word.'` answers;
`holder` shows the 35B's PID (check with `ps -o args -p <pid>`).
2. Handoffs: alternate `Qwen3.5-4B-task:Q4_K_M` and the 35B two or three times. Each answer is
correct and `holder` shows the PID of the model that just answered. Expect a few seconds per switch
(2026-10-24: 3.1-5.6 s).
3. Multimodal: one image request to `SC117/gemma-4-26B-A4B-it-qat-heretic-GGUF-nothink:UD-Q4_K_XL`
with the `img` helper; the answer names red. This also forces an eviction in the llama-swap matrix: the
evicted process must exit by itself, logging `VRAM arbiter: loop stopped, device memory freed,
releasing the GPU token`, with no kill escalation.
4. Text to gemma and to the 4B after the eviction; `holder` correct each time.
With the disk prompt cache on (F11): send the 35B a chat of at least 256 tokens before step 3.
Its eviction must log `disk cache: saved the prompt of N tokens`. Then resend the same chat plus one
new user message to the 35B (earlier messages must stay byte-identical: editing an earlier message
changes the prefix and legitimately gives no restore): the log shows `disk cache: restored`, and `timings.prompt_n` is
only the new suffix.
5. Ports: the children bind the `--port ${PORT}` values llama-swap passes (not upstream's default 9931).
6. Log scan of the new llama-swap log lines (`curl -s http://127.0.0.1:8080/logs`) for
`GGML_ASSERT|Assertion|terminate called|Segmentation fault|ErrorDeviceLost|ErrorOutOfDeviceMemory|DEVICE_LOST`: none.
7. `dmesg` clean (no `ring ... timeout`, no `GPU_HUNG`). No pod restart and no OOM kill:
- Restarts, from the workstation: `kubectl get pods -n llama | grep supervisord`; RESTARTS of the
Running pod must equal the value you noted before the deploy. A stale `supervisord-...-pbmjq`
in state `Unknown` is also listed; it is an old leftover, ignore it.
- OOM kills, in the pod: `dmesg | grep -E 'OOM controller|Sending SIGKILL to cgroup'`. The
timestamps are seconds since boot; compare them with the first field of `/proc/uptime` to see
whether any falls in the deploy window (2026-10-25: the newest was about 19 h old).
8. Inkling (FORK.md section 5, F12): judge the answer text, not only HTTP 200. The first request
after a fresh load should be a prompt of about 150 tokens (upstream #32778 gives all-'?' output
there); then a long prompt (Pan Tadeusz, 8K and 14K tokens, upstream #32755). Send an image
and a tool request to both entries: since the nothink macro dropped `--reasoning-budget 0`
(FORK.md F12) both answer them; repeated `<|message_model|><|content_thinking|><|end_message|>`
from the nothink entry means a budget of 0 is back. Since F13 a scratch server with the
production command line plus `-lv 4` must log `post_load_tensors: N views of host weights`
(production's own log level hides libllama's info lines, so the llama-swap log never shows it),
and the entries no longer set
`GGML_OP_OFFLOAD_MIN_BATCH=64` (F13 measured the 32-63-token window correct without it). The
placement is `-ot` with the loop layers 6..6+k-1 left on the GPU (FORK.md F13 placement guide);
after a change of context or quant, check the fit again (the breakdown must leave room for the
mmproj, about 0.8 GiB). The memory breakdown table is printed only at `-lv 4`,
which production does not set, so it is not in the llama-swap log: read it from a scratch server
started with production's command line plus `-lv 4`. Drivers used on 2026-11-22 (pod only):
`/root/arms/carry1122-post.py` (through llama-swap) and `/root/arms/carry1122-ink-direct.py`
(scratch server, GPU to itself).
A wedged arbiter looks like this: requests hang while `/health` still returns 200, and `/proc/locks`
shows a process holding WRITE on `token.lock` that is not generating. llama-swap restarts a child
that exits (on the next request for its model, FORK.md F7) but never one that wedges. Inspect it with
`gdb -p <pid> -batch -ex 'thread apply all bt'` before killing it. gdb is not in
the pod image; it was lost in the 2026-10-24 pod restart, but the rootfs persists since 2026-11-22 (section 11), so
an apt install now stays. Check `command -v gdb` and install it first if needed.
## 9. Rollback
```sh
supervisorctl -c /root/supervisord.conf stop llama-swap
ps -eo pid,args | grep '[l]lama-server' # SIGTERM any orphan by PID
cd /root/llama.cpp
git checkout -B <previous-production-branch> "$(head -1 /root/DEPLOY-ROLLBACK-commit-N.txt | cut -d' ' -f1)"
HF_UI_VERSION=$(cut -d'|' -f2 build/tools/ui/.ui-stamp) cmake --build build --target llama-server llama-bench -j 12
supervisorctl -c /root/supervisord.conf start llama-swap
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080/v1/models
```
This is the fallback when no build backup exists. With the deploy step 4 backup, roll back by copy
instead (stop, checkout the old commit, replace the build dir, start):
```sh
supervisorctl -c /root/supervisord.conf stop llama-swap
ps -eo pid,args | grep '[l]lama-server' # SIGTERM any orphan by PID
cd /root/llama.cpp
git checkout -B <previous-production-branch> <oldsha>
mv build /root/arms/build-failed-<newsha> # or rm -rf build; mind the disk
cp -a /root/arms/build-<oldsha> build
supervisorctl -c /root/supervisord.conf start llama-swap
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080/v1/models
```
Once the new deploy is confirmed stable, delete the copy (`rm -rf /root/arms/build-<oldsha>`; the
disk is about 98% full) and any `build-failed-*` directory.
Then run the post-deploy checks again. Roll back on any failed check; report rather than debug in
production. Keep the candidate worktree for a later redeploy.
If you run the rollback (or the deploy steps 4-7) from a workstation through `kubectl exec`, put the
whole sequence in one script on the pod and start it as `setsid nohup sh /root/arms/rollback.sh >
/root/arms/rollback.log 2>&1 </dev/null &`. Do not background a `cat > X && sh -n X && setsid ...`
chain in the exec shell: it can die with the exec session halfway, leaving llama-swap stopped (section
5). A rollback that also undoes a config change (for example removing `--cache-disk-path` from
`/root/config.yaml`, F11) needs the config restored first, from its `/root/config.yaml.bak-*`.
Pointer files 2 to 18 exist; for example commit-8 holds `64543a435`, commit-9 `5751c977b`,
commit-10 `6c480f7e7`, commit-11 was used by the failed cb48bf224 deploy, commit-12 holds
`2fc9f9c35`, commit-13 holds `adc2aa3ec`, commit-14 holds `3bf6b55b3`, commit-15 holds `3621025e8`,
commit-16 holds `b13c41355`, commit-17 holds `f3397cded` (config backup
`/root/config.yaml.bak-20261123-predeploy`: it removes the Inkling `LLAMA_LOOP_FULL_COPY=0` env), and
commit-18 holds `ec3bf13f6`, the rollback target for the slimmed production branch
`fable5/vram-ondemand-rebase-20261123` (next free: 19; build copy `/root/arms/build-ec3bf13f6`; config
unchanged by that deploy, backup `/root/config.yaml.bak-20261123-run3`; branch
`fable5/vram-ondemand-rebase-20261122`). After that deploy `inkling_args` went from `-tb 12` to
`-tb 6` (config only, backup `/root/config.yaml.bak-20261123-tb`); a rollback to commit-18 can keep
it. The formats vary
(commit-4 to 6 hold short SHAs, commit-6 has branch and date after the SHA, commit-9 a subject on
line 2), hence `head -1 | cut -d' ' -f1`. New pointers: the full SHA alone on line 1.
## 10. Recovering a hung GPU
Symptoms: a process that survives SIGKILL (stuck in the driver); `ring sdma1 timeout` or
`ring comp_... timeout` in the kernel log; after a reboot the supervisord pod sits in FailedMount with
`/dev/kfd is not a character device` / `/dev/dri is not a directory`, and
`talosctl get pcidevices` lists no VGA device (the RX 580 and its HDMI audio function are missing).
A warm reboot does not bring the card back (classic Polaris failed reset).
The node (`anapistula-delrosalae`, Talos, bare metal) has a NanoKVM at http://192.168.255.8.
Credentials: ask the owner. Procedure (owner's instructions, follow exactly):
1. Soft shutdown: **one short press** of the power button through the NanoKVM.
2. **Never use the reset button.** It does not cut GPU power and is useless here.
3. Wait until the power LED goes off.
4. Press the power button once more to boot.
5. Only if the LED is still on 10+ minutes after the short press: one **long press of 8 seconds** to
force power off, wait for the LED to go off, then a short press to boot. With the GPU off the bus the
soft shutdown has hung before (Talos services stopped, LED stayed on), and the long press was needed.
Talos access from the workstation:
```sh
export TALOSCONFIG=/home/user/Projects/klaster/talos/generated/talosconfig
nix run nixpkgs#talosctl -- -n anapistula-delrosalae get pcidevices
nix run nixpkgs#talosctl -- -n anapistula-delrosalae dmesg
```
Afterwards: pod Running, RX 580 listed, llama-swap RUNNING, `/v1/models` 200, and the 120 W cap active:
`cat /sys/class/drm/card*/device/hwmon/hwmon*/power1_cap` reads `120000000` (the
`power1_cap ... -> 120000000` line in `/tmp/fan-control.log` may be missing after a pod restart). The two 2026-10-09 hangs both came at the
first 4096-token prefill right after a decode phase, before the cap was fixed at 120 W; both a fork
and a clean-upstream build hung, so they were treated as hardware/power, not code.
## 11. Operations reference
Pod access:
```sh
export KUBECONFIG=/home/user/Projects/klaster/talos/generated/kubeconfig
kubectl -n llama exec -i deploy/supervisord -- sh -c '<command>'
kubectl get pods -n llama -l app=llama-swap -o name # the pod name changes across restarts
```
Alternative (since 2026-11-22): the pod runs sshd, so `ssh root@2001:470:61a3:400::7` works instead
of `kubectl exec` (`scp 'root@[2001:470:61a3:400::7]:/path' .` for files). The same rules apply:
detach long runs with `setsid nohup ... </dev/null &` and never `pkill -f`.
Dropped ssh sessions (looked at 2026-11-23): not sshd. Its settings are the defaults
(`MaxStartups 10:30:100`, `LoginGraceTime 120`, no `ClientAliveInterval`), the workstation
multiplexes every session over one ControlMaster connection (so a drop kills all of them at once),
and the pod's conntrack table is far from full. The drop seen at 09:34 UTC that day coincided with
the workstation losing its IPv6 default route and with the node's own outbound connections
(Talos discovery, IPv4) failing in the same minute; `dmesg` shows such resets every few hours. The
2001:470::/32 addresses are a Hurricane Electric tunnel, so the path rides the homelab's IPv4
WAN: suspect that path (or the client network), not the pod. `kubectl` uses the same IPv6 path
(the API is `2001:470:61a3:100::3`), so it is no fallback when IPv6 is down. sshd is started
without `-e` and the pod has no syslog, so it logs nothing; to diagnose a future drop, run it with
`-e -E /root/sshd.log` (not changed).
The pod's root filesystem now persists across pod restarts: packages installed with apt (gdb,
for example) stay installed. `/tmp` and `/run` are still wiped on every boot, so copy a scratch dir
you want to keep (fork-validate's `/tmp/fork-validate.*`) to `/root/arms/`.
Benchmark methodology (moved here from the `scripts/rx580-bench` README when that harness was
removed on 2026-11-23; the trap behind each rule is in FORK.md section 6):
- One llama-bench invocation per comparison wherever possible (comma-separated sweeps: `-t 6,4,4,6`,
`-d 0,16384`). Its error bars understate cross-invocation variance about 14x (276.7 +/- 0.9 and
296.4 +/- 0.6 for the same config), so two separate invocations differ by up to about 7% from noise.
- Two builds cannot share an invocation: interleave them in alternating order (ref, cand, cand, ref,
at least two arms each) and compare the MEDIAN of all repetition samples per build, never means
(CPU contention gives single catastrophic samples). Deltas under about 5% are unproven.
- Decode: tg256 at an explicit depth (`-p 0 -n 256 -d 4096`), never tg32 at the default depth
(launch-bound; it once read -36% for two commits at parity). Compare only same-depth cells.
- Prefill: `-p` a multiple of `-ub` (a partial trailing ubatch costs a full expert upload);
pp2048 at `-d 0,16384,32768` is the continuity metric (`fork-validate.sh --perf`).
- Threads: the 35B serves with `-t 4` for decode and `-tb 12` for batches (FORK.md section 5; on
this contended node fewer decode threads win). llama-bench has no `-tb` (a bad flag prints usage
and no rows, so check the row count); its `-t` sets both, so bench each phase with the thread
count production uses for it.
- `test-backend-ops -b Vulkan0`, never `-b Vulkan` (matches nothing, runs 0 cases, still exit 0).
- Nothing else on the GPU: run the window script under `/root/bench/moe/swapdown.sh` (restarts
llama-swap from a trap) and export production's three driver variables in it (FORK.md section 5).
- The harness's last corpus reference (2026-09-08/09, fixed `pan-tadeusz.txt` slices through
`/completion` with `cache_prompt: false`; upstream / fork): 4k 240 / 255 t/s, 16k 206 / 225, 32k
171 / 195. Results stay in `/root/bench/results.txt`; the code is in git history
(`git show fable5/vram-ondemand-rebase-20261122:scripts/rx580-bench/README.md`).
Wiring: k8s service `llama:11434` -> pod port 8080 (selector `app=llama-swap`) -> llama-swap `:8080`;
a Caddy proxy fronts `llama.lumpiasty.xyz`. llama-swap must listen on `:8080`.
Files (all under `/root`, a persistent volume):
- `/root/llama.cpp`: production tree, built in `build/` (shared libraries, so the real code is in
`build/bin/libllama.so` and `libggml-*.so`). Scratch worktrees go in `/root/arms/`.
- `/root/supervisord.conf`: supervisord (PID 1). `[program:llama-swap]` runs
`/root/llama-swap -config /root/config.yaml -listen :8080 -watch-config`; its `environment=` sets
`PATH` and `LD_LIBRARY_PATH` to `/root/llama.cpp/build/bin` and the arbiter variables (FORK.md section 5).
- `/root/config.yaml`: llama-swap models, macros (`moe_offload_args`, `moe_offload_gemma`,
`common_args`), matrix/exclusivity sets, preload. Backups `/root/config.yaml.bak-*`. Edit only with
the owner's approval.
- `/root/fan-control.sh`: fan curve and the fixed 120 W cap (separate supervisord program).
- `/root/bench/`: benchmark results and pod-side helpers (`/root/bench/moe/swapdown.sh`).
- `/root/DEPLOY-ROLLBACK-commit-N.txt`: rollback pointers.
- `/root/prompt-cache/` (configured 2026-11-21, `--cache-disk-path /root/prompt-cache
--cache-disk-size 4096` in the `moe_offload_args` and `moe_offload_gemma` macros; backup
`/root/config.yaml.bak-diskcache-20261121`): disk prompt cache files `*.lpcd` of every model
with the flag (FORK.md F11). Production check: a 35B 4.6k-token chat was saved on eviction (278.6
MiB, copy 126 ms, write 495 ms), restored after the reload (read 416 ms, restore 33 ms) and turn 2
prefilled 32 tokens; a gemma image request works with the flags on and is not cached. Safe to empty while llama-swap is stopped.
- `/dev/shm/llama-vram/`: production arbiter arena (`token.lock`, `want.lock`; an inert `doorbell/`
directory from the old design may remain). Never point a test at it.
Reloads: a `config.yaml` change is picked up by `-watch-config`, but a running model keeps its old
arguments until it restarts (`supervisorctl -c /root/supervisord.conf restart llama-swap`). An
`environment=` change needs `supervisorctl -c /root/supervisord.conf reread && supervisorctl -c
/root/supervisord.conf update`.
Useful commands:
- VRAM in use: `cat /sys/class/drm/card*/device/mem_info_vram_used`.
- Token holder and waiters: `/proc/locks` filtered by the inode of `token.lock` / `want.lock`
(WRITE = holder on token.lock, READ = registered waiters on want.lock).
- 120 W cap active: `cat /sys/class/drm/card*/device/hwmon/hwmon*/power1_cap` = `120000000`.
- The pod has `curl`, `python3`, `flock`; no `jq`, and `gdb` only if installed with apt (it persists
since 2026-11-22; without it `fork-validate.sh` runs its SIGTERM-in-release case by polling the log).
Second test box (optional): `ssh user@gaming-pc`, the owner's NixOS desktop with an RX 6600 (RDNA2).
Pod-built binaries can run there through the host glibc loader without compiling. Numbers from it do
not transfer: about 2.25x the RX 580's prefill, 13% slower decode, and the GCN-only mask_opt change does
not apply. Do not change its system config.
Not a fork problem: OpenWebUI's stop button does not cancel generation (its Redis task-command listener
never handles the stop); llama-server and llama-swap both cancel correctly on client disconnect.