Skip to content

mtp: walk every plain slot's waiting draft rows in one store walk - #735

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-draft-walk-batch
Oct 23, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-draft-walk-batch

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

MTP draft를 켠 Qwen3.8 서버에서 여러 slot이 같은 round에 plain step을 할 때, slot마다 따로 돌던 draft의 store walk를 한 번으로 묶어 sampled 요청의 처리량을 높이는 작업입니다.

Part of #565.

What and why

With BLOOMERY_DRAFT=mtp on Qwen3.8, a round in which several slots take a plain step (every sampled request that runs beside another slot, and every drafted slot whose window has no proposal) ran one target pass, but the MTP draft walked each slot's waiting rows one slot after another, one store walk per slot. This PR gathers those walks and runs them as one store walk over every slot's rows before the round's pass. Each slot's rows are embedded at their own positions and appended to their own store, so each slot's draft store is the one its own walk would have written. The shared part of a store walk (the ids upload, the input pack, eh_proj, the attention site's mix and the q, k and v projections) now runs once per round and reads its dense weights once.

A second commit removes the serial fallback round_keeps_refresh for rounds that leave slot 0 out. Such a round used to step slot by slot so that slot 0's waiting draft rows in the pass arena were not overwritten. The pass now walks into the first slot's own row buffer when it holds no row of slot 0, so slot 0's waiting rows stay where its draft reads them and the round runs as one pass.

On one DGX Spark (GB10) with nvidia/Qwen3.8-Flash-Next-FP4-Local, bloomery-serve --parallel 4, 4096-id prompts and 128 generated ids, sampled C@4 all-active decode moved by +4.41 to +7.22 % over main in all four measurements of two sittings, and its group total by +2.09 to +3.06 %. Sampled C@2 moved between -0.45 and +3.38 %, and greedy and time to first token stayed within noise. Every request returned the same ids on main, on the head and on the head with the draft off, in every group of both sittings. The drafted sampled groups remain 0.85 to 5.15 % below the same head with the draft off, so the #695 slot rule stays.

Changes

  • crates/app/src/mtp.rs: MtpDraft::gather runs the slot's own Policy::before_step against a Gather exec that records the store walk of the target's rows instead of walking it. A chain, a host-hidden walk or two heads are refused by name. SlotWalks::run hands every gathered slot's rows to MtpBody::store_slots, in calls of at most STORE_ROWS rows, before the target call that may overwrite them. MtpBody::store_slots defaults to the per-slot walk, so GLM keeps its behavior with no code of its own.
  • crates/gpu/src/arch/qwen3moe/mtp38.rs: Mtp38::store_rows and Mtp38::append_store replace store_walk. Mtp38::stage_store stages each slot's rows into its window of the store arena (with the arena bound checked by name), store_rows runs the shared part once over every block, and append_store appends each block to its own slot's store. Mtp38::checked holds the refusals that run_walk had, and copy_hidden is the one copy of the hidden-row match for the chain path and the store path, now over checked Windows.
  • crates/gpu/src/arch/qwen3moe/body38.rs: GpuModel::<Body38>::mtp_store_slots overrides the default. Body38::enqueue_slots swaps the first slot's rows_pass into the pass arena's final-stream place when the pass holds no row of slot 0 (stands_in), walks, and swaps back. That slot's RowsCopy is then not launched, and slots_launches counts one launch fewer.
  • crates/gpu-gates/src/bin/shared/serve_seats/{drafted,rounds,qwen38}.rs: step_rows_drafted and pass_slots' depth-zero windows gather and run the walk before the pass. before_row_by holds the seat's records around both the walk and the gather. round_keeps_refresh and its arena-model unit test go, with a dated PIN line in the test module.
  • crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs: capped_run takes a pass list and serves both the depth references and the new plain-rounds references, and slot_rounds runs both slots' rounds for the depth clauses and the plain rounds. The (z) "plain rounds" clause is new (see "What I ran").
  • crates/levers/src/lib.rs, docs/serving.md and the seat's docs: they now say the drafts are walked in one store walk beside the pass. The load draft=off message stays true and is unchanged.
  • tools/unsafe-ratchet.txt: the gpu pin goes from 2256 to 2253, because copy_hidden over checked windows removes three unsafe views. The diff adds no unsafe.

Only store walks of the target's rows are gathered. Drafted chains read a head and their own last row, so they stay per slot. The policy still decides each slot's rows (before_step), so batching moves where the rows run and leaves the choice of rows alone.

