Skip to content

gpu, gpu-gates: Qwen3.8's MTP draft store reads only final hidden rows - #691

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-mtp-draft-final-rows
Oct 22, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-mtp-draft-final-rows

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8의 MTP draft가 마지막 층의 combine이 빠진 hidden row로 key와 value store를 채우던 결함을 고칩니다.

Part of #565. Fixes the Medium item in #637.

What and why

With the MTP draft on, a Qwen3.8 prompt call hands the draft the target's hidden row for every prompt position. Only rows that the head's mix covered are final, because the head's mix applies the last layer's combine. Three kinds of rows never get it: the earlier units of a split walk, the earlier ubatches of a call that runs more than one ubatch, and the earlier passes of a call that runs pass by pass. The draft read those rows as if they were final, so the same prompt left a different draft store than it does when the rows run as one unit with the head. The target is not affected: next ids, logits and states stay bit identical, and only the draft's key and value store differ at the positions that read an uncovered row.

The change applies the last layer's combine to the rows the head's mix does not cover, before the draft reads them:

  • Gemm38::finals in wide38.rs runs the standalone combine on every unit the head will not cover (all units when the ubatch runs without the head, all but the last otherwise). The combine call is now one combine function that the PLE front shares, so the copy that lived inline there is gone.
  • Pass38::finals in program38.rs does the same for a pass that runs without the head.
  • walk_pass and walk_gemm in body38.rs call them only when the call feeds the draft. A call with the draft off launches nothing extra, and the head path and the buffers the target reads are untouched: the next pass or ubatch rewrites res in its embedding step, so the added combine never reaches the target's next computation.
  • Wide38 keeps its walked units in one Vec that each walk reuses, in place of the last-unit field and the unit counter, which also drops one allocation per walk.

The alternative I rejected is running the head site's mix over every column. The mix is three launches plus two Q8_0 projections and a mixed write, and it would have to run per unit with that unit's combine weights, so it moves more bytes and launches more than the single combine.

A new gate clause, (fr), compares the draft store after a prompt call walked as several units, ubatches or passes against the same call walked as one unit, bit for bit.

Release notes: Fixed: With the MTP draft on, a Qwen3.8 prompt call no longer fills the draft's key and value store from hidden rows that lack the last layer's combine.

Code shape

  • No second copy. combine replaces the inline combine in the PLE front and serves Gemm38::finals too. The kernel call itself has one owner.
  • Model code holds only architecture facts. The change is inside the Qwen3.8 walk files. No common owner gained a model branch.
  • Dead code is gone. The last-unit field and the unit counter are replaced by one Vec; nothing is left behind.
  • No silent failure. Gemm38::finals called before a walk returns a named error.
  • Comments state what is true now. The TargetRows doc now names the rows the head's mix covers and the rows the prompt call combines itself.
  • No relaxed gate. No band, tolerance or lint moved. The new comparisons are bit for bit.
  • cargo fmt --check is clean on the five changed files. cargo clippy was not run on this head here.

Duplication found or removed (path:line): the inline combine in the PLE front of crates/gpu/src/arch/qwen3moe/wide38.rs, now combine.

What I ran

Hardware: one RTX 5090 32 GB machine (x86_64 Linux), host mode, with the fixture model and its Q8_0 MTP draft.

NVIDIA GeForce RTX 5090, 595.99.02
| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |

The checks below ran on the head just before the last rebase onto main. That rebase left the commit patch-identical in git range-diff (1: 92093fe35 = 1: f25b44cae). Upstream's seven new commits touched three of my files, but only the draft's load path, and left the prompt walk, feed, walk_pass, walk_gemm, final_streams, TargetRows and the MTP policy as they were. I did not rerun the gates or the A/B on the rebased head, and I did not compile it on the GPU machine.

Gates, on the fixture tier:

BLOOMERY_TIER=fixture BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-mtp
gate_qwen4exp_mtp ran 47 s (exit 0)
BLOOMERY_TIER=fixture BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-e2e
gate_qwen4exp_e2e ran 52 s (exit 0)
  • With the fix, every (fr) comparison passes: clauses: 28 ran, 4 left to the real tier and gate_qwen4exp_mtp ran 47 s (exit 0).
  • The same gate with the four changed gpu files restored to main fails, and the differing store positions equal the number of uncovered rows. The split walk gives 32 of 64 positions other from 1, the pass walk 56 of 64, the call cut into ubatches 44 of 64, and ubatches combined with the split walk 54 of 64. The unit and ubatch counts and the next id still pass there, which confirms the target is unaffected.
  • The existing e2e gate passes: clauses: 26 ran, 8 left to the real tier and gate_qwen4exp_e2e ran 52 s (exit 0). Its split-walk bit pins pass, as do the eager and graph step paths, whose logits are bit identical.
  • just contrib-check --tier t0 passed: DONE tier=t0 total=107 red=0.

Speed, 4,096-id prompt with the draft on (BLOOMERY_DRAFT=mtp), Qwen3.8-Flash-Next UD-Q3_K_XL, default placement, one process per row, two sittings with main and head alternating:

generate_qwen3moe -n 4 --ctx 4352 --time
Arm Rows Median tok/s Mean tok/s
main 4 1564.47 1561.32
head 4 1560.42 1552.06
head / main 0.9974 0.9941

The head is within the spread inside one arm (up to 2.5%). In this load the 4,096-row ubatch runs as two units of 2,048 rows, so the added combine runs on one unit. A kernel trace of one prompt shows 21,454 kernels on main and 21,455 on head, and the added launch takes 113,439 ns. That is 0.004% of the 2.6 s prefill. The first sitting's head arm was 1.33% below main on its mean, from one row whose host expert time was 60 ms longer; the second sitting had head 0.15% faster.

What I ran into

This does not block review. I did not measure draft acceptance or decode speed. The speed rows cover the one prompt length above on one machine.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

The head's mix applies the last layer's combine, and a prompt call runs the
head on its last pass or ubatch alone, over a split walk's last unit alone.
The draft's warmup reads every row of every unit, so the rows of a split
walk's first unit and of each pass or ubatch before the last were read before
the combine. A prompt call with a tap now applies the combine alone to every
row the head's mix leaves: Gemm38::finals over each unit but the last (every
unit when no head runs), at the unit's own combine weights, and
Pass38::finals over a pass with no head. A call without a tap runs no such
combine, and the target's bits do not move either way.

gate_qwen4exp_mtp (fr): one call walked as one unit is the reference; the
same call under BLOOMERY_SPLIT_WALK=every and as several ubatches on a load
of the same plan leaves the draft's store and next id bit for bit, and the
call by passes leaves the call by steps'.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 22, 2026

@github-actions github-actions 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.

Verdict: CLEAN: No must-fix finding remains in the changed code.

Non-blocking

⚠ Complete GPU evidence for the current head: wide38.rs:2532.
Tapped prefill adds one combine launch per uncovered unit, including two per headless split ubatch. This launch-count change requires its owning gates. The reported gate runs and A/B predate the rebase; the tested base hash and exact model file are missing. Attach both tested hashes, the model file, and gate/A/B commands with output attributable to this head.

Optimization headroom

  • G. Per-launch and per-sync fixed cost: wide38.rs:2531. The units' residuals, outputs and per-row weights occupy contiguous spans. Use the existing wide combine once over the parent buffers for a headless split ubatch: one fewer launch per such m-row ubatch, or 1/m fewer launches per prompt token [derived].

Checked

Duplicates: 9 new items checked; none duplicated. The extracted combine reuses the PLE operation. Dryer reported 0 pairs in gpu; gpu-gates was excluded and checked by Grep.
Complexity: final_rows_ubatches is new at 18, mostly error propagation and conjunctions in assertions; load and comparison stages remain short. run rises 95→99 through linear gate stages. Neither needs another owner.
Silent failure: the new final-row paths propagate launch errors; a missing ubatch walk returns a named error. Non-GEMM zero counters describe steps/passes.
Tests: static mutation review—dropping the combine calls at body38.rs:3411 or body38.rs:3561 makes the corresponding (fr) store comparisons false; run propagates them to failure. The PR reports FAIL-first with production reverted. No GPU tests were run during this review.
Gates: no existing pin, tolerance or clause was removed or relaxed.
Adversarial checks: unit weights remain separate, the head's unit is excluded from the standalone combine, and the sink reads each pass or ubatch before the next walk reuses its arena.
Escape catalog: C1–C4 have no matches. No ledger lessons are in force.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/mtp38.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit f8578ee into midagedev:main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant