[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

Open
opened 2026-11-04 01:55:47 +07:00 by bsakaguchi · 2 comments
Owner

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

6× Tesla V100-SXM2-16GB (sm_70; cards 0-3 NVLink island, 4-5 second NVLink pair, one PCIe crossing), driver 580.x, CUDA 12.9
VM on Proxmox (CPU type=host, NUMA on), 88 GB RAM
Linux x86_64, engine built from source, -DCMAKE_CUDA_ARCHITECTURES=70 (CUDA 12)

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:

give back: 2609-4985 ms
take: 2498-4985 ms
total 5-10 s of overhead on a turn that arrives every 5-10 s - the copies are 50-100% of the agents' cycle. The useful work per turn is tiny (1 generated in 14-23 ms); everything else is the give-back/take pair.

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

--conversation-cache-slots (4 → 8) and --conversation-cache-mib (20 GiB → 24 GiB): the give-back/take pair happens regardless - the release is the engine's idle-slot decision (#2526), not the cache accepting the copy.
--conversation-cache-park-gain 1024: saves snapshot writes, not the slot release - a turn that grew by 387 tokens was still parked and still re-copied.
STRATA_DEFAULTS=026 is set in this config (the 0.2.7 pipelined-batch and layer-major prefill defaults regress on this 6-card sm_70 box; measured separately: 4×25955-token prompts, 240.7 s with 0.2.7 defaults against 125.8 s with 026), but the give-back/take pair happens with both.

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

Measured on sm_70 (V100); the copy times will differ on other cards, but the per-turn release itself is architecture-independent.
The two agents are external to Strata; I cannot make them batch their turns, and their 5-10 s cadence is fixed by their task loop.
evictions growth (159 → 161 in minutes) is consistent with the giant snapshots (3.5 GiB each) churning the 24 GiB parking budget, but I did not separate its cost from the slot copies.
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 6× Tesla V100-SXM2-16GB (sm_70; cards 0-3 NVLink island, 4-5 second NVLink pair, one PCIe crossing), driver 580.x, CUDA 12.9 VM on Proxmox (CPU type=host, NUMA on), 88 GB RAM Linux x86_64, engine built from source, -DCMAKE_CUDA_ARCHITECTURES=70 (CUDA 12) 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: give back: 2609-4985 ms take: 2498-4985 ms total 5-10 s of overhead on a turn that arrives every 5-10 s - the copies are 50-100% of the agents' cycle. The useful work per turn is tiny (1 generated in 14-23 ms); everything else is the give-back/take pair. 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 --conversation-cache-slots (4 → 8) and --conversation-cache-mib (20 GiB → 24 GiB): the give-back/take pair happens regardless - the release is the engine's idle-slot decision (#2526), not the cache accepting the copy. --conversation-cache-park-gain 1024: saves snapshot writes, not the slot release - a turn that grew by 387 tokens was still parked and still re-copied. STRATA_DEFAULTS=026 is set in this config (the 0.2.7 pipelined-batch and layer-major prefill defaults regress on this 6-card sm_70 box; measured separately: 4×25955-token prompts, 240.7 s with 0.2.7 defaults against 125.8 s with 026), but the give-back/take pair happens with both. 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 Measured on sm_70 (V100); the copy times will differ on other cards, but the per-turn release itself is architecture-independent. The two agents are external to Strata; I cannot make them batch their turns, and their 5-10 s cadence is fixed by their task loop. evictions growth (159 → 161 in minutes) is consistent with the giant snapshots (3.5 GiB each) churning the 24 GiB parking budget, but I did not separate its cost from the slot copies.
Author
Owner

@Barmallini commented on GitHub (Oct 31, 2026):

Follow-up: --conversation-cache-park-gain does not skip the re-park, and 0.2.9 adds a partial reuse that works about 1 time in 5

Follow-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-gain does not appear to skip the re-park (0.2.2 through 0.2.8)

With --conversation-cache-park-gain 1024 set, 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:

  • context grew +4 tokens since the previous snapshot -> full park, snapshot 2.8–3.2 GiB, 4.6 s
  • context grew +323 tokens -> full park, 5.2 s
  • context grew +387 tokens -> full park, 7.5 s
    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_bytes field. When it engages, the park of a giant conversation drops roughly 3x:

parked 145863 tokens in 1871.6 ms; ... snapshot_bytes=3166343192 reused_kv_bytes=1988777088   <- reuse hit
parked 198116 tokens in 4468.6 ms; ... snapshot_bytes=3397791864 reused_kv_bytes=0
parked 194781 tokens in 4569.0 ms; ... snapshot_bytes=3222261336 reused_kv_bytes=0
parked 190891 tokens in 7066.6 ms; ... snapshot_bytes=3651830616 reused_kv_bytes=0
parked 182833 tokens in 10072.3 ms; ... evictions=196 snapshot_bytes=3656558640 reused_kv_bytes=0

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

  • either park-gain actually 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),
  • or the 0.2.9 checkpoint reuse catching far more of these parks; at 1-in-5 it removes maybe a fifth of the per-turn parking tax for this pattern.
    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.

<!-- gh-comment-id:6542450402 --> @Barmallini commented on GitHub (Oct 31, 2026): ## Follow-up: `--conversation-cache-park-gain` does not skip the re-park, and 0.2.9 adds a partial reuse that works about 1 time in 5 Follow-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-gain` does not appear to skip the re-park (0.2.2 through 0.2.8) With `--conversation-cache-park-gain 1024` set, 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: - context grew **+4 tokens** since the previous snapshot -> full park, snapshot 2.8–3.2 GiB, 4.6 s - context grew **+323 tokens** -> full park, 5.2 s - context grew **+387 tokens** -> full park, 7.5 s 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_bytes` field. When it engages, the park of a giant conversation drops roughly 3x: ``` parked 145863 tokens in 1871.6 ms; ... snapshot_bytes=3166343192 reused_kv_bytes=1988777088 <- reuse hit parked 198116 tokens in 4468.6 ms; ... snapshot_bytes=3397791864 reused_kv_bytes=0 parked 194781 tokens in 4569.0 ms; ... snapshot_bytes=3222261336 reused_kv_bytes=0 parked 190891 tokens in 7066.6 ms; ... snapshot_bytes=3651830616 reused_kv_bytes=0 parked 182833 tokens in 10072.3 ms; ... evictions=196 snapshot_bytes=3656558640 reused_kv_bytes=0 ``` 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 - either `park-gain` actually 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), - or the 0.2.9 checkpoint reuse catching far more of these parks; at 1-in-5 it removes maybe a fifth of the per-turn parking tax for this pattern. 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. ---
Author
Owner

@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.

<!-- gh-comment-id:6660043371 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1984
No description provided.