Skip to content

fix(qwen4exp): keep MTP drafting while a thinking budget is open - #935

Merged
davide221 merged 3 commits into
mainfrom
fix/qwen4exp-draft-while-thinking
Nov 6, 2026
Merged

davide221 merged 3 commits into
mainfrom
fix/qwen4exp-draft-while-thinking

Conversation

@davide221

@davide221 davide221 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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, or QWEN4EXP_MTP_MAX_VERIFY when 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:

prompt before after
code 40-41 tok/s 51-52 tok/s
prose 44-45 tok/s 50 tok/s
2K-token document 34-35 tok/s 43-45 tok/s

The answers are byte-identical before and after in every run.

🤖 Generated with Claude Code

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 davide221 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; }

davide221 and others added 2 commits November 4, 2026 16:00
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant