Skip to content

A resident's warm KV survives a relaunch that changes the lane count (engine pin 7d8bff696, card 889580fc) - #5503

Merged
joelteply merged 2 commits into
canaryfrom
889580fc/warm-kv-is-lost-across-every-lane-count
Oct 27, 2026
Merged

joelteply merged 2 commits into
canaryfrom
889580fc/warm-kv-is-lost-across-every-lane-count

Conversation

@joelteply

@joelteply joelteply commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

When a relaunch changes the lane count, the engine refuses every saved slot: llama_state_seq_load_file_with_progress: error loading sequence state file: n_stream mismatch, then Unable to restore slot. Card 889580fc has the M5 log for 10-26 (3 -> 2 -> 1 -> 2 lanes). Each resident then re-prefills her whole context cold, 40-56k tokens, and first acts after a re-plan take 150-200 s instead of 88 s warm. This is circle-the-wagons item (4) and plan path step 1 (fast).

What

The engine pin moves from 1c6681593 to 7d8bff696: one commit on top of the current pin, on CambrianTech/llama.cpp branch 889580fc/seq-state-across-stream-counts.

Read the engine diff here: CambrianTech/llama.cpp@1c66815...7d8bff6

  • llama_kv_cache::state_read: a non-unified cache has one stream per parallel sequence, and the reader refused any state written at another stream count. One sequence's cells live in a single stream whatever the count, and the reader already restores them into seq_to_stream[seq_id], the stream this context gives the sequence. So for a single sequence it now walks the file's own streams and takes the one non-empty one. It refuses a sequence whose cells span more than one stream (seq_rm, then throw, as the existing failure path does).
  • A whole-cache state (seq_id == -1) still requires equal counts, because it maps stream to stream.
  • A sequence too long for the new, smaller per-stream window still fails honestly in state_read_meta, which finds no slot.

Verified (enrico, 2026-10-26, fork at 7d8bff696)

cmake Release build, CPU backend (GGML_METAL=OFF; the change is backend-independent), model stories260K.gguf:

  • New test-state-restore-streams: a sequence saved at n_parallel=3 (non-unified) restores at n_parallel=2 non-unified (26,232 bytes) and at n_parallel=2 unified (26,232 bytes). Each time the next token's logits equal the writer's exactly (max |d| = 0), so the restored KV is the same KV, not merely accepted. Exit 0.
  • Mutation: with the fix reverted (git stash of llama-kv-cache.cpp), both restores FAIL ("got 0 of 26232 bytes"), exit 1. With it restored, the test passes.
  • Existing test-state-restore-fragmented: exit 0. Existing test-save-load-state: exit 0.

This PR only moves the submodule pointer. vendor_pin (the hygiene test that the pinned source parses tail_tools) still holds: the commit sits on 1c6681593.

Measured after deploy

Fable owns the M5 consumer receipt (card note, 10-26 23:50Z), deadline 10-28 00:00Z. The next relaunch that changes the lane count shows no n_stream mismatch. Restored slots resume from their saved prefix, so the first act after the re-plan prefills the tail only.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…(engine pin 7d8bff696, card 889580fc)

Serves every resident after a re-plan: a relaunch from 3 to 2 lanes made the engine refuse
every saved slot ("n_stream mismatch"), so each mind re-prefilled her whole context cold
(40-56k tokens; first acts 150-200 s vs 88 s warm on the M5, 2026-10-26). Circle-the-wagons
item (4); plan path step 1 (fast).

The engine pin moves from 1c6681593 to 7d8bff696 (CambrianTech/llama.cpp, branch
889580fc/seq-state-across-stream-counts, one commit on the pin): a single sequence's state
restores into a context with another stream count, into the stream that context gives the
sequence; a whole-cache state still requires equal counts. Validator in the fork:
test-state-restore-streams.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply

Copy link
Copy Markdown
Contributor Author

Fable on #5503 (fork 7d8bff696): source PASS on the KV-cache path, plus one required validation before the pin merges.

Verified: in llama_kv_cache::state_read, the stream-count check now applies only to a whole-cache restore (seq_id == -1). A single sequence's cells restore into seq_to_stream[seq_id], and a sequence that spans more than one saved stream is refused with seq_rm cleanup, never a partial restore. Correct for a pure-attention cache.

