server : preserve RAM-cached branches sharing a large prompt prefix - #36
server : preserve RAM-cached branches sharing a large prompt prefix#36arc-uri-el wants to merge 2 commits into
Conversation
Preserve and consult the existing RAM prompt cache when any cached suffix is replaced. The half-prefix-loss heuristic drops independent conversations that share a large system or tool prefix. Extend the existing slot tests with two interleaved shared-prefix branches and exact restored token checks. Assisted-by: GPT 6 Astra
Take a one-token replay control before displacement. A full-prefill comparison also changes kernel shape and is not an isolation test for RAM restoration. Assisted-by: GPT 6 Astra
b51a897 to
9cbefdc
Compare
|
The CANN notification is a pre-existing workflow validation failure, not a compiler or test failure from this PR. Run 34227573493 reports:
The Server workflow is a separate state: GitHub says it is awaiting approval from a maintainer. It has not run yet. The local CPU/Vulkan regression evidence in the PR remains applicable; it is not being represented as CANN coverage. I have kept unrelated workflow changes out of this focused cache fix. The disabled CANN workflow definition needs a maintainer-side correction, and fork workflow execution needs the normal approval. |
Overview
Independent conversations can share most of a system message or tool schema while differing in a short suffix. The LCP slot-selection path only saves and consults the RAM prompt cache when fewer than half of the current tokens would survive. Consequently, two such conversations overwrite one another's suffix state without retaining it, even with
--cache-ramenabled.Use actual suffix replacement instead of the half-prefix-loss threshold. The existing RAM cache remains the only storage owner and keeps its existing capacity limit. Pure prefix extension does not enter the new path. No new cache, option, checkpoint API or scheduling policy is added.
The existing slot test now alternates two 241-token prompts with a 193-token common prefix. Before the change, returning to either branch reuses 193 tokens and evaluates 48. Afterward it restores 240 and evaluates one. The test compares generated tokens against the same one-token replay shape before displacement, rather than comparing a one-token decode to a full-prefill numerical path.
Measurements
Baseline and candidate were built separately in this session with identical settings, with no compiler warnings. The test-only follow-up does not change the measured executable. Attribution-only commit updates preserve the exact tested source trees. The later master merge
99a40a3e6changes speculative replay at a different site; this witness uses target-only generation.Baseline / after:
The submitted tiny-model regression fails its cache assertion on the baseline and passes on the candidate on both CPU and Vulkan. Both restored branches produce the exact token IDs of their undisplaced, same-shape replay controls. The fixture is the existing
ggml-org/test-model-stories260Kpreset, filestories260K-f32.gguf, SHA-256270cba1bd5109f42d03350f60406024560464db173c0e387d91f0426d3bd256d.The official-Qwen witness uses one 131,072-context slot, F16 KV, batch 2048/512, no speculative decoding, and a common system prefix plus the same
record_valuetool schema. Conversation A requests value 73 and B requests 91. Both runtimes make the right native calls and return their own exact receipts after interleaving. The candidate's two prompt phases take 482/481 ms versus baseline 755/751 ms. Those two observations are not a throughput claim or a variance estimate; the directly asserted improvement is 82 fresh tokens reduced to 26.Correctness:
Run the focused test through the existing server test suite after its normal preset setup:
Local execution used that exact test function and the normal
ServerProcesshelper, selecting the already-downloaded preset file explicitly to avoid downloading unrelated presets. Baseline and candidate library mappings and actual CPU/Vulkan KV placement were checked. All test processes exited and were verified absent.An initial synthetic-fixture check compared full-prefill output with one-token replay and found different IDs. A baseline-only undisplaced replay reproduced the same difference. The test now holds replay shape constant before and after displacement; no tolerance or cache assertion was weakened. A synthetic architecture fixture without a tokenizer was also rejected as a text-server witness and was not counted as acceptance.
llama-bench, perplexity and the full backend-op matrix were not run. No math kernel is changed and no general decode speedup is claimed. Additional branch saves consume the existing cache budget and copy time; the regression targets recovery of overwritten suffixes, not zero-overhead caching.Requirements