Release notes: Changed: a Qwen3.8 load with the MTP draft runs the draft's store walks of several slots' plain steps as one walk, which raises sampled decode throughput at four concurrent requests on a DGX Spark.

Code shape

  • No second copy. copy_hidden is the one copy of the hidden-row match for both walk paths, before_row_by serves both the walking and the gathering entry, and capped_run and slot_rounds absorbed the gate's separate plain-rounds runner and the repeated depth runs. The one pair the duplicate scan lists is answered below.
  • Model code holds only architecture facts. The gather and the batched walk go through MtpBody::store_slots, whose default is the old per-slot walk. GLM has no new code.
  • Dead code is gone. store_walk, round_keeps_refresh and its unit test are removed. capped_run's None arm has no caller in the first commit alone and is used by the second.
  • No silent failure. stage_store past the arena, store_rows with ids that do not match its blocks, mtp_store_slots with a slot named twice or a poisoned model, and Gather with a walk that is not a store walk of the target's rows or has two heads are each refused by name. enqueue_slots swaps back on a failed walk and returns the walk's error first.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved. One unit test is removed with a dated PIN reason, because the rule it modelled is gone and the (z) "plain rounds" clause pins the behavior on the card.
  • cargo fmt and cargo clippy: cargo fmt is clean on what I touched. I did not run cargo clippy here.

Duplication found or removed: crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs:720 and drafted.rs:957 (before_row and gather_row) are one-line calls of the shared before_row_by, one walking (before_step) and one gathering (gather, which needs B: Slots).

What I ran

GPU evidence

The A/B ran on one DGX Spark. The first gate run and the FAIL-first runs ran on an RTX 5090 machine, and a later gate run ran on the same GB10 as the A/B. The GB10 A/B log prints the card, driver and CUDA version in nvidia-smi:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

The RTX 5090 gate runs print the card with nvidia-smi -L, and the machine's nvidia-smi query reports its name, driver and compute capability:

GPU 0: NVIDIA GeForce RTX 5090 (UUID: GPU-d61733c2-d437-7c63-ed90-4e410e223a60)
NVIDIA GeForce RTX 5090, 595.99.02, 12.0

The GB10 gate run prints its card the same way:

GPU 0: NVIDIA GB10 (UUID: GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb)

Throughput A/B

One GB10, nvidia/Qwen3.8-Flash-Next-FP4-Local from its folder with its own MTP layer, bloomery-serve --parallel 4 --ctx-size 16896 (4224 per slot, prompt cache off), one server load per arm. Every request has a 4096-id prompt from a code corpus and generates 128 ids. Groups: C=2 and C=4 requests sent at once. Sampled requests use temperature 0.7, top-p 0.8, top-k 20 and seed 20261023 plus the request index. "sampled ignore_eos" is the same group with ignore_eos. Greedy requests do not use ignore_eos, so an early end reruns the wave with shifted windows. All-active decode tok/s is the summed decode rate over the window in which every request of the group decodes. Group total tok/s is the group's ids over its wall time. BLOOMERY_STEP_STATS=1 is set on every arm. The arms are main with the MTP draft, the head with the MTP draft, and the head with BLOOMERY_DRAFT=off, in that order in each sitting. The GPU clock cap was lifted for each arm and restored after it.

Each sitting ran every arm once, and two sittings ran, so each cell is one observation and there is no significance test. The two sittings' main arms differ from each other by 0.1 % and 0.8 % on the two C@4 sampled group totals, which is the spread to compare the gains against. The gains below are outside that spread.

