mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1604] --batch-groups disables the per-slot conversation cache even when the group size is 1 (no pad row is ever written) → alternating long conversations re-prefill from token 0 every turn #642
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#642
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 @113636xfh on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1604
Engine: 0.1.40.1 (
project(strata VERSION 0.1.40)), Linux, CUDA 12.9.Code references are to
src/program/generate.cppandinclude/strata/core/verify.hppof this build.Related: #1413 ("
--batch-groups G>1+--batch-mtpis silently inert") — same pipelined path, different symptom. PR #1601 (a memory guard so parking checks the RAM the container really has) — §5.5 is the same gate failing on a bare-metal host, and our measured park sizes are far above the 240–750 MB quoted there. #1603 (two long-context sessions underparallel: 2) — likely the same root cause seen from the client side.1. Our machine
2. Our launch configuration
strata-iq3_s.json→serve/server.py --engine strata --port 8100,"gpu": [0,1,2],"parallel": 4(→--batch 4),"layer_split": [16,32]:Startup evidence that the memory side is healthy (VRAM is not the problem):
3. Exact conditions that trigger it
--batch Nand--batch-groups Gwith G == N, soGS = N / G == 1(one slot per pipeline group).Under those conditions the conversation that is not currently live in the main session loses its state every single turn and re-reads its whole prompt from token 0.
4. Symptom, verbatim from the engine log
and then every following turn of that same conversation:
The short conversation (45 K tokens) keeps working normally throughout; only the long one is destroyed.
Aggregate over one run (log lines 1661–9527, 1803 prompts):
0 reused0 reusedpromptsskip parking (physical RAM admission …)skip parking (snapshot … exceeds available budget)evictionsslot N gave back … tokens of this conversation--batch-groups 4run--batch-groupsSo the slot conversation cache is provably never used once
--batch-groupsis on.5. Our analysis
5.1 The pipelined path clears
cachedunconditionallyversus the non-pipelined path at the same point:
and the resume source skips any slot with
cached == false:5.2 The stated reason (pad rows) is unreachable when
GS == 1A group is only ever started if it has an active slot:
With
GS == 1,group_active(gi)isbs[gi].active, so insidethe
!sl.activebranch cannot execute, andbatch_launch(pick*GS, GS, …)launches exactly the one active slot's row. No idle slot's state is ever written. Yet:7672still clearscachedfor every finished slot.5.3 The real constraint is the hand-off row addressing, not KV independence
include/strata/core/verify.hppcontrasts the two window APIs:So the coupling is that
batch_launchaddresses a fixed contiguous group (to keep hand-off rows disjoint between groups), which forces padding of idle slots inside an active group. That is an addressing limitation, not a conflict with per-conversation KV.5.4 The per-slot KV is independent and already allocated — the cache is disabled for free
qsa_state_init(src/core/layer.cpp:802) allocates the authoritative K/V per QSA state whenever KV streaming is on:and
--batchcarves a full session per slot per stage (generate.cpp:3512). On our box that is 1.03 GiB × 3 stages × 4 slots = 12.4 GiB of pinned host RAM, resident from startup, whether or not the slot cache is ever used.copy_to_slot/copy_from_slotalready walk every stage's slot sessions, so the pipelined path writes exactly the sessionscopy_from_slotreads back.Enabling the slot cache at
GS == 1therefore costs no additional RAM or VRAM.5.5 Why the fallback then collapses at long context
With the slot cache off, the only resume source left is the main session's
live/checksplusConversationCache, and both of its gates fail for long conversations:Byte budget. Measured
snapshot_bytesfits ≈ 1.2 GiB fixed (live+ up to--prompt-cache 6checkpoints × ~118 MB) + ~14.4 KB per token:Two conversations therefore both fit in
--conversation-cache-mib 8192only below ≈ 206 K tokens each = 78.6 % of--max-context 262144. Above that,make_room()evicts the other conversation oldest-first. (This matches the reported "both sessions at 80 %" threshold exactly.)One figure relevant to PR #1601, which quotes "about 240 MB to 750 MB per park": at these context lengths our parks are 1.9 GiB at 44 K tokens and 4.3 GiB at 210 K tokens, i.e. 3–18× that. The ~1.2 GiB fixed part (the
livestate plus up to--prompt-cache 6checkpoints) is what dominates below ~90 K tokens.Physical-RAM admission.
conversation_memory_admit(MemAvailable, additional, floor)requiresMemAvailable ≥ 6 000 MiB + additional. Our engine's RSS is 75.3 GiB (expert arena 46.8 GiB + pinned host KV 15.5 GiB + parked conversations 4.2 GiB), soMemAvailableis only 7 799 MiB → headroom 1 799 MiB → any snapshot above ~1.8 GiB (≈ 90 K tokens) is refused outright. The floor is a host-levelMemAvailablesample that the engine's own arenas have already consumed.5.6 Two destructive-ordering defects that turn a refusal into a lost conversation
conversations.take(parked.index)(:8257) removes the entry before the turn runs. If the re-park at the end of the turn is then refused by either gate, nothing puts it back → the next turn of that conversation finds no entry at all →0 reused. This is exactly the 103 K → 108 K sequence in §4.make_room(estimate, held)(:6454) evicts entries and incrementsevictions_before the RAM admission check at:6464. A park that is subsequently refused has already destroyed the oldest parked conversation.drop_superseded()at the top ofpark_current_bodyis likewise destructive before the refusal points.6. Proposed fixes and their cost
A. Minimal (what we would like upstream to accept). At
generate.cpp:7672, mirror the non-pipelined path when the group size is 1:GS == 1by construction (§5.2).copy_from_slot— measured 309–689 ms for 45 K–103 K tokens — instead of a 68–73 s full re-prefill.tools/batch_interleave_test.pyalready covers "a next turn continued from its slot" (from all it holds, and from its turn checkpoint), but contains no--batch-groupscase. Adding one with--batch 4 --batch-groups 4would pin this.B. General fix (lifts the limitation for
GS > 1too). Givebatch_launcha row map likerun_slot_rows(rows[]instead ofbase + S), with hand-off rows reserved statically per group so groups still never share one. Cost: hand-off row space grows frombatchtobatch_groups × kVerifyMaxT-ish, and the captured batch-graph layouts multiply (there is alreadyset_batch_graph_limitLRU for--batch-mtp). More invasive than A; A alone already covers theG == Nconfiguration thatsetuprecommends for a layer split.C. Independent of A/B, two ordering fixes worth taking regardless:
make_room()after the RAM admission check, or roll its evictions back on refusal (§5.6, second bullet).D. Documentation.
docs/BATCHING.md:131currently states "a pipelined slot is not kept as a conversation cache". If A lands, that sentence should become "GS > 1only".7. What we have not established (so the maintainers don't over-read this)
--batch-groups 1vs4on this machine with matched context lengths. The pipelined throughput lines are… rows/s (admissions included)and are contaminated by the 68 s re-prefills they are caused by (we see 3.9–6.3 rows/s in windows containing an admission and 26–50 rows/s in clean ones), so no clean multiplier can be quoted from these logs.:7672; the pad-row argument is the only one the code and comments give, and it is unreachable atGS == 1.copy_to_slot/copy_from_slotdo not carry the MTP draft layer's K/V;docs/BATCHING.mdalready notes that a request in a slot decodes without MTP drafts by default and that a drafter that read a different conversation accepted as many drafts as one that read it. We assume that remains true here but have not measured it.8. Reproduction sketch
@Niko1221 commented on GitHub (Oct 10, 2026):
Could not reproduce in v0.1.42, and the path your analysis points at is already handled there: since #857 (in 0.1.40.1 and 0.1.41) a pipelined slot becomes a cache again when its request finishes, and the pad-row clear only touches an idle slot inside a started group, which cannot happen at a group size of 1. Test on 2x Radeon AI PRO R9700 (layer split, --batch 2 --batch-groups 2, i.e. 2 groups of 1, IQ3_S, conversation cache on): two conversations alternating over 3 rounds of ~3.2K tokens each reused 3220-3390 tokens per request (5 'slot N gave back' lines, nothing re-read from token 0 after the first round), and the answers are identical to the same run with --batch-groups 1. If you still see it on v0.1.42 with 3 cards and 4 groups, please send the first 100 lines of the engine log of the second turn; with parks of 2-4 GiB at 44K-210K tokens the separate RAM-floor refusal you describe (#1601's guard now reports the real headroom and its source) is the more likely cause.
@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.
If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
__dp4afalls back to a 4-iteration loop although gfx906 has v_dot4_i32_i8 #3006