Repository navigation
gpu: Qwen3.8's verify decodes E4M3 in pairs, stages four-column MXFP8 activations and replays its commit in one launch - #884
Conversation
ByteBlocks gains values(), a word's four byte values. MXFP8 (and FP8_B128, which reads its bytes the same way) takes them from the hardware's E4M3 pair convert to f16 and the f16 widening, both exact, where the build target has it; Q8_0 and older targets keep the per-byte decode. The gemv word dot and the f32 tile's byte staging read the four values from it, so every product keeps its bits. gate_mxfp8 --bench-kernels gains the MXFP8 gemv at Qwen3.8's dense verify shapes at one to four columns.
… a block into shared memory mxfp8_gemv_mcol reads each column's activations once per row: at four columns every warp of a block loads the same 2 KB a step. The new mxfp8_gemv_mcol_staged entry loads a step's four columns once into one of two 2 KB shared stages, one thread a quad, while the warps take the previous step's dots from the other stage; one barrier a step orders the two. Each column's word dots are the one-column walk's, in the same order, so the output keeps its bits. enqueue_e4m3_gemv takes it for an MXFP8 weight at four columns when k is a multiple of 512, which every Qwen3.8 dense verify shape is. On GB10 the staged walk ran 4 to 7 % faster than the unstaged one at four columns, level at three, and 5 to 10 % slower at two, so two and three columns keep the unstaged walk. gate_mxfp8 runs attn_q_b (k = 1536) at one to four columns so the staged entry is checked bit for bit against the one-column launch, and adds 1, 7 and 9 rows at k = 512 (a last block of eight rows partly empty) and 9 rows at k = 384 (the unstaged walk at four columns), each in both output layouts.
…unch A verify's commit replays the kept rows of each delta layer's records into its committed lane: 36 gdn_delta_recovery launches a window on Qwen3.8, each a small grid of 8 blocks a value head, back to back. The new gdn_delta_recovery_layers entry runs all of them in one launch: block b is block b - s·per of store s's replay, where a RecoveryTable built once per sequence holds each store's state, stamps and carry addresses and its layer. The replay reads no qkv, beta or decay and writes no o, so the stores share nothing; each block runs delta_lanes_body as the per-layer launch does, now told its block index, and raises its faults under its own store's layer through FaultSink::at_layer. Body38 builds a table for the live sequence's stores and one for each parked sequence's, and the exchange that swaps the stores swaps the table with them; resident_bytes and seq_bytes count each table's four device words a store. RecoveryTable::new refuses a store whose state or stamp bytes overlap another state's, stamp's or carry's, so each store's state and stamps have one writer in the launch. gate_linear checks the one launch against the per-store replays bit for bit on three stores (one without a carry), at every kept count, eager and captured, and with a stamp planted wrong in one store, which must raise that store's fault under its layer, and the refusals of overlapping state, stamp and carry ranges (windows at different addresses included) and of kept counts of 0 and lanes + 1; --case recovery also times 32 stores both ways. The Qwen3.8 slots harnesses derive a sequence's bytes with the table's term.
There was a problem hiding this comment.
Verdict: CLEAN: I built no failure path that survives the code; the replay table, the staged walk and the planner terms hold on every input I tried.
Non-blocking
⚠ Timed head and final head differ: the PR body says the A/B ran on 92d2624a, the PTX spill scan on 4d3bdd78, lint on 03045c5b; the final head is b8ce8b95. The body says the kernel bodies are unchanged, but sm_121a was not scanned again, and the cargo fmt/clippy checklist item is unchecked. Run just gate-ptx-spill at sm_121a and just lint on the final head before merge; the two new PIN lines rest on the earlier scan.
⚠ Row width is written twice in the replay kernel: delta.rs:1114 says table.len() >= 4 * n_stores, while the body reads RECOVERY_ROW * s with get_unchecked. If DELTA_REPLAY_WORDS changes, the contract no longer proves the unchecked read, and let &[..] = row else { return } makes the mismatch a silent no-op. Write RECOVERY_ROW * n_stores if the macro accepts a const path; otherwise add const _: () = assert!(RECOVERY_ROW == 4); beside the kernel.
⚠ Comment carries a measurement without conditions: q8f32.rs:1423 says the unstaged walk "is as fast there on GB10". Keep the invariant only: "Fewer columns keep [blocks_lane_partials_mcol]'s walk."
Checked
- Duplicates: about 12 new items checked; none duplicated. dryer found 0 pairs but did not search
crates/gpu; I compared the staged walk withblocks_lane_partials_mcolby hand. They share helpers and differ in staging. - Complexity:
RecoveryTable::new17 andenqueue_delta_recovery_layers18 are new functions, complex on their own: load-time validation, one check per named refusal.enqueue_e4m3_gemv21 to 26 is one match arm. Kernel bodies are complex by design. - Silent failure: 8 sites followed. Two build.rs
unwrap_or_defaultgive the bit-identical per-byte decode. Twoelse { return }in the replay kernel are unreachable behindRecoveryTable::new. - Adversarial: overlapping stores, a lane word inside a written range,
exchangewith a stale table, barriers in the staged walk, and an unalignedxorkare all blocked. - Tests: the PR body shows each new clause failing against a planted mutant. I did not re-run them.
- Gates: new PINs are dated with reasons; the
mxfp8_w8a8_norm_gatemove is a decrease with the cause named. - Performance: the commit goes from 36 launches to 1 per window; the table is uploaded once per sequence. The staged walk adds one barrier per 128-value step at four columns. Decode +3.383%, +2.617%, +1.883% on GB10, earlier head.
- Escape catalog: no pattern matched.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_linear.rs, crates/gpu-gates/src/bin/gate_mxfp8.rs, crates/gpu-gates/src/bin/gate_qwen38_twocard.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)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 FP4-Local MTP의 verify와 commit 경로에서 MXFP8 곱셈, 활성값 읽기, 델타 상태 복구 launch를 줄여 DGX Spark의 MTP 디코드 속도를 높이는 속도 PR입니다.
What and why
A Qwen3.8 MTP verify window runs MXFP8 gemvs at two to four columns, and its commit replays the kept rows of every delta layer. This PR changes three things on that path. The outputs keep their bits.
ByteBlocks::valuesincrates/gpu/src/q8f32.rsis now the one owner of a word's four values. MXFP8 and FP8_B128 take them fromcvt.rn.f16x2.e4m3x2and an f16 widening, both exact. Q8_0 and older targets keep the per-byte decode. The gemv word dot and the f32 tile's byte staging read their values from it.crates/gpu/build.rssetsbloomery_e4m3_cvtfrom the build target.mxfp8_gemv_mcol_stagedentry takes over for an MXFP8 weight at four columns whenkis a multiple of 512 and the activation base address is 16-byte aligned. Any other call, including one on an activation window at an unaligned offset, uses the existingmxfp8_gemv_mcol. Two and three columns keep the unstaged walk, which measured faster there. Each column's word dots run in the one-column walk's order.gdn_delta_recovery_layersentry (crates/gpu/src/linear/delta.rs) replaces the 36gdn_delta_recoverylaunches of a window. ARecoveryTablebuilt once per sequence holds each store's state, stamps, carry and layer. Each block runsdelta_lanes_bodyas the per-layer launch does, and raises its faults under its own store's layer throughFaultSink::at_layer.RecoveryTable::newcompares byte ranges: it refuses a store whose state or stamp overlaps another store's state, stamp or carry, or its own state, so every store has one writer in the launch. Stores may share a carry, which the launch only reads. The launcher also refuses a lane word that lies inside any store's state or stamp, since the lanes are read while those ranges are written.The table is card memory, and the planners count it.
DELTA_REPLAY_BYTESincrates/runtime/src/stores.rsis the size of one table row.Body38counts its tables inresident_bytesandseq_bytes.PlanInputs::seq_termsadds one row per delta layer to a sequence's card bytes, which the single-slot, multi-slot and MTP plans all read, and the fixed two-card plan'sBESIDEadds the 36 rows. The saved host state does not hold the table, so its size is unchanged.Greedy output is identical on every request of the timed run.
Release notes: Changed: Qwen3.8 MTP verify and commit run faster on a DGX Spark, with unchanged output.
Code shape
ByteBlocks::valuesis the one owner of a word's four values (the per-bytevaluestays its default). The staged walk reusesblock_code,word_dot,gemv_lane_sums,store_sumsandas_vectors. The replay launch reusesdelta_lanes_bodywith a block index instead of a second replay body. The size of a table row is one constant that the GPU table, the model planner and the card planner all read.Body38only builds and swaps the replay tables for its stores and counts their bytes. The planner term is the descriptorSeqTermsthe planners already share.RecoveryTable::newand the launcher refuse by name: no store, fewer than three lanes, a short state, stamp or carry, a misaligned state or carry, a layer at or pastLAYER_HEAD, any overlap of a written range with another range, a lane word inside a written range, and a lane index past its buffer. A fault in the replay is named under its own layer.PIN(2026-10-27)and the reason:mxfp8_gemv_mcol_stagedandgdn_delta_recovery_layersare new entries pinned at 0 spill and 0 JIT local bytes,mxfp8_w8a8_norm_gateis measured lower (364 to 340 spill bytes, JIT local 72 to 64), and the unsafe counts forgpu(2749 to 2764 blocks, 350 to 353 fns) andgpu-gates(106 to 109 blocks) cover the new code, each block with its SAFETY line.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up. Both lint runs below passed on an earlier head of these patches, and the finished head was not linted again.Duplication found or removed (
path:line): none.What I ran
Each line says which commit it ran on. The final head is
b8ce8b95146ce70d56b0331800b5e5d9467e4235on upstream main08047d8b5422432dccb31f9b77f8e00d3892981c. The runs below name the earlier headb56a2471f54bbff4cba6baa4190183986128fa67where they ran on it.git range-diffshows every commit of this PR equal, and the upstream commits in between touch no file this PR changes. The one difference is a single line inlabs/hip-native/Cargo.lockfor the newbloomery-runtimedependency ofbloomery-placement, which the locked build of that lab needs. No source changed.Cards:
On the GB10 (sm_121a):
gate-gpu-linearonb56a2471f54bbff4cba6baa4190183986128fa67: 164 clauses, 0 failed.--case recoveryexits 0. It includes the replay-table clause (one launch over three stores against each store's own replay, every kept count, eager and captured, and a stamp planted wrong in one store) and the refusal lines: seven overlaps of a written range, four lane words (inside a stamp, inside a state, at the last stamp, past the buffer), two accepted layouts (stamps that abut, stores that share a carry), and kept counts of 0 and lanes + 1.gate-gpu-mxfp8on03045c5b9ba23ed9a2e6f9e744c3c24e602be694: PASSLINES mxfp8 468 FAILLINES 0. It covers the tail shapes of 1, 7 and 9 rows at k 512 and 9 rows at k 384, and every gemv case again with the activations shifted by one f32 off a 16-byte boundary: X_OFF4 head pass=96 fail=0.gate-gpu-qwen4exp-e2eonb56a2471f54bbff4cba6baa4190183986128fa67, with a fixture made fromQwen3.8-Flash-Next-UD-Q4_K_XLand itsmtp-Qwen3.8-Flash-Next-shared-Q8_0.ggufdraft (fixture SHA-256d5e99a1f6b4e040ec75d41b3f6764cdcf4b1bc426f225ba4ab4bafb6c096cd62for the target andbfd72ccdba0f98775dbc4956d4d3b2e8b3c505e1d6fb2b03036bac7e7c0c3262for the draft): the gate exits 0 with 26 clauses run and 8 left to the real tier, which this run did not cover. Its slot-plan line and itsslots H3line both PASS: one added sequence growsresident_bytesandseq_bytesby 42675588 bytes, the same as the sum derived from the header shapes, including the 64-byte replay table.gate-gpu-qwen4exp-mtpon4d3bdd78: exit 0. It ran before the later changes toRecoveryTable::newand the planners and was not run again.gate-ptx-spillon4d3bdd78at sm_121a, sm_121 and sm_86: violations 0 PASS on every table. At sm_121a,mxfp8_gemv_mcol_stagedhas 52 registers, 4096 B of shared memory, 0 spill and 0 JIT local.gdn_delta_recovery_layershas 80 registers, 0 spill and 0 JIT local. The scan was not repeated after the replay kernel lost its position argument.ptx-compareat sm_86 against main on76dcfadbexits 3, as expected: added 2 (gdn_delta_recovery_layers,mxfp8_gemv_mcol_staged), removed none, changed 21. Of the 21, onlyfp8_b128_gemvchanged a resource column (registers 38 to 37, JIT registers 39 to 40). The others changed only their md5, because the new word decode is inlined into every walker that reads a byte block.ptx-compareat sm_86 from14dcdf9ctob56a2471is identical: 470 entries on each side, added none, removed none, changed none. The last commit of this PR changes no kernel at sm_86. It was not run at sm_121a.gate-gpu-linear --case recoveryfails on five lines: the lane words inside a stamp, inside a state and at the last stamp are accepted, and the two replay clauses with a planted fault report no fault. With the staged-walk guard and byte-range check of03045c5bat thed6adc635code, the same case fails 7 lines (PASSLINES recovery-old 66 FAILLINES 7), andgate-gpu-mxfp8fails 12 (X_OFF4 old pass=84 fail=12): the staged shapes leave the output untouched when the activations are not 16-byte aligned.03045c5b, the e2e gate fails its oneslots H3line and nothing else (PASSLINES e2e-old 172 FAILLINES 1).On the RTX 5090 (sm_86, default x86 build), all on
b56a2471f54bbff4cba6baa4190183986128fa67except the MXFP8 gate:just check(cargo check --workspace --all-targets):ALL-TARGETS rc=0.gate-gpu-linear: 164 clauses, 0 failed.slot_plans_count_every_term_per_slot: 1 passed, 0 failed. It asserts that a sequence'sbesidebytes are the old terms plus 96 B. The placement testsqwen38_cards: 28 passed, 0 failed.gate-gpu-mxfp8on03045c5b9ba23ed9a2e6f9e744c3c24e602be694: PASSLINES mxfp8 444 FAILLINES 0, with X_OFF4 pass=96 fail=0.Lint on
03045c5b(an earlier commit): the clippy lint run exited 0, andcontrib-check --tier t0ended with DONE tier=t0 total=34 red=0.Each new or changed gate clause was made to fail first by breaking the code it covers, and passes again after the file was restored:
gate-gpu-mxfp8:gemv.bits ... m=4 equal=0/65536 FAIL, 4 FAIL linesgate-gpu-linear: 17 FAIL linesgate-gpu-linear: 9 FAIL lines, fault layer 65535 for the planted layer 7slot_plans_count_every_term_per_sloton the RTX 5090:left: 368644,right: 368740Not run:
gate_qwen38_twocard, whose changed lines are a derived-value term, a doc line and the table's size; they compile injust check. The other gatesjust affectedselects are not run either. A maintainer runs those on the workstation.Speed
The timed model is
nvidia/Qwen3.8-Flash-Next-FP4-Localat revisionb9ce18a6887e18c089fdea8509a33e63429a3300, with the Q8_0 MTP draft filemtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf(SHA-2565ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6) for the draft-on arms. Each run uses a 4096-id prompt and 128 greedy tokens, on eight corpus windows 50,000 ids apart, with three rounds after a lead-in. Base is upstream maind4af82e5a901048f237a17804311bbd7935c6d01. The head timed is92d2624a85c71abb4845ef0b7e20e9484269133d. Base and head are built from their own trees and run alternately. Each cell is the median of three rounds. A positive change means head is better, which for TTFT means lower.Ranges are "separate" when the three head rounds and the three main rounds do not overlap.
draft-on decode +3.383% (code-fn) and +2.617% (prose-en) and draft-off decode +1.883% (code-fn), above the 1.476%, 0.964% and 1.492% the run can resolve; the other rows are inside the spread of repeated runs of the same tree
Only the three decode changes are resolved. The other rows are inside the spread of repeated runs of the same tree, so they are not evidence of an effect or of none.
The head timed is not this PR's head, and the A/B was not repeated on it. The later commits change the staged walk's alignment condition, the byte-range check in
RecoveryTable::new, the lane-word check, the removed position argument of the replay kernel, the table's byte accounting in the load-time plans, and the gate shapes. The kernel bodies are unchanged, and the sm_86 PTX of the last commit is identical to its parent's. The host side checks the staged walk's alignment and the lane word's address, and no longer looks up a position for each replay.Reproduction
Build the head the same way. Send 4096-id prompts from eight windows of the same corpus with 128 greedy tokens (temperature 0), alternating the two trees, and compare the median server decode rate. For the draft-off arm set
BLOOMERY_DRAFT=offand leave outBLOOMERY_MTP_DRAFTandBLOOMERY_MTP_WIDTH.Hardware
The GB10 is a DGX Spark. The timed runs and the sm_121a gates ran on it, and the sm_86 gates and
just checkran on the RTX 5090 whose card lines are above. A number from one card is not mixed with the other.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.