Sitting Group Metric main MTP head MTP head off head MTP vs main head MTP vs off
a1 sampled C@2 all-active decode tok/s 43.75 44.51 45.80 +1.73% -2.82%
a1 sampled C@2 group total tok/s 26.66 27.12 27.87 +1.72% -2.71%
a1 sampled C@2 TPOT p95 ms 74.44 73.44 71.47 -1.35% +2.76%
a1 sampled C@2 TTFT p95 ms 7500.10 7343.09 7178.95 -2.09% +2.29%
a1 sampled C@4 all-active decode tok/s 59.28 62.53 63.07 +5.49% -0.85%
a1 sampled C@4 group total tok/s 26.05 26.63 27.04 +2.26% -1.49%
a1 sampled C@4 TPOT p95 ms 151.71 149.38 147.47 -1.54% +1.29%
a1 sampled C@4 TTFT p95 ms 14868.14 14526.08 14362.64 -2.30% +1.14%
a1 sampled ignore_eos C@2 all-active decode tok/s 42.72 44.17 46.57 +3.38% -5.15%
a1 sampled ignore_eos C@2 group total tok/s 26.60 27.16 28.24 +2.10% -3.82%
a1 sampled ignore_eos C@2 TPOT p95 ms 74.91 73.33 70.56 -2.10% +3.94%
a1 sampled ignore_eos C@2 TTFT p95 ms 7226.96 7255.27 7067.10 +0.39% +2.66%
a1 sampled ignore_eos C@4 all-active decode tok/s 59.13 61.74 63.42 +4.41% -2.64%
a1 sampled ignore_eos C@4 group total tok/s 26.12 26.67 27.35 +2.09% -2.49%
a1 sampled ignore_eos C@4 TPOT p95 ms 152.34 149.47 145.76 -1.88% +2.55%
a1 sampled ignore_eos C@4 TTFT p95 ms 14486.32 14507.76 14134.09 +0.15% +2.64%
a1 greedy C@2 all-active decode tok/s 68.49 67.18 47.01 -1.91% +42.90%
a1 greedy C@2 group total tok/s 33.68 33.36 28.42 -0.95% +17.38%
a1 greedy C@2 TPOT p95 ms 59.39 54.77 70.12 -7.78% -21.89%
a1 greedy C@2 TTFT p95 ms 7247.26 7260.47 7147.54 +0.18% +1.58%
a1 greedy C@4 all-active decode tok/s 72.26 70.11 64.88 -2.97% +8.07%
a1 greedy C@4 group total tok/s 27.80 27.69 27.33 -0.39% +1.30%
a1 greedy C@4 TPOT p95 ms 126.56 120.13 145.86 -5.07% -17.64%
a1 greedy C@4 TTFT p95 ms 14513.50 14493.56 14389.03 -0.14% +0.73%
a2 sampled C@2 all-active decode tok/s 44.49 44.29 45.99 -0.45% -3.69%
a2 sampled C@2 group total tok/s 27.07 27.06 28.02 -0.03% -3.45%
a2 sampled C@2 TPOT p95 ms 73.59 73.61 71.09 +0.02% +3.54%
a2 sampled C@2 TTFT p95 ms 7335.86 7343.38 7234.56 +0.10% +1.50%
a2 sampled C@4 all-active decode tok/s 58.51 62.73 64.12 +7.22% -2.17%
a2 sampled C@4 group total tok/s 26.07 26.77 27.44 +2.67% -2.45%
a2 sampled C@4 TPOT p95 ms 151.54 147.61 145.27 -2.60% +1.61%
a2 sampled C@4 TTFT p95 ms 14509.12 14575.21 14144.85 +0.46% +3.04%
a2 sampled ignore_eos C@2 all-active decode tok/s 43.16 44.49 45.88 +3.07% -3.04%
a2 sampled ignore_eos C@2 group total tok/s 26.79 27.33 28.17 +2.04% -2.97%
a2 sampled ignore_eos C@2 TPOT p95 ms 74.38 73.17 70.99 -1.63% +3.07%
a2 sampled ignore_eos C@2 TTFT p95 ms 7235.58 7215.09 7013.17 -0.28% +2.88%
a2 sampled ignore_eos C@4 all-active decode tok/s 58.38 62.12 63.75 +6.40% -2.57%
a2 sampled ignore_eos C@4 group total tok/s 25.92 26.72 27.41 +3.06% -2.53%
a2 sampled ignore_eos C@4 TPOT p95 ms 153.49 149.29 145.52 -2.73% +2.59%
a2 sampled ignore_eos C@4 TTFT p95 ms 14496.45 14527.88 14147.10 +0.22% +2.69%
a2 greedy C@2 all-active decode tok/s 68.12 68.73 46.58 +0.89% +47.57%
a2 greedy C@2 group total tok/s 34.02 33.76 28.31 -0.76% +19.26%
a2 greedy C@2 TPOT p95 ms 54.17 59.24 70.34 +9.35% -15.78%
a2 greedy C@2 TTFT p95 ms 7247.79 7243.45 7033.71 -0.06% +2.98%
a2 greedy C@4 all-active decode tok/s 70.21 69.56 65.26 -0.92% +6.60%
a2 greedy C@4 group total tok/s 27.74 27.96 27.73 +0.80% +0.83%
a2 greedy C@4 TPOT p95 ms 144.20 142.02 143.82 -1.51% -1.25%
a2 greedy C@4 TTFT p95 ms 14461.36 14485.69 14093.31 +0.17% +2.78%

Sampled C@4 all-active decode +4.41 to +7.22 % and group total +2.09 to +3.06 % over main in all four measurements of the two sittings (sampled and sampled ignore_eos); sampled C@2 -0.45 to +3.38 %; greedy and TTFT within noise. The head with MTP stays 0.85 to 5.15 % below the head with the draft off on sampled groups.

Sampled C@4 gained in every measurement. Sampled C@2 is within noise. The greedy rows and time to first token show no change beyond noise. Greedy C@2 TPOT p95 moved by -7.78 % in the first sitting and +9.35 % in the second, and greedy C@4 all-active decode read -2.97 % and -0.92 % with group totals of -0.39 % and +0.80 %. The greedy windows differ from arm to arm because the width chooser reads wall-clock costs. The change adds no work to a greedy round: its depth-zero windows now share one store walk, and its chains are unchanged.

An uneven C=4 group (one request asks for 16 ids, three ask for 128) shows the second commit. In the first sitting main ran 117 rounds of three rows as three passes, one slot at a time, once the 16-id request finished, and the head ran one. In the second sitting main ran one such round and the head none. The decode rates of that group depend on which slot finishes first, so they are not in the table.

The two sittings ran on the first commit's batched walk alone (first sitting) and on both commits (second sitting), both on main b9dfc4a7. The PR head differs from the second sitting's head in three ways: the gate code (the dedup of the two runners above), comments and docs, and one product change, copy_hidden over checked windows, which issues the same device copies as before. I did not re-measure the head after that change. The head here is both patches rebased onto upstream 648dd751: git range-diff shows both commits unchanged (=), and the 15 upstream commits between b9dfc4a7 and 648dd751 touch none of this PR's files.

Gates

just check, just gate-app, just gate-q38-serve-rules, just gate-gpu-qwen4exp-mtp, just gate-gpu-qwen4exp-e2e and just gate-gpu-glm5next-mtp ran in the fixture tier on an RTX 5090 machine, on a head before the gate dedup, copy_hidden and the final rebase. The output summaries:

$ just gate-app
test result: ok. 27 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
$ just gate-q38-serve-rules
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 227 filtered out; finished in 0.00s
test result: ok. 20 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
$ just gate-gpu-qwen4exp-mtp
clauses: 28 ran, 4 left to the real tier
gpu-gate.sh: gate_qwen4exp_mtp ran 63 s (exit 0)
$ just gate-gpu-qwen4exp-e2e
clauses: 26 ran, 8 left to the real tier
gpu-gate.sh: gate_qwen4exp_e2e ran 53 s (exit 0)
$ just gate-gpu-glm5next-mtp
gate_glm5next_mtp: clauses: 14 ran, 7 left to the real tier
gpu-gate.sh: gate_glm5next_mtp ran 12 s (exit 0)
PASS-RC check=0 app=0 q38-serve-rules=0 qwen4exp-mtp=0 qwen4exp-e2e=0 glm5next-mtp=0

just check printed no warning or error line. The (z) depth 1, depth 3, waiting, step after and plain rounds clauses all pass; the plain-rounds clause reports 3 walks that took both slots' rows and 3 passes of slot 1 alone beside slot 0's waiting rows.

After the gate dedup and copy_hidden, I ran just check, just gate-gpu-qwen4exp-mtp and just gate-gpu-qwen4exp-e2e on the GB10, which printed:

$ just gate-gpu-qwen4exp-mtp
$ just gate-gpu-qwen4exp-e2e
PASS-RC check=0 qwen4exp-mtp=0 qwen4exp-e2e=0

In that run the pass of slot 1's four rows alone holds 115 nodes against the body's 115. The clauses that need the real model (four of 28 in gate_qwen4exp_mtp, eight of 26 in gate_qwen4exp_e2e, seven of 14 in gate_glm5next_mtp) did not run here. A maintainer runs them. The server A/B above ran with the real model, and its ids were equal in every group.

FAIL first

The new (z) "plain rounds" clause fails on each defect it protects against. I applied one small change to the code at a time:

  • Appending every block to one slot's store (dropping select_slot from the append loop) makes the clause fail: "a walk from position 66: the draft's store holds this sequence's positions below 65".
  • Turning off the stand-in (stand_in && false, the old arena behavior without the fallback) makes it fail: "differs in slot 0 draft windows, slot 0 draft store".
  • Taking the stand-in term out of slots_launches makes it fail on the final head (the first two ran on the head before the gate dedup): "the pass of slot 1's 4 rows alone holds 115 nodes against the body's own 116".
(z) plain rounds: a call failed: qwen4exp Mtp38: a walk from position 66: the draft's store holds this sequence's positions below 65, and the walk would read the keys between FAIL
(z) plain rounds: 12 passes, a plain slot's waiting rows walked in one store walk of the pass's plain slots; differs in slot 0 draft windows, slot 0 draft store; 3 walks took both slots' rows, 3 passes of slot 1 alone ran beside slot 0's waiting rows, 0 walks took more than one row of a slot (printed, not pinned in this tier) FAIL
gate_qwen4exp_mtp: FAILED: one or more checks above did not pass

The three runs were on the RTX 5090 machine, and each change was reverted afterwards.

Hardware

One DGX Spark (GB10) for the A/B and for the second gate run, and an RTX 5090 machine for the first gate run and the FAIL-first runs. The nvidia-smi lines are in "GPU evidence".

What I ran into

None of this blocks the PR. A drafted sampled round still costs about 1.4 to 1.7 ms more than a round with the draft off (derived from the all-active rates of the second sitting: C@4 63.8 against 62.4 ms a round, C@2 45.2 against 43.5 ms). A sampled request beside another slot never proposes (it takes a plain step), so on these groups the draft only costs: a cheaper walk can bring drafted sampled close to the draft-off rate but not above it. The #695 rule, which keeps the unset draft off under --parallel above 1, therefore stays. The load draft=off message and the lever text are unchanged.

AI help

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

A drafted Qwen3.8 round of several slots' plain steps ran one pass of the
target rows, then walked each slot's draft over its waiting rows one
slot after another, a whole store walk a slot. Every op of a store walk
up to the append is row-local, so the walks now gather: each slot's
policy still decides its rows (`MtpDraft::gather`), and
`SlotWalks::run` walks every gathered slot's rows as one store walk
(`MtpBody::store_slots`) before the target call that may overwrite
them. Body38 stages each slot's hidden rows into its window of the
draft's arena, embeds each block at its own positions, runs the pack,
eh_proj, mix and q/k/v once over all rows, then appends each block to
its own slot's store. A body without its own `store_slots` walks the
slots in turn, as before.

The plain steps of `step_rows_drafted` and the depth-zero windows of
`pass_slots` take this path. Drafted chains stay per slot.

gate_qwen4exp_mtp's (z) plain rounds pins each slot's ids, kept rows,
draft windows and draft store against its window run alone, through
rounds whose plain slots share one store walk.
A pass of several slots walked the pass arena's final streams, which are
slot 0's own rows while the homes are canonical, even when it held no
row of slot 0. A drafted round that left slot 0 out therefore ran one
slot at a time (`round_keeps_refresh`) to keep slot 0's waiting hidden
rows. Such a pass now walks into its first slot's own final-stream rows
(`Body38::enqueue_slots`), where that slot's copy would have put them,
and launches no copy for it. Slot 0's rows stay as its last call left
them, so the round runs as one pass and `round_keeps_refresh` goes.

gate_qwen4exp_mtp's (z) plain rounds adds passes of slot 1 alone while
slot 0's draft waits on rows of the pass arena.
@github-actions github-actions Bot added documentation Improvements or additions to documentation 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 two retained findings are non-blocking; no must-fix finding remains.

Non-blocking

⚠ Observe executed batching: crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs:5685 counts PLAIN_ROUNDS entries, independent of the executed store walks. Replacing gather with immediate before_step calls preserves the comparisons and this count while restoring serial walks. Assert the executed shared-walk count, or describe the count as rounds scheduled with both slots plain. This prevents a later regression from retaining a false batching witness.

⚠ Identify the measured revisions: crates/gpu/src/arch/qwen3moe/mtp38.rs:2386 combines per-slot projection launches into a shared batch and changes row geometry. The body names base b9dfc4a7 and describes differences from this head, but omits the tested head hashes and exact A/B commands. Attach those hashes and commands with output to make the reported performance evidence attributable.

Checked

Both cited lines are added by this full-review diff. pass_slots gathers depth-zero rows before SlotWalks::run; Qwen3.8 runs shared projections before appending each block with its slot selected.

plain_rounds compares IDs, kept rows, draft windows and draft stores with standalone runs. Its separate graph-node check covers the target pass, not the draft's shared store walk.

The measurement-evidence request follows CONTRIBUTING.md. Neither item meets the kind A or kind B must-fix bar. No active ledger lessons or applicable escape-catalog patterns change their classification.

Notes

Static validation only; no build or GPU gate was run here.

Card check: needs-gpu. This pull request changes crates/app/src/arch/qwen3moe/mtp.rs, crates/app/src/mtp.rs, crates/gpu-gates/src/bin/bloomery_serve_qwen38.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 164b240 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

documentation Improvements or additions to documentation 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant