Skip to content

qwen38: a drafted load runs a round of several slots' plain steps as one pass - #703

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sampled-pass
Oct 23, 2026
Merged

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sampled-pass

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

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

Part of #565. Fixes the Low item in #699.

What and why

With BLOOMERY_DRAFT=mtp, a round in which several slots take a plain step (a sampled request, or one that bans token ids) ran one pass per slot. A load without a draft already runs the same round as one pass of all busy rows. This PR gives the drafted load the same pass: step_rows_drafted selects each row's slot, lets that slot's draft walk the rows it left waiting, runs one step_rows_one_pass, and then tells each slot's draft the row's answer as its next refresh.

On one DGX Spark (GB10) with nvidia/Qwen3.8-Flash-Next-FP4-Local, bloomery-serve --parallel 4 and BLOOMERY_DRAFT=mtp, four sampled requests decode at 55.80 tok/s over their all-active window where main decodes 28.29 tok/s (+97.28%), and two sampled requests at 41.77 tok/s where main decodes 28.07 tok/s (+48.84%). Every request returns the same ids as on main in every group. Greedy requests take drafted passes, which this PR changes only in the order of passes in a round of more than eight rows.

  • crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs: step_pass no longer excludes a load that drafts with MTP, and the seat's step_slots calls rounds::step_rows_drafted for such a load. A lookup load keeps its per-slot fallback.
  • crates/gpu-gates/src/bin/shared/serve_seats/rounds.rs: step_rows_drafted loops over whatever rows the round holds, so the row count stays data.
  • crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs: before_row is the pre-step half of step_reading, which now calls it, so one function owns the order. after_row gives the draft the row through passed_plain.
  • crates/app/src/mtp.rs: MtpDraft::passed_plain is the one owner of "a plain row ran in a pass of several slots". The depth-0 window in pass_slots calls it too, because a depth-0 window is one row and records the same refresh. The row's hidden state is the pass arena's, where Body38::plan_slots already lays the rows of step_slots.
  • crates/app/src/lib.rs: round_passes cuts a round's entries into passes of at most SlotRows::MAX_ROWS rows and runs the pass that holds slot 0 last (see "A defect that was already there" below). Session::step_slots_rounds runs the passes in that order and puts each pass's ids and logits rows at the round's own row positions, so a caller sees its rows in the order it gave them. An entry of no row, an entry of more rows than a pass holds, and a pass that answers another count of ids than its rows are each refused by name.
  • crates/app/src/mtp.rs: pass_slots takes the whole round, makes every window's proposal before the first pass, and cuts the passes with round_passes from the rows the proposals actually hold. It returns the commits and the number of passes, so the signature of this pub fn changes; the two callers in gate_qwen4exp_mtp.rs and gate_glm5next_mtp.rs ignore the count.
  • crates/gpu-gates/src/bin/shared/serve_seats/rounds.rs: pass_rows_one_pass calls pass_slots once and no longer lays windows out with a loop of its own.
  • crates/levers/src/lib.rs, crates/levers/src/registry.rs, docs/serving.md and the seat's docs: the reason the unset draft rule gives is updated to what is still true (see "The qwen38: keep the unset MTP draft off under --parallel above 1 #695 rule" below).
  • crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs: round_keeps_refresh is the one rule for when a step or verify call may take the shared pass (see "A defect that was already there"). step_slots and pass_slots both ask it.
  • crates/gpu-gates/src/bin/gate_qwen38_serve.rs: the new gate clauses described under "What I ran". sampled_pair is the one body of the plain arm's sampled rounds clause and the drafted one. ids_as_alone is the one comparison of a together run's ids with the same requests run alone, used by the slots clauses, the late pair and sampled_pair.

A defect that was already there

A pass of several slots writes its rows into the pass arena that slot 0's live sequence also reads its hidden rows from, whether or not the pass holds slot 0. A parked slot's rows are copied out to its own buffer; slot 0's are not. When a round takes more than one pass and slot 0's pass is not the last, the next walk of slot 0's draft reads another slot's hidden row, and nothing reports it.

The new step path meets this with nine slots, where a round of plain rows takes two passes of at most eight rows. The drafted greedy path in pass_rows_one_pass had the same defect before this PR: it laid windows out in slot order, slot 0's first, so a round whose windows hold more than eight rows (a fixed window width of 3 with three or more slots) ran slot 0's pass first, and a later pass overwrote its rows. round_passes fixes both paths with one order. Moving slot 0's pass last is not enough for the windows, because an earlier pass would then overwrite the waiting rows that slot 0's draft walks when it proposes. So pass_slots makes every proposal before the first pass.

