Repository navigation
Conversation
…mpt-cache-roots, opt-in) With --batch the chain a system-prompt root was made in does not stay whole: a slot keeps only its turn checkpoint, and a request that continues from a slot takes over that checkpoint alone. After a few turns of any chat the engine holds no root, so the next new chat of the same client reads its whole system prompt again. --prompt-cache-roots N keeps a copy of the last N roots (one per distinct system prompt, ~118 MB each). A new chat mounts through one from the main session, when its cells hold those tokens, or from any idle slot that holds them. The default (0) leaves every path as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Thanks for the pull request. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to review properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes:
The rules are in CONTRIBUTING.md. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
We serve an agent client whose every chat opens with the same ~79K-token system prompt and tool list, on
parallel: 4with--batch-mtpand--conversation-cache-mib 8192. Its chats overlap with other traffic all day, and every new chat read the whole opening again (20-35 s) although the engine had read the same tokens minutes before.The cause is in
--batch. The root checkpoint (the end of the system prompt, PR #65) lives in the main session's chain, but:drop_superseded).After a few turns of any chat nothing holds the root any more. Solo traffic does not show it: a request that runs alone stays on the main session and its chain stays whole.
What it does
--prompt-cache-roots N(default 0 = off, every path unchanged) keeps a copy of the last N roots the engine made, apart from any conversation (one per distinct system prompt, ~118 MB of RAM each; least recently made or used leaves first). A root's state depends on its tokens alone, so:Because the main chain keeps its root again, parked conversations keep it too, so a new chat also mounts through a parked one.
Tests
conv_cache_testcovers the store (kept, refreshed, the least recently used one leaves, other images or control-vector mode do not match, clear).Real engine: v0.1.43 on one RTX PRO 6000 (Blackwell), Qwen3.8-Flash-Next IQ3_S,
parallel: 4,--batch-mtp,--conversation-cache-mib 8192. A 42K-token system prompt; chat A three turns, a request with another system prompt, chat B two turns, chat C. Greedy, the same requests with the flag off and on:--prompt-cache-roots 2)--conversation-cache-mib 0), the root only in an idle slot: new chat B (--prompt-cache-roots 8)Answers were identical between the arms except one 600-token answer decoded beside another request; that one also differs between two runs with the flag off (batched greedy decode is not run-to-run identical).
N matters: in the last scenario with N = 2, a third system prompt pushed the 42K root out before chat B came, so we run 8.
In use: v0.1.43 plus this change has run with
--prompt-cache-roots 8on two RTX PRO 6000s for about 8 hours of mixed agent, chat and tool traffic (about 2,800 requests, no errors); new chats of that client now reuse their shared opening.Builds: the measurements above are from this change on v0.1.43. Rebased on current
main, it builds for CUDA (sm_120) and CTest passes (conv_cache_testincluded) exceptple_parity, which needs a Q2_0 model file I do not have. I could not build HIP or SYCL (no toolchain here). The change is host-only C++ insrc/program/generate.cppandconv_cache.hpp; the SYCLgenerate.cppincludes the header but does not use the new class (the header also compiles alone with g++-Wall -Wextra).Default path: with the flag at 0 the store is empty and every new branch is skipped:
seed_root, the slot lookup andkeepall testenabled()orprompt_cache_rootsfirst, so no checkpoint, copy or log line differs.Related: #1529 keeps the root in the disk tier's spilled files. This change is the RAM side under
--batchand does not touch the disk tier.Happy to change the shape (a default other than 0, or keeping the roots inside the conversation cache's budget).
🤖 Generated with Claude Code