mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4677] [Engine] parked conversation snapshot sometimes rejected on continuation — falls back to an older checkpoint and re-reads ~6% of the prompt #2133
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#2133
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 @hanchengme on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4677
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Source, and the packaged engine too. We run
serve/server.py --engine stratawith the serve side at tagv0.2.8(870aedd9). Three engine binaries are involved:efc84b874c18fcf531bb89acaec1c6f16df0b0d96a7d48b3dff0f284d7255fc5BUILD.jsonreportssource: f-amd-vision 8c1aea4bca1b870aedd9, unmodified053b02e696ef110213548e25a38af567b7e1b848dca28201d67c06b21861ccbfSTRATA_SERVE_STOP_BOUND=1)9cd5d5d4bc3cbe688c3b216a72fe5b6d5019879a95abf7116a203e310d67463aAll three show the fallback. One caveat we want to state up front: the packaged build self-reports its source object as
f-amd-vision 8c1aea4bca1b, which we could not locate in the public repository, so all source reading and the patch are against the public870aedd9; we do not claim that is byte-for-byte the shipped source.What happened
A parked conversation snapshot is sometimes not accepted on continuation, and the engine falls back to a mid-prompt checkpoint. The whole generated answer's K/V is discarded and 809 tokens of prefill are paid again. Every answer in these runs is verified by an acceptance code embedded in the request, and 96/96 correctness checks passed — this is a cache-identity problem, not a wrong-answer problem.
Same serve, same model, same client script. Hit:
Miss, same conversation, next turn:
The prompt is 12,076 tokens; after a 768-token answer the parked length should be 12,843/12,844 (last emitted token left unconsumed, as in the scalar loop). On the miss, reuse drops to 12,069 and reuse fraction goes 99.73% → 93.72%; time to first token 0.31–0.55 s → 0.96–1.29 s.
Two things make this worth a look:
parked 12845 tokens6 times, where the correct parked length for this shape is 12,843/12,844 — i.e. a snapshot parked with more tokens than the client ever received.The code that can produce that, in the single-request speculative decode paths of
870aedd9(normal path aroundsrc/program/generate.cpp:16749–16802, and the experimental two-verifier path around line 16334): the accepted rows of a verify window are committed first, and the output loop truncates tomax_new/ EOS afterwards.If the last window of a request accepts more rows than the request is allowed to emit, the live state and the
consumedsequence — and therefore the snapshot that gets parked — carry tokens the client never got. Sinceconversation_prefix()requires the snapshot's full token sequence to be a prefix of the new prompt, and the snapshot also carries running state so it cannot be rewound to a shorter common prefix, the whole snapshot is rejected and the older checkpoint is used instead.We tried a bounded-commit change (attached, opt-in, HIP only): cap the accepted rows at the rows this request can actually emit, and end at the first EOS, before
pl_commit_async. Merged prompt windows keep the current behaviour; the grouped--batchMTP path is untouched because it already bounds emittable rows when it starts a window.-Wall -Wextra -Werroron both clang++ (macOS) and g++ (Linux).It is not a complete fix, and we want help with the rest. One of the eight patched continuations still falls back to the same
12069 tokens (checkpoint). So a second source of sequence mismatch exists that we have not located, and since our shape runs--batch 8 --batch-groups 2, the snapshot that failed may have been written by the batch path at all rather than by the two paths we changed.Smallest steps or command that reproduce it
--conversation-cache-mib 16384 --conversation-cache-slots 16 --conversation-cache-min-tokens 4096 --conversation-cache-park-gain 128 --conversation-cache-min-free-mib 32768,--batch 8 --batch-groups 2, 262144 context, KV int8,--spec 4with MTP, temp 0.timings.cache_n/prompt N tokens = X reused + Y read.cache_n ≈ 12843–12844, ~34 tokens read. Observed on some continuations:cache_n = 12069, 809 tokens read, and arestored 12069 tokens (checkpoint)line in the engine log.Continue the same conversations with short answers instead and reuse stays ~99.79% with no fallback at all — that is the trap in reproducing this.
Reproduction status
Reproduced locally, on this machine, on:
--conversation-cache-park-gainsweeps (1024 / 128 / 0), where the run config leftexeunset so serve loaded/opt/Strata/engine/strata; every threshold showed the same partial fallback, so the park thresholds are not the cause;v0.2.8(head870aedd9), unmodified — 1 of 4 continuations fell back to the 12,069-token checkpoint (93.72% reuse);Not every continuation shows it; in these runs roughly one in four to one in eight. All prompts are synthetic; no real user content is included in the attachments.
Strata version
Strata 0.2.8 · engine 0.1.54. Serve code at tag
v0.2.8head870aedd9; engine binaries and their SHA-256 are listed under "Desktop app, Terminal or source?" above.Graphics card, memory and system
4× Radeon AI PRO R9700 32 GB (gfx1201) behind a PLX PCIe switch · EPYC 7452 (32C/64T) · 251 GiB RAM · Linux, kernel 7.0.0-38-generic · ROCm 7.2.4, hipBLASLt 100200 ·
serve/server.py --engine strata, two replicas of two cards each, 8 batch slots per replica (16 slots total).Also present in the run config and unrelated to this report:
HSA_ENABLE_SDMA=0, which is our mitigation for the separate SDMA page-fault crashes in #4591. Nothing here crashes — the native engine PIDs were unchanged through these runs and there were no kernel GPU fault signatures in the window.Model, size and settings
Qwen3.8-Flash-Next IQ3_S · 262144 context · KV int8 ·
--kv-resident 20480·--spec 4+ MTP ·--batch 8 --batch-groups 2(STRATA_PIPED_MTP=1) ·--layer-split 25 --trim-stage-weights· conversation cache--conversation-cache-mib 16384 --conversation-cache-slots 16 --conversation-cache-min-tokens 4096 --conversation-cache-park-gain 128 --conversation-cache-min-free-mib 32768· temperature 0, thinking off, pictures enabled and verified separately.Reproduction shape:
timings.cache_nplus theprompt N tokens = X reused + Y readline.Expected on the continuation:
cache_n ≈ 12843–12844, ~34 tokens read. Observed on some continuations:cache_n = 12069, 809 tokens read. Hit and miss side by side, same serve and script:Reuse fraction 99.73% → 93.72%; time to first token 0.31–0.55 s → 0.96–1.29 s. Every answer carries an acceptance code that we check, and 96/96 checks passed, so the answer is right and only the cache identity failed.
The trap when reproducing: continue those conversations with short answers instead and everything is fine — a 32-conversation × 12K round robin with short answers reuses 99.79% weighted over three rounds with zero fallbacks. The failure needs a long answer, because that is what makes the last verify window accept more rows than the request can still emit.
What we ruled out
--conversation-cache-park-gain1024, 128 and 0 all showed the same fallback;--spec 2also showed it (single-stream decode 72.88 vs 82.37 tok/s in that same shape, so it is not a free knob), therefore the thresholds and the draft depth are not the cause.evictions=0with parked bytes far below the 16 GiB budget, andMemAvailablestayed above the 32 GiB floor;min-tokenswas met.The code we found, and the attached attempt
In the single-request speculative decode paths of
870aedd9(normal path aroundsrc/program/generate.cpp:16749–16802, experimental two-verifier path around:16334), the accepted rows of a verify window are committed before the output loop truncates tomax_new/ EOS:So the state and
consumed— and the snapshot parked from them — can contain accepted rows whose outputs this request never emits. Sinceconversation_prefix()needs the snapshot's full token sequence to be a prefix of the new prompt, and the snapshot carries running state that cannot be rewound arbitrarily, the candidate is rejected as a whole rather than truncated to the shared prefix. The over-commit shows up in the log asparked 12845 tokenswhere this shape should park 12,843/12,844.Attached
spec-stop-bound-complete.patchadds one pure helper and calls it before the commit in both single-request paths (STRATA_SERVE_STOP_BOUND=1, HIP only, off by default); merged prompt windows keep today's behaviour.git apply --checkpasses against870aedd9.What it does and does not fix is stated above; the honest summary is that over-commit is real and reproducible, the patch is behaviour-preserving for output and improves this subset, but it does not remove every fallback.
Logs
engine-log-fallback-excerpt.txt, plus arm-labelled machine-readable results with the run configuration SHA-256 incontinuity-unpatched-public-0.2.8.jsonandcontinuity-patched-stop-bound.json. The engine's own serve log lines carry no timestamps and our log files span several restarts, so the counts inside that file are not attributed build-by-build — the JSON files are.All requests in the runs are synthetic tasks; no api keys, credentials or real user sessions appear in any attachment.
Questions
--batch 8 --batch-groups 2(withSTRATA_PIPED_MTP=1)? Does that path's snapshot token sequence stay aligned with what the request emitted, or can it also carry rows whose outputs were cut bymax_new/ EOS?conversation_prefix()compare, and is there a debug switch that prints why a candidate snapshot was rejected — the first differing token position, or which running-state array / shape mismatched? That would locate the residual case in a single run instead of another 72-request sweep.Not covered
--batchMTP path: not changed, not analysed beyond reading that it bounds emittable rows at window start.stop-bound-20261030.tar.gz
@Niko1221 commented on GitHub (Oct 31, 2026):
Your analysis is clear, and the test of the policy function is what we'd want. We haven't applied the patch. It changes the commit path of the speculative decode in the engine, so it needs a run on an AMD card with the long-answer case (4 cards,
--batch 8 --batch-groups 2). Our AMD boxes are busy this week, so we'll run your 8-continuation test against the patch when one frees up.About the build ID: the packaged engine's
f-amd-vision 8c1aea4bca1bis a branch name from our side, so the public source you read can differ from it. If you can, please send the first lines of the engine log of the packaged build, with the prompt and answer lengths of a miss.@hanchengme commented on GitHub (Oct 31, 2026):
Thanks — and understood on the AMD run; no rush, and happy for you to take the 8-continuation test yourself. Our box is exactly the shape you described (4× R9700 gfx1201, 2 replicas × 2 cards,
--batch 8 --batch-groups 2,STRATA_PIPED_MTP=1, conversation cache 16 GiB / 16 slots per replica), so if it helps we can re-run the arms here on a schedule and post the numbers, or test an instrumented build from you instead. Two things we owe you, and one new finding that we think matters more than the patch.1. The packaged-build log you asked for. Attached:
packaged-0.1.54-log-window.txt— theengine started:line with the full command line and the following startup lines of a packaged-engine run (2026-10-30 11:37:10,/opt/Strata/engine/strata, top-level SHA-256efc84b87…,BUILD.json=version 0.1.54,source f-amd-vision 8c1aea4bca1b,variant rx9070,portable true,vision gpu), plus the hit and the miss from that same run, same conversation:Lengths for the miss: the first turn is a 12,076-token prompt with a 768-token answer (769 requested); the continuation prompt is 12,878 tokens, client history is a verbatim echo of that answer,
max_new_tokens768 again. Expected reuse 12,844 (+34 read), observed 12,069 (+809 read). Same run, same replica, the over-park signature is in the attached window:parked 12845 tokenswhere this shape can only park 12,843/12,844, twice, on the packaged binary. So the packaged build shows the same thing we patched, andf-amd-vision 8c1aea4bca1bbeing a branch name is consistent with our reading — we don't claim the public tree is byte-identical to it.2. The residual case is a different bug, and we can now point at it. We kept digging after posting, because with the patch applied 7 of 8 continuations hit and 1 still fell back to the same 12,069-token checkpoint. The remaining case is not an over-commit in the spec path: the token sequence the engine parked and the token sequence serve re-derived from the echoed history genuinely differ, mid-answer, at a BPE boundary. From a native prefix trace (identical text on both sides, same model, temperature 0, and the four fixed tasks still produce byte-identical output hashes):
So the snapshot's token sequence stops being a prefix of the new prompt for a reason that has nothing to do with which decode path wrote it, and
conversation_prefix()is right to reject it — a whole 12.8k-token snapshot is lost over a handful of boundary tokens. That also predicts why a benchmark with short answers never sees it: fewer tokens of generated text in the history means fewer opportunities for a boundary to land differently.We fixed it at the serve layer rather than the engine, as a way to confirm the diagnosis: when the incoming history matches the previous turn verbatim, reuse the token ids the engine actually generated for its own reply instead of re-tokenizing it (
reuse_generated_prefix, off by default in our build). On exactly the failing 8-continuation shape that moved 6/8 → 8/8 above 99%, weighted reuse 98.22% → 99.73%, mean TTFT 0.683 → 0.515 s, with the first-turn output byte-identical to baseline and decode speed unchanged; in a 16-way concurrency variant 32/32 stayed above 99%. It is a workaround, not the right home for the fix — the engine knows what tokens it emitted, the client does not. For a proper fix on your side it looks like either (a) telling the client which token ids the assistant turn occupies so the next request can be re-derived exactly, or (b) letting the cache match tolerate a boundary re-tokenization instead of demanding an exact prefix, or (c) comparing the parked sequence against the text rather than the ids.3. The two questions from the original post still stand, and are now the short path to the rest. (i) Which path writes the snapshot for a batched slot under
--batch 8 --batch-groups 2withSTRATA_PIPED_MTP=1— the over-parked12845appears with our patch applied, i.e. in a build where both single-request paths are bounded, so a batch path is the likely writer. (ii) A debug switch that prints why a candidate snapshot was rejected — first differing token position, plus the ids/text on each side, would have replaced two 72-request sweeps with one run. With (ii) we can run it on this box and hand you the trace.Status on our side, so the numbers above are unambiguous: production is currently the public
870aedd9(v0.2.8) serve plus our HIP build of it withSTRATA_SERVE_STOP_BOUND=1, and the serve-layerreuse_generated_prefixguard. If you land your own fix for the over-commit and something that pins the assistant-turn token identity, we will drop both local patches and re-run the arms against the release. And to be explicit about coverage: HIP/gfx1201 only — we have not built or run CUDA, SYCL, Metal, or Windows, and we did not GPU-validate the experimental two-verifier path.packaged-0.1.54-log-window.txt
@DamirLukina88 commented on GitHub (Nov 7, 2026):
AMD RDNA3 (RX 7600 XT) Validation Report for
serve_stop_bound(#4677)Sharing the measured numbers from an AMD RDNA3 setup with speculative decode (
--spec 4, MTP) across multi-turn continuations on the commit path change.Hardware & Test Environment
gfx1102, ROCm 6.2, CachyOS Linux,MemorySwapMax=0)Qwen3.8-Flash-Next Coder IQ1_M, MTP--spec 4,--max-context 65536, int8 KV cache, 256 resident experts in RAMSTRATA_SERVE_STOP_BOUND=1Test Results: Policy & Unit Verification
tests/core/serve_stop_bound_test.cppacross 2,736 boundary edge cases comparing the speculative commit bounds against the output emission loop.Benchmark Measurements: Long Multi-Turn Continuations (A/B)
Ran a 4-leg paired A/B benchmark (16 long requests with multi-turn conversation caching) comparing default unconstrained commit (
STRATA_SERVE_STOP_BOUND=0) vs bounded commit (STRATA_SERVE_STOP_BOUND=1):STRATA_SERVE_STOP_BOUND=0)STRATA_SERVE_STOP_BOUND=1)\pm 0.2tok/s)Observations