The same arena is shared between calls, not only between the passes of one call. A pass that holds no slot 0 overwrites the rows slot 0's draft still has waiting, and nothing moves slot 0's position or its pending refresh. A sampled step of slots 1 and 2 ahead of a greedy verify (or the reverse) would therefore change slot 0's next proposal and its acceptance. round_keeps_refresh closes this at both entries, step_slots and pass_slots: a group takes the batched pass when it holds slot 0, when the load has no MTP draft, or when slot 0's draft is off. Any other group runs each slot in turn, which leaves slot 0's buffers alone. The sampled C@2 and C@4 groups measured below hold slot 0, so they stay on the batched pass; only a partial round that leaves out slot 0 steps per slot. docs/serving.md says the same in its concurrent-request paragraph.

Rounds of at most eight rows are one pass, so the 2-slot and 4-slot rounds measured below run the same calls as before.

The second commit, gate_qwen38_serve: one owner joins a streamed request's thread, is a cleanup inside that gate. The slots clauses' together runs, the default server's pair, the late pair, the off slot's drafted request, run_streamed and run_sampled each had their own copy of the loop that joins a streamed request's thread, receives its answer and prints it. They now call answers, and answer is its one-request form, so run_streamed and run_sampled are gone. The file loses 98 lines and gains 39. The lookup cost clause keeps its own loop, because a failed request there ends the gate with an error instead of turning a check red.

Rounds that mix a drafted slot with a stepping slot still make two target calls, one for the steps and one for the windows. Folding the steps into the verify pass needs verify_slots to return each plain row's logits. That is not part of this PR.

Release notes: Changed: a Qwen3.8 load with the MTP draft runs a round of sampled or id-banning requests from several slots as one pass, which roughly doubles sampled decode throughput at four concurrent requests on a DGX Spark.

Code shape

  • No second copy. passed_plain replaces the inline refresh record in pass_slots, before_row is moved out of step_reading and called from both paths, sampled_pair serves both sampled rounds clauses, and answers replaces the copied join loops in the gate.
  • Model code holds only architecture facts. The new pass runs through MtpBody and SlotRows, so a model supplies no new branch, flag or method for it.
  • Dead code is gone. run_streamed and run_sampled are removed in the second commit. Nothing else is left unused.
  • No silent failure. The draft refuses a proposal that has no refresh before it, by name, and a failed request in answers is a printed failure and a red check.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or pin moved, and no gate was removed. The plain arm's slots_sampled_rounds_run_one_pass and slots_sampled_together_alone keep their names and checks.
  • cargo fmt and cargo clippy are clean on what I touched.

Duplication found or removed: the join loops in gate_qwen38_serve.rs (second commit), and the sampled pair clause shared between the plain arm and the drafted one.

What I ran

Throughput A/B

One GB10 in a CUDA 13.3.1 container. Main (78c3680d) and the head were built in their own targets with cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features glm5next,clef,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve. Each arm loaded the server once with bloomery-serve -m <folder> --parallel 4 --ctx-size 16896, BLOOMERY_DRAFT=mtp and BLOOMERY_HOST_ROOM=96G, and the arms ran back to back in one sitting with the GPU clock cap lifted for each arm and restored after it. Every request has a 4096-id prompt from a code corpus and generates 128 ids with the prompt cache off. Greedy groups use temperature 0. Sampled groups use temperature 0.7, top-p 0.8, top-k 20 and seed 20261023 plus the request index. All-active decode counts the tokens that all requests emit while all of them decode.

Each arm ran each group once, so these are single observations, not a significance test.

Group and metric Main Head Change
C@4 sampled, all-active decode tok/s 28.29 55.80 +97.28%
C@4 sampled, group total tok/s 10.42 12.66 +21.57%
C@4 sampled, TPOT p95 ms 380.71 315.47 -17.14%
C@2 sampled, all-active decode tok/s 28.07 41.77 +48.84%
C@2 sampled, group total tok/s 13.11 15.60 +18.98%
C@2 sampled, TPOT p95 ms 152.19 127.69 -16.10%
C@4 greedy, all-active decode tok/s 68.13 65.40 -4.01%
C@4 greedy, group total tok/s 13.11 13.07 -0.30%
C@4 greedy, TPOT p95 ms 275.45 298.45 +8.35%
C@2 greedy, all-active decode tok/s 60.97 61.19 +0.36%
C@2 greedy, group total tok/s 17.04 17.32 +1.65%
C@2 greedy, TPOT p95 ms 117.38 115.48 -1.62%

C@4 sampled all-active decode under BLOOMERY_DRAFT=mtp rose from 28.29 to 55.80 tok/s (+97.28%) and C@2 from 28.07 to 41.77 tok/s (+48.84%), with the same ids as main; the greedy groups take drafted passes, a path the change leaves as it is.

C@2 sampled with banned ids went from 28.31 to 42.20 tok/s (+49.08%). Each server's own slots round records show the change: main ran its plain rounds a slot at a time (cmd=step rows=2 passes=2 263 times and rows=4 passes=4 123 times), and the head ran them as one pass (rows=2 passes=1 267 times and rows=4 passes=1 126 times). The drafted rounds are nearly the same on both.

The greedy C@4 all-active decode is 4.01% lower on the head, and I have one observation of it. Greedy requests that ban no id take drafted passes, so they never reach step_rows_drafted. The four-request window is 4.1 to 4.4 s long, the cost chooser's draft counts follow its clock, and the group total moved by -0.30%.

The A/B ran on 7122ac48, which is the change on top of main 78c3680d; this head differs from it. The head adds comments, docs, the unset rule's message text, the gate changes, round_passes and round_keeps_refresh. The measured sampled rounds hold at most four rows, so they are one pass, and round_passes leaves a one-pass round as it was. Every measured round holds slot 0, so round_keeps_refresh chooses the same batched pass for it. I carried the measurement to this head and did not rerun it.

Correctness

The ids are equal on every pair of arms (main with the draft, head with the draft, head without it) in the greedy, sampled and sampled id-banning groups, and in a pair of two sampled requests of 16 and 128 ids. In that pair the long request drafts 95 proposals and keeps 78 on the head, against 97 and 82 on main, with the same ids. A sampled request that steps beside a short one and then drafts alone depends on after_row, and the gate clause below covers it.

With nine slots a round takes more than one pass. On one GB10 I served the same model with bloomery-serve --parallel 9 --ctx-size 9216, BLOOMERY_DRAFT=mtp and a fixed window, and ran nine greedy requests of 48 ids and nine sampled requests of 48 ids (end ids banned), each set alone and then together. All eighteen requests return the same ids together as alone, and the greedy ones the same proposed and accepted counts (request 0: 51 and 31 both ways). The server's slots round records show the cuts: the sampled rounds are cmd=step rows=9 passes=2 (46 rounds), and the drafted greedy rounds are cmd=pass rows=9 passes=5 (17 rounds). A slot 0 draft that walked another slot's row would change its proposals and accepts, so the equal counts cover the order for the drafted path. Slot 0's order on the step path is covered by the host test below, because a sampled request drafts nothing.

The change adds no kernel and no graph. A drafted load's round now makes the same step_slots call a plain load makes, so the Pass38 and Verify38 launches are the ones that already exist.

The #695 rule

The unset draft stays off under --parallel above 1. On the same head, a sampled load with the draft is still slower than the same load without it, and a greedy load gains only at C@2.

Same head, draft off to draft on Draft off Draft on Change
C@2 sampled, all-active decode tok/s 45.07 41.77 -7.31%
C@4 sampled, all-active decode tok/s 62.74 55.80 -11.05%
C@2 greedy, all-active decode tok/s 46.30 61.19 +32.14%
C@4 greedy, all-active decode tok/s 64.51 65.40 +1.38%

A request without a temperature is sampled, so turning the unset draft on would trade the default request's throughput for greedy's. What is left is the draft's own walk: before_row walks each slot's draft over its waiting row, one slot after another, before the shared pass. The rule is unchanged, and its stated reason in the lever text, the registry and docs/serving.md now says this.

Gate clauses

gate_qwen38_serve's slots server (BLOOMERY_DRAFT=mtp, a fixed window, --parallel 2, BLOOMERY_STEP_STATS=1) gains three clauses after slots_drafted_beside:

  • slots_drafted_sampled_rounds_run_one_pass: a sampled pair banning the end ids, run alone and together, where every slots round record of the together run is cmd=step, rows=2, passes=1, slots=2. It protects step_pass and step_rows_drafted.
  • slots_drafted_sampled_together_alone: the pair's ids together equal its ids alone, so each row's answer goes back to its own request.
  • slots_drafted_sampled_tail_drafts: a sampled request of 96 ids beside one of 8 drafts alone after the short one ends, and its proposals per id past the short one's 8 are at least half of its alone run's. It protects after_row. The clause is refused by name unless the short request answered all 8 ids and a slots round record of that run is cmd=step, rows=2, passes=1, because the tail checks hold only for a long request whose rows rode a pass beside the short one.

I could not run this gate. just gate-gpu-qwen38-serve on an RTX 5090 machine built its binaries and was refused by tools/gpu-gate.sh, because the gate runs on the RTX 3090 only and its paged clause needs that card's plan. The new clauses compile, and the compile is part of the cargo check run below. A maintainer runs the gate on the 3090.

$ just gate-gpu-qwen38-serve
gpu-gate.sh: gate_qwen38_serve runs on the 3090 only
error: recipe `gate-gpu-qwen38-serve` failed on line 2651 with exit code 64

To show that the clauses can fail, I checked the same predicates on the real server. Main's server keeps step_pass false under the draft, and the same pair's rounds print passes=2 where the clause asserts passes=1. With after_row told nothing on the head, the pair of 16 and 128 sampled ids steps beside the short request as one pass and then the long request's first drafted pass is refused:

engine: sampled pass at position 4112: MTP window: a proposal before the draft's refresh (its prompt call, or the accept before it)

On the unmodified head the same pair completes, drafting 95 and keeping 78.

Host checks

On an RTX 5090 machine at this head: the check recipe's cargo check --workspace --all-targets command exits 0, bash tools/gate.sh --oxide -p bloomery-app --release --lib reports 27 passed, the gate-q38-serve-rules recipe reports 3 and 20 passed, and the gate-serve-draft-rules recipe reports 6 and 5 passed.

