mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4450] [Engine] --batch: a slot is given back and re-copied on every agent turn - two alternating 200K-token conversations spend ~50-100% of their cycle on KV copies #1984
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#1984
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 @Barmallini on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4450
[Engine] --batch: a slot is given back and re-copied on every agent turn - two alternating 200K-token conversations spend ~50-100% of their cycle on KV copies
Reproduction status
Measured locally
Hardware
What happened
Two autonomous agents run with contexts of ~194K and ~219K tokens (--batch 4, 4 slots). They take turns every 5-10 seconds. Each turn ends with the slot giving the conversation's KV back to the conversation cache, and the next turn copies it all back in:
Code block
strata batch: slot 1 gave back 192262 tokens of this conversation (all it holds) in 3448.9 ms
strata batch: slot 1 takes 192264 tokens (copied in 2792.8 ms)
strata serve: prompt 192264 tokens = 192263 reused + 1 read in 14 ms (73.8 tok/s), 1 generated in 18 ms (56.3 tok/s)
Per-turn cost of the shuffle:
The KV of a 200K-token conversation is ~2.4 GiB at int8 (--kv int8), which matches the copy times. Two conversations ping-pong between the parking cache and their slots; evictions on the parking cache climbed 159 → 161 during just a few minutes of this.
The parallel decode itself is fine: batch (pipelined, 4 groups of 1): 2009 group-steps in 26648 ms - rows are interleaved across slots as expected. The cost is entirely the per-turn release of the slot.
What I expected
Some hysteresis: a slot that just finished a turn keeps its conversation for a short grace period (say, configurable, a few seconds to a minute) before the conversation is parked and the slot given away. With two conversations alternating every few seconds, both would stay resident in their slots and the give-back/take pair would disappear; the slot would only be released when the grace period lapses or when another request actually needs the slot.
What I ruled out
Suggested fix
A pin/grace period on the most recently used slot(s), e.g. --batch-slot-pin-seconds N (0 = today's behaviour): after a reply, the conversation stays in its slot for N seconds; if its next turn arrives within the window, no copy happens at all; if another request needs the slot, it is given back immediately as today. For the two-agents-alternating case above, any N ≥ 10 s removes the copies completely.
Related: #4420 (parking an idle slot drops the shared system-prompt checkpoint), #2526 (the original idle-slot parking).
Limits of this report
@Barmallini commented on GitHub (Oct 31, 2026):
Follow-up:
--conversation-cache-park-gaindoes not skip the re-park, and 0.2.9 adds a partial reuse that works about 1 time in 5Follow-up on this thread, measured on our box: 6x Tesla V100-SXM2-16GB (sm_70), one PCIe crossing between the two NVLink pairs, Strata 0.2.9 / engine 0.1.55 built from source, Qwen3.8 GSQ-RCO IQ3_S,
--conversation-cache-slots 4,--conversation-cache-min-tokens 30720,--conversation-cache-park-gain 1024,--conversation-cache-min-free-mib 1536,STRATA_DEFAULTS=026,--kv-resident 262144,--parallel 4/--batch 4. Real agentic traffic: two very large conversations (~130K and ~190K tokens) alternating turns every few seconds.1.
park-gaindoes not appear to skip the re-park (0.2.2 through 0.2.8)With
--conversation-cache-park-gain 1024set, I expected a conversation whose context grew by less than ~1024 tokens since its snapshot to skip a full re-park. That did not happen. From one session's log (0.2.8), three consecutive turns of the same agent:Each of those turns then paid the give-back + take/restore cycle again (~6–12 s of overhead per turn for a ~200K-token int8 context, which matches the slot-pin cost described in this issue). So in our runs the flag changed nothing observable for the alternating-giant pattern.
2. 0.2.9: partial checkpoint reuse helps, but engages rarely
On 0.1.55, park lines gained a
reused_kv_bytesfield. When it engages, the park of a giant conversation drops roughly 3x:That is 1 hit out of 5 parks in this window. When
reused_kv_bytes=0, the full snapshot copy stays at 4.4–10 s, exactly as before. We did not try to characterize why the reuse misses (checkpoint age? interleaved slot overwrite? evictions?); this is just the observed rate under two alternating giants.What we would love to see
park-gainactually suppressing the re-park when the context delta is under the threshold (the giant case is where the flag matters — small conversations park in milliseconds anyway),Happy to run a specific experiment (single-switch isolation, longer capture, specific env off) if that helps. Logs are ours, measured today; I can post fuller excerpts on request.
@shoucandanghehe commented on GitHub (Nov 5, 2026):
I have a local, single-GPU experiment addressing the session-shuttle side of this problem. A request stays in one physical session from prefill through completion; when concurrency changes, the compute batch changes rather than moving the conversation back to a main session. A lone active request can use the single-sequence kernels without a session handoff.
This is broader than a retention timer, so I would like to agree scope before proposing the refactor. Would an opt-in, single-GPU-only PR be acceptable, with today's path and multi-GPU behavior unchanged when it is off? Slot-local sampling, recurrent/indexer state and draft rollback must remain isolated. Image-cache ownership would be included only where required by that session lifetime, not as a separate one-line cache change.
I checked main
5d37280d(0.2.11): the inspected admission/handback paths still copy between main and slot sessions. This is unconfirmed static analysis, not a reproduction of this issue's timings. I have not rerun the local experiment on this upstream revision and make no speed or output-parity claim for it. I am also checking #2526, #2527 and #4966 so that this does not compete with an existing solution. If the smaller retention approach is preferred, I will keep the broader implementation local.