Skip to content

width: a chain draft walks only the width the pass plans to verify - #705

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-draft-stop
Oct 23, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-draft-stop

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 MTP draft가 폭 선택기가 고른 폭만큼만 draft를 걷게 해서, DGX Spark 한 대에서 MTP decode 속도를 코드 약 2.3%에서 3.6%, 산문 약 6.9%에서 8.1% 높입니다.

Part of #565.

What and why

The Qwen3.8 MTP draft walks its own layer once for every id it proposes. The width chooser decides how many ids a window verifies (0 to 3), but the draft ignored that and always walked three ids, so a window that verified one or two ids still paid for the extra walks. One walk costs about 2.5 to 2.7 ms at a 4096-id context on a GB10, against a window of about 60 ms.

  1. width: a chain draft walks only the width the pass plans to verify adds Draft::CHAIN (default false, set by MtpDraft). Choosing::propose hands a chain draft forced.unwrap_or(self.width).min(room) ids, so the walk count follows the planned width. The chain already took its walk count from the room it was given, so no device code changes. A window's own cut can still go below the planned width but never above it. Block drafts and the lookup draft keep CHAIN = false and get their whole width as before.
    • A proposal now learns from the positions it reached: the mean acceptance profile counts seen per position, and "the proposal filled its room" replaces "the proposal held every id".
    • Kind::Cut marks a verify that cut below the ids the draft walked. Its wall time includes walks beyond its width, so it is not a cost reading of that width, the same rule Kind::Walked already follows. Kind::verifies keeps the accept and step bookkeeping the same for Verify and Cut.
    • Gate (c) of gate_qwen4exp_mtp asserted that every proposal held all three ids. It now asserts at least the verified width and at most three ids, and a new condition requires at least one proposal shorter than three ids under the paying walls (the warm-up's forced widths 1 and 2). That condition fails on main.
  2. mtp: walk the waiting rows through the store's append alone makes the catch-up walks that run before a plain step use the store walk. catch_up, before_step and the zero-row walk of a one-id prompt used to run flash, feed-forward, head and argmax, and nobody reads that head: the next chain walks its own refresh, and later rows read only keys and values. Only the chain still uses Shape::mode. MtpBody::FITS now also checks that a refresh fits one store walk (Qwen's STORE_ROWS is 64, GLM's is WALK_ROWS). A Qwen store walk's keys and values match an eager walk's within the q8 activation error, so proposals after a plain step can differ slightly. Kept tokens cannot change, because the target verifies every id.

Release notes: Changed: the Qwen3.8 MTP draft walks only the width the chooser plans to verify, which raises MTP decode throughput by about 2% to 8% on one DGX Spark.

Code shape

  • No second copy. Choosing::propose is the one owner of the width rule and policy.rs chain of the room rule. The catch-up walks reuse the store walk the prompt's warm-up already used.
  • Model code holds only architecture facts. The runtime change is one associated const on Draft. The common chooser gained no per-model branch.
  • Dead code is gone. The w.ids.len() == 3 gate pin was replaced by the range check and the new condition.
  • No silent failure. A Cut wall that is not positive is refused by name, like a Walked wall.
  • Comments state what is true now.
  • No relaxed gate. The gate (c) length check is widened from exactly three to the verified width up to three, and a stricter condition is added beside it that fails on main.
  • cargo fmt is clean on what I touched.

Duplication found or removed (path:line), or "none": none.

What I ran

Head df7686ea1 on main a83dd0df9. cargo check --workspace --all-targets with the check recipe's features, just gate-app and both MTP gates ran on this head, on an RTX 5090 machine.

GPU Evidence

On an NVIDIA GeForce RTX 5090 (gates):

| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
|   0  NVIDIA GeForce RTX 5090        Off |   00000000:01:00.0 Off |                  N/A |

On an NVIDIA GB10 (throughput):

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
Command Result
cargo check --workspace --all-targets rc 0, no warning or error line
just gate-app test result: ok. 27 passed; 0 failed
just gate-gpu-qwen4exp-mtp (fixture tier) exit 0, clauses: 28 ran, 4 left to the real tier; gate (c) paying and losing, (i) and (v) PASS
just gate-gpu-glm5next-mtp (fixture tier) exit 0, clauses: 14 ran, 7 left to the real tier

Gate (c) paying on the head:

(c) paying: the 64 ids = the plain run's PASS; 12 windows, each its pass's width with the target's kept ids PASS; the chooser's widths [51, 4, 4, 4] = the passes' [51, 4, 4, 4] PASS; incumbent 0, the cuts and the gate PASS

The new tests and gate conditions fail without the change (each check ran on the same patches before the final rebase, which left both patches unchanged):

  • With depth = room in width.rs, so a chain draft gets its whole width again, a_chain_draft_walks_the_width_it_verifies fails (1 failed), and gate (c) fails (the cuts and the gate FAIL, widths [0, 0, 59, 4]).
  • With the three catch-up walks back on self.shape.mode, gate-app fails 6 of 26 tests (20 passed; 6 failed), the ones that expect the store walk.
  • With this head's gate over main's width.rs, speculative.rs and mtp.rs, gate (c) paying fails (incumbent 0, the cuts and the gate FAIL), because every proposal there holds three ids.

Not run: just gate-gpu-qwen4exp-mtp at the real tier, which needs fixtures this machine does not have, so a maintainer runs it.

Throughput

The checkpoint is nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, served from its folder with its own MTP layer and the width chooser at its default, bloomery-serve --parallel 1 --ctx-size 8192. Each arm loads its server once. Every request uses a 4096-id prompt, 128 generated ids, temperature 0 and one concurrent request. Each arm sends one warm request, then 8 code windows and 8 prose windows. Decode tok/s is the generated ids over the server's decode time. The GPU clock cap was lifted for each arm only.

Case (FP4-Local, one GB10, 4096-id prompt, 128 ids, 8 windows) main head change
C@1 MTP greedy code-fn decode tok/s, sitting b (main first) 50.873 52.702 +3.60%
C@1 MTP greedy prose-en decode tok/s, sitting b (main first) 34.832 37.642 +8.07%
C@1 MTP greedy code-fn decode tok/s, sitting c (main last) 51.806 53.015 +2.33%
C@1 MTP greedy prose-en decode tok/s, sitting c (main last) 35.761 38.230 +6.90%

C@1 MTP decode rose 3.60% and 2.33% on code-fn and 8.07% and 6.90% on prose-en in two sittings with opposite arm order; every window of both corpora was at least as fast on the head in both sittings.

Sitting b ran main first on main 78c3680d3 and head 287d5e458. Sitting c ran main last on main a83dd0df9 and head df7686ea1. The rebase between the two left both patches unchanged. The gain keeps its sign and most of its size with the arm order reversed. Greedy ids were equal in all 32 request pairs of each sitting. Every figure is one observation per arm with no confidence interval.

For reference, here is the same checkpoint on NVIDIA/flare-local-inference (5f37bd14 with the loader patch from its issue #2, the recipe's default package with adaptive MTP) on a DGX Spark (GB10, driver 595.84), C@1, 4096-id prompts and 128 generated ids. The bloomery columns are sitting c above.

C@1 MTP decode tok/s Flare bloomery main this PR this PR against Flare
code-fn 51.3 51.806 53.015 +3.3%
prose-en 37.4 35.761 38.230 +2.2%

This PR is ahead of Flare on both corpora, but the margin may be within the run-to-run spread.

Where the time went, from the width chooser's own cost readings in sitting b: dropping two walks made a width-1 verify cheaper (48.05 to 42.12 ms in one request), and dropping one made a width-2 verify cheaper (55.51 to 52.68 ms), while a width-3 verify stays near 60 ms. One walk is therefore about 2.5 to 2.7 ms. With these prices the prose gate settles on width 1 most of the time, where it picked width 2 on main.

The second commit makes a plain step about 1 ms cheaper (34.60 ms with only the first commit to 33.33 ms with both, in the same readings), but plain steps are rare at this load, so it shows no throughput change in these runs. It matters where the chooser closes and plain steps are common, which this A/B does not measure.

What I ran into

This does not block the PR. Code decode gains less than prose decode here, because code windows mostly verify three ids and keep the full walk cost. Verify rows are most of a code window, and the draft's own walk is the next largest cost the chooser can see.

Hardware

One NVIDIA DGX Spark (GB10), driver 595.84, CUDA 13.3, for the throughput runs, and one RTX 5090 machine, driver 595.99.02, CUDA 13.2, for the checks and gates.

AI help

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

The MTP draft proposes one id per walk of its own, yet the width chooser
handed it its whole width every window and then verified the front k ids:
a window cut to 1 or 2 still paid for every walk up to 3. The draft's
`Draft::CHAIN` now says a proposal into less room runs only its walks, and
the chooser hands such a draft the width it plans to verify (the warm-up's
or a probe's width, else the gate's). A window's own profile can still cut
that width but not widen it. A shadow still walks the whole width.

Each width's cost readings now hold the walks that width needs, so the
gate weighs a narrower verify at its own price. A verify cut below the ids
the draft walked is no reading of its width (it holds walks past it), and
the mean profile learns each position from the proposals that reached it.
Block drafts and the lookup draft keep their whole width.
The rows a step or a held pass walks before the target overwrites their
arena (the cut step, every plain pass of a closed width chooser, a prompt
call that continues the sequence) ran a whole walk with its flash,
feed-forward block and head, though nothing reads them: the next chain
walks its own refresh, and a later row reads only the rows' keys and
values. They now run as store walks, which stop after the append, as the
prompt's walks already do. Only a chain's walks read a head.

`MtpBody::FITS` now also holds a refresh to one store walk.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 23, 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: The changed draft widths, acceptance bookkeeping and store-only catch-up have no proven merge-blocking defect.

Non-blocking

⚠ Supply the GB10 benchmark commands: crates/runtime/src/width.rs:1371. The throughput table supplies revisions, model and request sizes, but omits the benchmark/client commands and their output. Attach them for both arms, as CONTRIBUTING.md requires, so the speed claim can be reproduced before publication.

Checked

  • Duplicates: 7 new function/constant declarations checked; no duplicate owner. Dryer reported zero pairs. The changed GPU gate was checked manually.
  • Complexity: land 17→20 adds the Cut timing arm; propose 27→29 adds chain room selection; width_chooser 23→24 strengthens the paying clause. These extend their existing jobs.
  • Silent failure: 3 paths followed. The width fallback selects the incumbent; invalid proposal probabilities return WidthError::Probability; nonpositive Cut walls return WidthError::Time. Cut acceptance still updates calibration and tallies.
  • Tests: static mutation review maps width.rs:1372 changed to room to the new walked-versus-verified assertion; policy.rs:319/619 changed back to shape.mode to all six edited policy tests. The two other runtime test edits preserve their assertions. The PR reports FAIL-first for the width test, store-mode tests and gate (c).
  • Gates: the proposal-length change has PIN(2026-10-23) and a reason; the added short-proposal clause rejects the old full-width behavior.
  • Adversarial checks: shortened proposals cannot widen past their room; both verify kinds retain acceptance bookkeeping; store-only catch-up is followed by a fresh chain refresh. Context-end and NaN scenarios are guarded.
  • Escape catalog: C1–C4 do not match this diff.

Notes

Runtime checks were not rerun during this static review. The PR reports fixture-tier MTP gates on an RTX 5090 and defers the real-tier Qwen gate.

Card check: gpu-evidence. This pull request changes crates/app/src/mtp.rs, crates/app/src/mtp/policy.rs, crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs and carries a gate run on the author's card, which counts as verified.

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

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 23, 2026
@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 b9dfc4a into midagedev:main Oct 23, 2026
7 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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant