Repository navigation
Conversation
…when the CUDA server uses its own kernels --kernels native is the CUDA CLI's flag; the server runs its own kernels whenever it has no captured Triton set.
|
Thank you, @BadAd84. This is a real gap and you found its exact shape: the superseded rule is right for a conversation that only grows and wrong for a turn that several continuations share. Your fix keeps the first case as it was. It landed in 1.0.9 as One thing differs from how we usually land a PR. The commit here carries a personal email address, and we keep personal addresses out of the public history, so the landed commit is authored with your GitHub noreply address, We ran it served, with Nemotron 3.5 Lightning MLX 4-bit and a small cache budget, before and after the change on the same machines: a ~4,000-token history, two forks from it, each with a ~450-token assistant answer and a follow-up so each keeps its own longer state, then unrelated prompts until the cache has to free a state, then a third fork.
Two notes from our review, for later and not blocking. A branch point keeps its mark after the longer state that set it is gone, so it leaves only as the least recently used, the cost you describe. And the GB10 numbers in the description came from an earlier tree that also had a rule for short whole-prompt states, which this commit doesn't add. If that second rule matters on main, a PR with a measurement on main would show it. |
…oint, freed only as least recently used A resumed state kept its place in the cache's use order, and once the continuation kept its own longer state, _superseded counted the shared history as superseded and freed it first under memory pressure. Every next continuation (a re-sent, edited or forked turn, an agent that restarts each step from one history) then prefilled the whole history again. A resume now moves the state to the newest end and marks it a branch point when a later turn already extends it; _superseded skips branch points. A conversation that only grows still frees its old turns first. Ports upstream ashhart#735. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nder the entry cap Upstream ashhart#735 fixed a cache that freed such a history first. Flash Next's fork already copies the history to a spare slot, where it is the slot's shortest entry, which _superseded never gives up; this test holds that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…when the CUDA server uses its own kernels --kernels native is the CUDA CLI's flag; the server runs its own kernels whenever it has no captured Triton set.
What this changes
When the prompt cache needs room it frees first a state that a longer state, kept by a later prompt, extends (
victimButinzig/src/core/prompt_cache.zig;pickinzig/src/core/prompt_radix.zig). That's right for a conversation that has grown past its old turns.It's wrong for the state several continuations branch from: a re-sent turn, a regenerated or edited reply, or an agent that starts each step from the same history. Once one of them has kept its own longer state, the state the next one needs counts as superseded, and the next prompt that keeps anything (a long prompt keeps its history) evicts it first. Every later continuation then prefills the whole history again and keeps nothing at that history either, so the conversation never recovers.
A kept state that is resumed again after a later prompt kept a longer state extending it is now a branch point: the superseded rule skips it, and it only goes as the least recently used, like a shared system cut does. A state resumed once and then extended is still superseded first, as before, so a conversation that grows turn by turn frees its old turns first.
Both stores get the rule (the paged store has no backend yet; the rule is the same there).
Found this on a Qwen3.8 Flash Next serve built on an earlier TensorFold whose store has this same rule. One GB10, a ~100k-token conversation, three other streams decoding, and other 1k-8k token prompts in between its turns:
On main the same sequence fails in a host test, below.
The cost: a branch point that's never resumed again sticks around until it's the least recently used state, where it used to go first.
Receipt
0efbd447(main), Zig 0.17.0, Linux aarch64 on a GB10 host, host tests only (CPU). No checkpoint.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: not run. The change is eviction order only: no row arithmetic, kernel or reply path changes. In every new test a resumed prompt pass equals a fresh one (the test family's running sum).tools/bench_openai.py: not run (no decode path changed).tools/prefill_cold.py: not run. A resume now scans the kept states once for a longer one that extends it, the same scan eviction already makes for each state.zig build test: main 616/621 (5 skipped); this change 623/628 (5 skipped).zig/tests/server/zig_test.sh: main 155/155 and 96/96; this change 155/155 and 100/100.expected 100117, found 0: the conversation's next turn prefills from the start after a 6k prompt made room) and so does the paged store's (expected 20, found 0); the other two new tests pass on main as they should (a state resumed once and then extended is still superseded first; a turn's rewind state is not superseded by the history state its own prompt kept).victimBut, marking every resumed state, dropping the "kept by a longer prompt" condition from the extension check (killed by the rewind test, which I added for it), and the same three for the paged store.python3 tools/zig/lean_check.pyreports no problem this change adds;zig fmt --checkpasses on the changed files.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Resumed equals fresh in the host tests; no engine run.)