The new test round_passes_keep_each_drafts_hidden_rows models the pass arena (every pass writes its rows from row 0 of the live arena, and parked slots' rows are copied to their own buffers) and checks that each slot's draft walks its own slot's rows after nine sampled slots' plain rows at eight rows a pass, three drafted windows of four rows, a round without slot 0 and a round of one pass. It also checks the named refusals of an entry of no row and of nine rows. To show the test can fail, I turned off the move of slot 0's pass to the end, and the test fails:

test tests::round_passes_keep_each_drafts_hidden_rows ... FAILED
slot 0's draft walks rows of slots [8] after [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1)]

The test mixed_rounds_keep_slot_zeros_proposals_and_acceptance models the live pass arena, the parked slots' own buffers and the row-count metadata. It runs three pairs of a sampled step and a greedy verify over three and four slots, and compares each slot's proposal rows and acceptance with the same calls run alone. It also checks that groups holding slot 0, a load without MTP and a load with slot 0's draft off keep the batched pass. With the guard turned off (every group batched), the test fails: slot 0's proposals become [1,1,1,1,3,3] where alone they are [1,1,1,1,1,1], and its acceptance is 4 where alone it is 6. With the guard restored, the seat's host rules report 21 passed, 0 failed. This commit touches only the seat, this test and docs/serving.md, so the app and draft-rule results below are from the commit before it.

The commands of the gate-q38-serve-rules and gate-serve-draft-rules recipes, run directly, print:

test result: ok. 27 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 225 filtered out; finished in 0.00s
test result: ok. 20 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
PASS-RC mutant=101 app=0 rules=0 draft-rules=0 check=0

Hardware

One DGX Spark (GB10, compute capability 12.1) in the CUDA 13.3.1 container used for the A/B. The card was idle before each arm and the CPU load was under 1 for 30 seconds. The nine-slot run used a second GB10 of the same driver and CUDA version.

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

What I ran into

None of this blocks the PR. The greedy figures in the A/B were measured before pass_slots began cutting its passes by the rows the proposals hold, which can only lower a drafted round's pass count, and I did not remeasure them. The new gate clauses did not run on the RTX 3090, as described above. The greedy C@4 difference of -4.01% is a single observation on a path whose measured rounds the PR does not change.

AI help

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

…one pass

A drafted load stepped a round of sampled or id-banning requests a slot
at a time, each step told to its slot's draft. The round now runs as one
pass of the busy rows, as a plain load's does, each row told to its
slot's draft around the pass: the rows its draft left waiting walked
before it, and the row's answer recorded after it as the next refresh,
its hidden row the pass's.

On a --parallel 4 server of Qwen3.8-Flash-Next-FP4-Local on a GB10 under
BLOOMERY_DRAFT=mtp, four sampled 4096-id requests decoded at 55.8 tok/s
over their all-active window against 28.3, and two at 41.8 against
28.1, with the same ids; greedy requests are unchanged.

The unset draft stays off under --parallel above 1: the drafted round
still walks each slot's draft over its row, one slot after another, and
the same sampled rounds ran at 62.7 and 45.1 tok/s on the plain load.
The reason the rule names is updated.

gate_qwen38_serve's slots server holds it: a sampled pair banning the
end ids steps in rounds of one pass of both slots with its alone ids,
and a sampled request that steps beside a short one then drafts alone
from the state its rows left. The plain arm's sampled rounds clause
shares the pair's code.
The slots clauses' together runs, the late pair, the off slot's drafted
request, run_streamed and run_sampled joined each streamed request's
thread and took its answer in their own copies of the same loop; they
now take it from answers, and one answer posts no request of its own,
so run_streamed and run_sampled are gone.
The drafted sampled tail kept the long request's answer and dropped the
short one's, so a short request that failed, or one that never shared a
round, left the long request drafting alone, and both tail checks could
pass without a row of the long request told to its draft from a pass.
The clause now refuses by name unless the short request answered its
eight ids and a slots round record of the tail run is one step pass of
both rows.

ids_as_alone takes the alone answers as an iterator, so the slots
clause's ids check and the late pair's go through it with the sampled
pair's.
A pass of several slots writes the pass arena the live sequence, slot
0's, reads its hidden rows from, whether the pass holds slot 0 or not;
only a parked slot's rows are copied out to its own buffer. A round cut
into more than one pass ran the pass that holds slot 0 first, so the
passes after it overwrote the rows slot 0's draft walks next: a drafted
round of nine sampled slots fed slot 8's hidden row into slot 0's MTP
store, and a greedy round of drafted windows past the pass bound fed
another slot's rows into slot 0's refresh.

round_passes cuts a round between entries at the body's bound and puts
the pass that holds slot 0 last. Session::step_slots_rounds runs its
passes in that order, each pass's ids and logits rows at its rows of the
round. pass_slots now takes the whole round: every window's proposal is
made before any pass, so no pass overwrites the rows a draft walks
before its own, then the windows run in round_passes' passes, cut by
their proposals' rows, and it returns the passes it ran with each
window's commit.
@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: No must-fix defect survives the source review.

Non-blocking

⚠ Verify the final dispatch path: crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs:2830.
The owning gate was refused with exit 64, and the A/B predates the final pass planner and refresh guard.
Run just gate-gpu-qwen38-serve on an RTX 3090 and a base/current-head A/B, including mixed and multi-pass rounds. These runs verify the implementation being merged.

Optimization headroom

Checked

Duplicates: 16 new items checked; no duplicated owner found. Dryer reported 0 pairs; gpu-gates was excluded and checked by Grep.
Complexity: pass_slots 19→21 adds a pass loop using the shared planner. slots_drafted_sampled is new at 17: pair exercise, tail prerequisites, assertions; sampled_pair already owns the reusable stage.
Silent failure: 4 error-sensitive branches followed. Request errors turn checks red; absent drafts are intentional; missing round drafts are refused before execution.
Tests, static mutation audit: removing the slot-0 move at crates/app/src/lib.rs:786 fails the planner test. Forcing the guard true at crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs:2579 fails the mixed-round test.
Sampled clauses: disabling step_pass fails the pass-count assertion; swapping row answers fails together/alone; dropping after_row fails the drafting tail; forcing zero acceptance fails its acceptance assertion. The extracted plain sampled clauses retain their assertions.
Gates: no existing threshold, case, or pin was relaxed or removed. FAIL-first evidence describes the planner, refresh guard, batching, and refresh-record mutants.
Escape catalog: C1–C4 do not match the changed code.

Notes

Source review only; no build or hardware test was run here. The PR supplies no successful owning GPU gate run.

Card check: needs-gpu. This pull request changes crates/app/src/lib.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 a83dd0d 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