Repository navigation
fix(qwen4exp): keep MTP drafting while a thinking budget is open - #935
Merged
Merged
Conversation
The batched engine left max_decode_tokens() at its default of 0, so the scheduler gave a slot whose thinking budget was still open one token per step: the MTP drafts went unused until the thinking closed, which on a reasoning answer is most of it. A step of the MTP slot emits at most QWEN4EXP_MTP_MAX_VERIFY tokens (its accepted drafts and the verified token). Reporting that lets the scheduler keep the bursts while the budget's closing token is still out of reach, as the qwen35 engine does. Measured on an R9700 + Strix Halo box (Qwen3.8-Flash-Next split, four slots, greedy, 384-token answers): code 40-41 -> 51-52 tok/s, prose 44-45 -> 50, a 2K-token document 34-35 -> 43-45. The text is identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
davide221
commented
Nov 3, 2026
davide221
left a comment
Contributor
Author
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and logic errors in the changed code.
Reviewed c5fcd6f7 · 1 candidate issue checked, kept at ≥70% confidence · add the code-review label to review again
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="server/src/qwen4exp/qwen4exp_seq_engine.h">
<violation number="1" location="server/src/qwen4exp/qwen4exp_seq_engine.h:71">
P2: Fixed `--verify-width` values are smaller than `QWEN4EXP_MTP_MAX_VERIFY`, but this advertises 8 tokens anyway. With `--verify-width 2`, the scheduler switches to single-token decoding six tokens before the thinking hard limit; return `verify_width_` for fixed modes and 8 only for adaptive mode.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| bool token_is_eos(int32_t token) const override; | ||
| // A step of the MTP slot alone emits its accepted drafts and the verified token, so the scheduler keeps | ||
| // drafting while a thinking budget is still open and hands off to single tokens only near its close. | ||
| int max_decode_tokens() const override { return mtp_slot_ >= 0 ? QWEN4EXP_MTP_MAX_VERIFY : 1; } |
Contributor
There was a problem hiding this comment.
P2: Fixed --verify-width values are smaller than QWEN4EXP_MTP_MAX_VERIFY, but this advertises 8 tokens anyway. With --verify-width 2, the scheduler switches to single-token decoding six tokens before the thinking hard limit; return verify_width_ for fixed modes and 8 only for adaptive mode.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At server/src/qwen4exp/qwen4exp_seq_engine.h, line 71:
<comment>Fixed `--verify-width` values are smaller than `QWEN4EXP_MTP_MAX_VERIFY`, but this advertises 8 tokens anyway. With `--verify-width 2`, the scheduler switches to single-token decoding six tokens before the thinking hard limit; return `verify_width_` for fixed modes and 8 only for adaptive mode.</comment>
<file context>
@@ -66,6 +66,9 @@ class Qwen4ExpSeqEngine final : public SeqEngine {
bool token_is_eos(int32_t token) const override;
+ // A step of the MTP slot alone emits its accepted drafts and the verified token, so the scheduler keeps
+ // drafting while a thinking budget is still open and hands off to single tokens only near its close.
+ int max_decode_tokens() const override { return mtp_slot_ >= 0 ? QWEN4EXP_MTP_MAX_VERIFY : 1; }
private:
</file context>
Suggested change
| int max_decode_tokens() const override { return mtp_slot_ >= 0 ? QWEN4EXP_MTP_MAX_VERIFY : 1; } | |
| int max_decode_tokens() const override { return mtp_slot_ >= 0 ? (verify_width_ == 0 ? QWEN4EXP_MTP_MAX_VERIFY : verify_width_) : 1; } |
…tep emits A fixed --verify-width caps an MTP step at its draft count plus one (cache.mtp_draft + 1, as qwen4exp_mtp_step reads it), not at QWEN4EXP_MTP_MAX_VERIFY. Reporting 8 at --verify-width 2 was safe but made the scheduler hand off to single tokens up to six tokens before a thinking budget's close; the slot cache's cap is exact in both modes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The MTP slot is slot 0 today; index the cache by mtp_slot_ so the cap follows that slot if it ever moves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 6, 2026
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.
Summary
The Qwen3.8-Flash-Next batched engine never overrode
SeqEngine::max_decode_tokens(), so it reported 0 ("unknown"). The scheduler then treats every slot whose thinking budget is still open as unable to take a burst, and the slot decodes one token per step: the MTP drafts go unused until the thinking closes, which on a reasoning answer is most of the answer.A step of the MTP slot emits at most its accepted drafts plus the verified token: the slot cache's draft cap plus one (a fixed
--verify-width, orQWEN4EXP_MTP_MAX_VERIFYwhen adaptive). Reporting that lets the scheduler keep bursts while the budget's closing token is still out of reach (ThinkingBudget::needs_ar_tail), the same contract the qwen35 engine already follows with its chain width. Slots without the MTP head still report 1.Validation
R9700 + Strix Halo box, Qwen3.8-Flash-Next split across both GPUs, four slots (the default batched launch), greedy, 384-token answers, two runs each:
The answers are byte-identical before and after in every run.
🤖 Generated with Claude Code