mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2099] serve: sub-agent fan-out gets 0% sibling prefix reuse without --prompt-cache-tail - 93% and 11.7x prefill with it (GTX 1080 Ti, IQ3_S, 0.1.43) #835
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#835
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?
Originally created by @MrKop-git on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2099
TL;DR
Sub-agent requests that share a long prefix get 0% reuse on defaults when the prompt is below the first periodic checkpoint (16,384): each sibling re-reads everything (~143 s per 14.8K-token prompt on this box).
--prompt-cache-tailalone takes sibling reuse to 93% / 11.7x faster prefill;STRATA_CACHE_MESSAGE_BOUNDARY=1takes the agent retry pattern to 3.1x;--prompt-cache-every 4096recovers 33-65% for mid-prompt forks. All measurements, including two negative results ("parallel": 2does not fit an 11 GB card at 262K context;--prompt-cache 10does not widen the eviction window), are in the body and the follow-up comments below. Ask: consider--prompt-cache-tailon by default for--serve, and a pre-start check that--batch Nat a given--max-contextleaves the verify tier enough expert slots.Index of the follow-up measurements (comments)
STRATA_CACHE_MESSAGE_BOUNDARY=1- 99.6% reuse, 3.1x"parallel": 2negative result + pre-start check suggestion - slot sessions cost 0.95 GiB each at 262K context--prompt-cache-every 4096- chunk geometry: checkpoints land on chunk boundaries--prompt-cache 10negative result - the K=5 cliff is not governed by the checkpoint pool; chunk geometry is a per-boot lotteryExpected / Actual
Expected: a request whose prompt shares a prefix with a recently served prompt reuses the shared part (that is what the bounded checkpoint cache is for).
Actual: with
--prompt-cache-everyat its default 16,384 and a prompt below that length, no checkpoint exists at all, so a sibling that diverges at the tail re-reads the entire prompt: measured 0% reuse, three times in a row (14.8K-token prompts, ~143 s each on this box).Goal
One coding-tool conversation that spawns sub-agents: sibling requests that share a long prefix (system prompt + repo context, ~14.8K tokens) and diverge only in a short task tail (~30 tokens). Measured on a real serve box; the numbers below show sibling reuse is 0% on defaults and ask whether
--prompt-cache-tail(or an equivalent) should be considered for agent-style workloads by default.Environment
--spec 4 --spec-min-p 0.70 --mtp,--kv int8 --kv-resident 32768,--pcie-frac 0.00vram_free_mib1887Method
Three sibling POSTs to
/v1/chat/completions, back to back, same context (14,800 tokens: engine + server sources and docs), three different task tails, temperature 0,chat_template_kwargs {"enable_thinking": false},max_tokens32, unique salt in the system message per run.reused/prompt_read/prompt_msfrom/metrics. Run twice: once with defaults, once with--prompt-cache-tail(only change; engine restarted between runs).Baseline (defaults:
--prompt-cache6,--prompt-cache-every16384, no tail)0% sibling reuse: the whole prompt is under the first periodic checkpoint (16,384), so no state exists to reuse, and each sibling re-reads everything. A 3-way fan-out costs ~7.2 min of pure prefill on this box. For contrast, the tool's own main conversation (a growing conversation, 159-163K prompts) reuses 99.9%+ and reads 16-304 tokens per request.
With
--prompt-cache-tail(the only change)93.4% reuse (13,824 = the chunk boundary), sibling prefill 11.7x faster, sibling wall 3.9x. The whole 3-way fan-out drops from ~431 s to ~220 s.
Ask
Primary: consider
--prompt-cache-tailon by default for--serve, or at least a pointer to it in BATCHING.md's agent/slot section - its cost is one extra checkpoint write per fresh long prompt, and for prompts below--prompt-cache-everyit is the difference between 0% and 93% sibling reuse.Secondary (happy to split into its own issue if easier to track): a pre-start check that
--batch Nat a given--max-contextleaves the verify tier at least its 367 slots, before the ~4-minute model load - from the negative result in the comments.Reproduction
serveon any single-GPU config with the defaults (--prompt-cache6,--prompt-cache-every16384, no tail flag)/v1/chat/completionswith a ~14.8K-token prompt (system + concatenated sources + a one-line task), temperature 0/metrics: the second request showsreused: 0,prompt_read= the full prompt,prompt_ms~= the first request's--prompt-cache-tailadded; repeat 2-4: the second request now showsreusedat the last chunk boundary (13,824 of 14,795 here) and ~12 s prompt_msRelated
@MrKop-git commented on GitHub (Oct 12, 2026):
Follow-up measurement on the same box: the agent retry pattern (same history, final user message replaced) with
STRATA_CACHE_MESSAGE_BOUNDARY=1on top of--prompt-cache-tail, single change between runs:Baseline (defaults +
--prompt-cache-tailonly): request B (history + replaced final message) reuses up to the tail chunk boundary and re-reads the rest.With
STRATA_CACHE_MESSAGE_BOUNDARY=1(only change): the checkpoint lands exactly at the turn boundary.52 and 101 are exactly the replaced final message's length. The retry/regenerate turn drops to ~4 s wall (3.1x), and the fresh-request (A) cost stays within +-2% noise, so the snapshot cost called out in MESSAGE_BOUNDARY_CACHE.md did not show up here.
So for the coding-agent workload both opt-ins compose well:
--prompt-cache-tailfixes sibling fan-out (the tables above),STRATA_CACHE_MESSAGE_BOUNDARY=1fixes the retry/edit-last-message loop. Both are prefix-exact and free of VRAM cost on this 11 GB card.@MrKop-git commented on GitHub (Oct 12, 2026):
A third data point, this one negative:
"parallel": 2(the engine's--batch 2) does not fit this card at 262K context. With the config's--max-context 262144 --kv int8and a desktop sharing the GPU:Each slot session costs 0.95 GiB at 262,144 tokens (vs the 0.56 GiB per session quoted in BATCHING.md, which is the 32K-context shape), so two slots eat the entire expert-cache budget and the verify tier refuses to start. Reverted to one-at-a-time; the engine is back with 926 expert slots.
Two small suggestions from this run:
--batch Nat this--max-contextleaves fewer than 367 slots" before the ~4-minute model load would save a restart loop on small cards (it failed after loading 47 GiB).--max-context(~0.95 GiB at 262K, int8 KV) would set expectations: on an 11 GB card with a desktop,parallelabove 1 needs 32K-ish contexts or--kv q4_0.For the record, the serial-FIFO baseline for the same burst (two siblings fired simultaneously, prefix already warm from
--prompt-cache-tail): first TTFT 12.3 s / wall 13.1 s, second TTFT 25.3 s / wall 30.0 s (it waits for the first to finish), decode 21.5 tok/s on the solo path with MTP drafts active. With rounds 1+2 in place, the second sub-agent's real cost is the ~12 s tail re-read plus queueing behind the first stream's decode, which is tolerable for a single-user coding loop.@MrKop-git commented on GitHub (Oct 12, 2026):
Fourth data point: sub-agents whose context subsets differ (divergence in the middle of the prompt, not the tail) get 0% reuse on defaults, and
--prompt-cache-every 4096recovers part of it. Same box, single change between runs (bench: sibling-a then sibling-b, sibling-b shares the leading context and diverges at a chosen point, temperature 0):Baseline (
--prompt-cache-everydefault 16384):With
--prompt-cache-every 4096(only change):The reused values pin down the chunk geometry on this box:
--prefill autochunks are 4,608 tokens and checkpoints land on chunk boundaries at or past multiples of the interval (4,608 / 9,216 / 13,824 - the 13,824 tail boundary from the first tables is the same boundary). Reuse always extends to the last boundary before the divergence point, so the gain grows the later the fork; a fork before the first boundary still gets nothing.For agent fan-outs that tailor context per sub-agent (different file subsets after a shared system/project prefix), a smaller
--prompt-cache-everyis what turns 0% into 33-65% reuse. The trade we have not quantified yet: the 6-slot checkpoint cache now turns over faster when the main conversation's long prompts also write checkpoints, so the shared prefix survives less intervening traffic.@MrKop-git commented on GitHub (Oct 12, 2026):
Last measurement: the eviction window of the 6-slot checkpoint cache, since
--prompt-cache-every 4096makes every long request write checkpoints and turns the pool over faster. Same box; per arm: warm the shared 14.5K-token prefix, then K unrelated ~5K-token conversations (each crosses the 4,608 boundary, so each writes at least one checkpoint), then a probe sibling that shares the warm's prefix and differs only in the tail:The shared prefix's checkpoint survives exactly 4 intervening long requests; the 5th evicts it (the warm's own prompt holds several slots - 4,608 / 9,216 / 13,824 / tail - and each intervener adds one or two, so 6-slot LRU arithmetic checks out). A probe that does fall back to a full read re-establishes the checkpoints, so the window resets on any request sharing the prefix.
Side observation from the logs during this run: the conversation cache (8 GiB, 4 slots) was parking and evicting conversations the whole time (
evictions=13..18) with no effect on the probe's checkpoint reuse - the two caches are cleanly independent.Practical guidance for agent workloads on small cards: fire the fan-out siblings back-to-back (within ~4 intervening long requests of the first), or accept one full re-read to reset the window. A larger
--prompt-cache(each checkpoint ~118 MB) widens the window at a memory cost; we have not measured that arm yet.@MrKop-git commented on GitHub (Oct 12, 2026):
One more arm: we tried widening the pool (
--prompt-cache 10) to widen the eviction window, and it does not - worth flagging because the mechanism is not what the flag suggests.--prompt-cache 6(default)--prompt-cache 10The cliff stays at exactly K=5 with 10 slots. With
--prompt-cache-every 4096, our ~4.3-5.0K-token interveners only write a checkpoint when they cross a chunk boundary, and on the 10-slot boot the auto chunk was 7,040 tokens (so the interveners wrote no periodic checkpoints at all) - yet the warm prefix's checkpoint still died at K=5. So the eviction that kills the shared prefix at the fifth intervening request is not driven by the checkpoint pool's LRU alone; something else (the conversation cache's 4 park slots interplay is our prime suspect) is the binding constraint. We reverted to 6 slots: the wider pool only cost 60 expert-cache slots (~9% slower cold prefill) and bought nothing on the window.Two smaller observations from this arm:
--prefill autopicks the chunk from free VRAM at start, so where a fork-divergent sibling's reuse lands varies between restarts. Worth a line in PROMPT_CACHE_TAIL.md if reproducible elsewhere.expert_slotsfrom/metrics.Final config after the whole series (11 GB card, IQ3_S, 0.1.43):
--prompt-cache-tail --prompt-cache-every 4096+STRATA_CACHE_MESSAGE_BOUNDARY=1,--prompt-cacheleft at the default 6, noparallel(does not fit at 262K context). Sibling fan-out: first agent pays the cold read, siblings within 4 intervening requests reuse 93-97% (12 s instead of 143-172 s); retry/edit-last-message turns cost 3.7 s instead of 11.4 s.@MrKop-git commented on GitHub (Oct 12, 2026):
Postscript with better numbers: the box this series was measured on turned out to have its PCIe link pinned at Gen1 by a leftover driver option (
NVreg_RegistryDwords="...;RmDisableGen2LinkRetraining=1"), which capped the streaming tier at the Gen1 ceiling (~3.2 GB/s measured). Found it because the Monitor page kept saying "Gen3 · idle Gen1" while the link never left Gen1 even under 147 s of saturated load - that display bug is now #2137. With the option removed and the link actually at Gen3 x16, the same benches on the same config:--prompt-cache-tailon)So the full stack on an 11 GB Pascal card now serves a coding-agent fan-out at: first agent ~57 s (cold), each sibling ~4 s, retry ~4 s - against 143 s for every request when this issue was opened. The prefix-reuse flags and the link fix compound multiplicatively: reuse removes the tokens to read, Gen3 moves the ones left 3-4x faster.
@bulhenvaster commented on GitHub (Oct 13, 2026):
One more agent pattern for this thread, measured on a real install: a client's summarization (compaction) call gets 0% reuse on defaults, and
"effort_position": "end"(#458) takes it to 98.8%.Setup. Engine 0.1.43, IQ3_XXS, 262K context,
--kv int8 --kv-resident 32768, RTX 5060 Ti 16 GB + RTX 3060 12 GB (--peer-device 1), Xeon E5-2683 v4, Linux. Client: DeepSeek Harness (DSH) over/v1/chat/completions, session efforthigh.What the client sends. Its compaction request replays the conversation prefix byte for byte (same system message, same 55 tools in the same order, the same messages) and appends one instruction as the last user message - it is written to hit a prefix cache. The only field that differs from an ordinary turn is
reasoning_effort:noneinstead ofhigh(compared from two bodies captured with"api_monitor": true). With the default"effort_position": "start"the effort sentence is the first thing in the system turn, so the two prompts differ from the first tokens.Same session, the request before and the compaction request:
high)effort_positionstart (default)high)effort_positionendOne request per row, the config key the only change between the two pairs (engine restarted in between).
What it cost before. In this install's engine log (7,733 requests over several days of agent use, engine 0.1.41 and 0.1.43) there are 135 such compaction calls: median prompt 88,647 tokens, 0 reused, 9,721 s of prompt reading in all. A full read also replaced the conversation's checkpoints, so the turn after each one read the compacted conversation from token 0 as well (175 reads with nothing reused, 10,219 s; that count includes new sessions). Together about 11% of the 175,346 s the engine spent on requests.
For the docs. DETAILS.md describes
effort_positionfor "an agent's think-harder switch"; a client's own helper calls (compaction, titles) that run at another effort than the session are the same case and probably the more common one. A line there, or next to the agent notes in BATCHING.md, would have saved the search. Whetherendshould be the default I cannot say from one install: how well the model followslow/mediumfrom the trailing turn is not measured here (this client only ever sendshighandnone).Not tested:
low/medium, the Anthropic endpoint, a layer split.@MrKop-git commented on GitHub (Oct 14, 2026):
Third tier of the link table: Gen3 x8. The postscript's two arms were labelled "Gen1" and "Gen3", which mixes speed generation with lane width; this machine's link trains at a third shape, so here it is with both stated.
The three link shapes, labelled
Width is not a footnote: Gen3 x8 is half of Gen3 x16, while Gen1 is a fifth of Gen3 x16 regardless of width. The three arms are not evenly spaced on one axis.
On the Gen1 arm's width: it was never logged. That arm came from a leftover
RmDisableGen2LinkRetraining=1, which holds the generation down, so the width was most likely still x16 — but that is an inference, not a measurement, and the watch log from that period is gone (rotated by reboots). If anyone re-runs it, please record width alongside generation.Measurements
The x8 sibling and cold-prefill rows are one probe pair with the same shared prefix (13,400-word body, request B replacing only the final instruction), so they are internally consistent:
prompt 14107 = 0 reused + 14107 read in 73199 msandprompt 14105 = 13824 reused + 281 read in 3595 ms.The interesting part is that the two rows move differently. Cold prefill is strongly width-bound: 171 s → 111 s → 52-57 s across the three arms. The x16/x8 gap is ~2x, which is exactly the width ratio; Gen1 is ~3.3x slower than x16 rather than the ~5x its link would predict, so something besides link bandwidth costs it the rest. The sibling tail-fork is barely width-bound at all: 4.49 s on x8 is within noise of 4.1-4.2 s on x16, because once the checkpoint is hit there are only 281 tokens left to read and that fits through any link. So for a fan-out workload the width pays for the first agent's cold read and for almost nothing after.
Two API fields that will mislead you if you measure reuse from the response
Both are wrong for the prompt-checkpoint path; the engine log line is the one that tells the truth.
timings.prompt_nis the tokens computed in this call, not the prompt length. For B above it read281, while the prompt was 14,105 tokens.usage.cached_tokenswas0for B despite 13,824 reused tokens. It accounts for the conversation cache, not the checkpoint cache.If you build a table from
prompt_n - cached_tokensyou get "0% reuse, 281-token prompt" for what is really a 97.9% hit.Numbers that only the x8 arm has, from the standard suite
From
tools/strata_bench.py(medians of 3, same engine and config): short-chat decode 24.4 tok/s (TTFT 1.22 s), fresh 4K prompt 234.0 tok/s (TTFT 17.24 s), fresh 16K prompt 234.1 tok/s (TTFT 68.65 s), agent turns reusing 68.8% of the conversation and re-reading 3 tokens per session, and a 4-client burst on the serial-FIFO path at 18.8 tok/s total (TTFT p50 12.0 s, p95 22.3 s).Note the 16K figure is not interchangeable with the cold-prefill row above: it is a different prompt shape (the suite's calibrated word list vs a 20-word vocabulary repeated), and the two disagree by ~1.8x on this arm (234 tok/s vs 127 tok/s wall). Compare like with like.
What makes the x8 arm not a clean A/B
Three things besides the link changed between the Gen1/x16 arms and this one, so read any x8-vs-x16 ratio as approximate:
--vram-reserve-mib 1024gives 1,331 slots now vs 926 in those arms.A single-variable x8-vs-x16 number would need the same SM cap and the same expert-cache size on both arms. I have not run that pair; the table above is what was actually measured on each arm as configured.
Config under test
Engine 0.1.43.1 on a GTX 1080 Ti 11 GB, driver 580.178.04,
--kv int8 --kv-resident 32768 --max-context 262144 --prefill auto --spec 4 --spec-min-p 0.5 --prompt-cache-tail --prompt-cache-every 4096,STRATA_CACHE_MESSAGE_BOUNDARY=1, 1 parallel slot (no--batch— confirmed again that it does not fit at 262K). Full standard-suite report:bench/results/2026-10-14-community-gtx-1080-ti-qwen3-8-flash-next-iq3-s-2/.@Niko1221 commented on GitHub (Oct 19, 2026):
Thanks for taking the time to report this.
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 read 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:
/reopen. A check runs and either reopens the issue or lists what is still missing.The rules are in CONTRIBUTING.md.