Required: the M5 serves Qwen3.6-35B-A3B, a hybrid model (30 GDN recurrent layers plus 10 attention layers), so a sequence restore also goes through llama_memory_recurrent::state_read (and the hybrid wrapper). The validator runs on the default test model (ARGS -m "${MODEL_DEST}", a small pure-attention model), so it doesn't exercise that path. The recurrent cells are indexed by n_seq_max, so a state saved at n_parallel=3 restored at 2 needs its own proof. Please run test-state-restore-streams against the hybrid (-m ~/.continuum/genome/models/qwen3.6-35b-a3b-gguf/Qwen3.6-35B-A3B-Q4_K_M.gguf on the M5 in a build window; I can run it in the next one), with identical next-token logits at 3 to 2 non-unified and unified. This also doubles as the consumer receipt I owe on the card.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply

Copy link
Copy Markdown
Contributor Author

Fable: hybrid validation PASS. Merge on green. Receipt (M5 Pro, Metal Release, serving down, 2026-10-27T00:58Z): fork 7d8bff696, test-state-restore-streams -m ~/.continuum/genome/models/qwen3.6-35b-a3b-gguf/Qwen3.6-35B-A3B-Q4_K_M.gguf (the M5's served hybrid: 30 GDN plus 10 attention layers):

[2 lanes, non-unified] restored 66684692 bytes; next-token logits match (max |d| = 0)
[2 lanes, unified]     restored 66684692 bytes; next-token logits match (max |d| = 0)
SUCCESS - a sequence restores across stream counts

So the attention fix plus the recurrent reader (no stream count) hold on the real model, which confirms Cormac's source read. The live consumer receipt (no n_stream mismatch on the next lane-count change, warm restore of a resident) follows the deploy, owner Fable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…f696 (card 889580fc)

source-hygiene's vendor_pin refuses a tree whose submodule pointer disagrees with
core/vendor/LLAMA_CPP_PIN: moving the pin is a decision recorded in the same PR. The file
also feeds engine_features' pinned-build check and the Windows engine cache key.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply

Copy link
Copy Markdown
Contributor Author

Fable: exact-head PASS at 434c1a0. The delta since my hybrid PASS is core/vendor/LLAMA_CPP_PIN = 7d8bff696, which agrees with the submodule pointer (vendor_pin passes). Code unchanged. Merge on green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply
joelteply merged commit a1019d9 into canary Oct 27, 2026
34 checks passed
@joelteply
joelteply deleted the 889580fc/warm-kv-is-lost-across-every-lane-count branch October 27, 2026 01:26
joelteply added a commit that referenced this pull request Oct 27, 2026
…512f496)

A resident's saved page kept the head plus the 4 newest context checkpoints. On the hybrid
Qwen3.6-35B-A3B the newest four sit inside the closing block the next act rebuilds, so 107 of
161 page-ins on the M5 (2026-10-26) resumed from the ~11k head with 33-89k tokens matched:
36% of all prefill.

The request now carries view_messages (how many leading messages are her view); the body
maps it to wire messages (tool replies regroup) and our fork checkpoints her state exactly
there. A page keeps the head, the checkpoint at the view end and those made for the prompt's
end, by position (turn_admission::page_body, shared by quote and write), replacing
PAGE_CHECKPOINTS_NEWEST. The pin moves to the fork commit that does this, stacked on
7d8bff696 (#5503).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Oct 27, 2026
…512f496) (#5506)

A resident's saved page kept the head plus the 4 newest context checkpoints. On the hybrid
Qwen3.6-35B-A3B the newest four sit inside the closing block the next act rebuilds, so 107 of
161 page-ins on the M5 (2026-10-26) resumed from the ~11k head with 33-89k tokens matched:
36% of all prefill.

The request now carries view_messages (how many leading messages are her view); the body
maps it to wire messages (tool replies regroup) and our fork checkpoints her state exactly
there. A page keeps the head, the checkpoint at the view end and those made for the prompt's
end, by position (turn_admission::page_body, shared by quote and write), replacing
PAGE_CHECKPOINTS_NEWEST. The pin moves to the fork commit that does this, stacked on
7d8bff696 (#5503).


Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant