mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2325] [CLOSED] --batch: keep system-prompt roots apart from the conversations (--prompt-cache-roots, opt-in) #3982
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3982
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2325
Author: @brocktice
Created: 10/13/2026
Status: ❌ Closed
Base:
main← Head:batch-slot-root📝 Commits (1)
0771999--batch: keep system-prompt roots apart from the conversations (--prompt-cache-roots, opt-in)📊 Changes
5 files changed (+183 additions, -2 deletions)
View changed files
📝
docs/BATCHING.md(+8 -0)📝
docs/DETAILS.md(+3 -1)📝
include/strata/program/conv_cache.hpp(+56 -0)📝
src/program/conv_cache_test.cpp(+32 -0)📝
src/program/generate.cpp(+84 -1)📄 Description
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.