Repository navigation
Conversation
…ulti-turn resumes (#98) Flash Next (qwen4_exp) on CUDA remembered the whole prompt as its prefix-cache entry and matched only an exact token-prefix-extension. Because Flash Next is a reasoning model, the next turn re-renders the assistant boundary (a stripped <think> plus two newlines) so the last token of the previous prompt differs, the stored full-prompt entry is no longer a prefix, _slot_for/_resume find nothing, and every turn pays a full prefill (cached=0). This is what #98 reports. The dense 27B (qwen3_5) already avoids this by keeping its entry one token early (entry_end). Port the same idea to qwen4_exp: - decode.prefill: add keep_at. It forces a chunk boundary onto keep_at, captures the committed state there (a resume dict {state, tail}), then absorbs token keep_at into the MTP head exactly as a resume does. The kept state's bits match a fresh prefill of prompt[:keep_at] and the current request is unchanged; it returns (first, kept) when keep_at is set. - engine.entry_end + both remember paths (concurrent MultiDecoder.admit and the single-stream _decode) store prompt[:entry_end] with that early state. entry_end is applied on one GPU only, so the two-rank path (which hands rank 1 a fixed resume point) is untouched. Output stays exact regardless: every drafted token is verified against the target and the reused KV rows come from the retained slot, so a wrong MTP resume tail could only lower draft acceptance, never change the reply. Follow-ups (not in this change): message-start snapshots via resume_points/points (needs multi-stop capture in prefill), resuming past the previous reply, and the two-rank path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
Author
|
Closing this as a duplicate of #124. I didn't see it when I opened this one, sorry for the noise. #124 fixes the same thing more completely: it keeps the state inside the chunk (no extra forward), it handles the same prompt sent several times in a row (this PR misses every other identical resend), it covers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #98.
Problem
On the CUDA lane, Flash Next (
qwen4_exp) remembered the whole prompt as its prefix-cache entry and matched only an exact token-prefix-extension. Flash Next is a reasoning model, so the next turn re-renders the assistant boundary (a stripped<think>plus two newlines), which changes the last token of the previous prompt. The stored full-prompt entry is then no longer a prefix of the next turn,_slot_for/_resumefind nothing,cached = 0, and every turn pays a full prefill — exactly what #98 reports.It reproduces only with thinking on (the default): with the reasoning boundary the last token diverges by exactly one token (
…assistant\n→…assistant\n<think>\n\n…); with thinking off the full-prompt entry already matches.Fix
The dense 27B (
qwen3_5) already avoids this by keeping its cache entry one token early (entry_end). This ports the same idea toqwen4_exp:decode.prefillgainskeep_at: it forces a chunk boundary ontokeep_at, captures the committed state there (aresumedict{state, tail}), then absorbs tokenkeep_atinto the MTP head exactly as a resume does. The kept state's bits match a freshprefill(prompt[:keep_at])and the current request is unchanged; it returns(first, kept)whenkeep_atis set.engine.entry_end+ both remember paths (concurrentMultiDecoder.admitand single-stream_decode) storeprompt[:entry_end]with that early state.entry_endis applied on one GPU only, so the two-rank path (which hands rank 1 a fixed resume point) is untouched.Output stays exact regardless: every drafted token is verified against the target and the reused KV rows come from the retained slot, so a wrong MTP resume tail could only lower draft acceptance, never change the reply.
Results
1× DGX Spark (GB10),
Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP,--parallel 5 --context 262144 --kv-dtype int8, thinking on. Controlled A/B: cleanv0.5.0(worktree at9cd52ab) vs the same + this patch, identical image and flags.cached = 0and warm TTFT = cold TTFT (1×) at every size — full re-prefill each turn.cached= prompt − 1 confirms the one-token-early entry.tools/bench.pydecode 69.3 code / 55.7 chat tok/s;tools/toolcheck.pyOK.--parallel 4/5) and single-stream (--parallel 1).Not in this change (follow-ups)
resume_points/points(needs multi-stop capture inprefill), for reuse when an earlier turn is edited.qwen3_5).🤖 Generated with Claude Code