Skip to content

gpu: Qwen3.8's verify decodes E4M3 in pairs, stages four-column MXFP8 activations and replays its commit in one launch - #884

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-r1m1-verify
Oct 27, 2026
Merged

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-r1m1-verify

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

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.

  • An E4M3 word decodes two bytes per convert on sm_89 and later. ByteBlocks::values in crates/gpu/src/q8f32.rs is now the one owner of a word's four values. MXFP8 and FP8_B128 take them from cvt.rn.f16x2.e4m3x2 and 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.rs sets bloomery_e4m3_cvt from the build target.
  • A four-column MXFP8 gemv loads each step's activations once per block into shared memory. The new mxfp8_gemv_mcol_staged entry takes over for an MXFP8 weight at four columns when k is 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 existing mxfp8_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.
  • The commit replays all delta layers in one launch. The new gdn_delta_recovery_layers entry (crates/gpu/src/linear/delta.rs) replaces the 36 gdn_delta_recovery launches of a window. A RecoveryTable built once per sequence holds each store's state, stamps, carry and layer. Each block runs delta_lanes_body as the per-layer launch does, and raises its faults under its own store's layer through FaultSink::at_layer. RecoveryTable::new compares 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_BYTES in crates/runtime/src/stores.rs is the size of one table row. Body38 counts its tables in resident_bytes and seq_bytes. PlanInputs::seq_terms adds 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's BESIDE adds 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

  • No second copy. ByteBlocks::values is the one owner of a word's four values (the per-byte value stays its default). The staged walk reuses block_code, word_dot, gemv_lane_sums, store_sums and as_vectors. The replay launch reuses delta_lanes_body with 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.
  • Model code holds only architecture facts. The changes sit in shared GPU code. Body38 only builds and swaps the replay tables for its stores and counts their bytes. The planner term is the descriptor SeqTerms the planners already share.
  • Dead code is gone. The staged walk takes exactly four columns, since two and three columns measured slower with it. The replay launch takes no position words, because its recovery path never reads them.
  • No silent failure. RecoveryTable::new and 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 past LAYER_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.
  • Comments state what is true now.
  • No relaxed gate. The moved counts are re-pinned with PIN(2026-10-27) and the reason: mxfp8_gemv_mcol_staged and gdn_delta_recovery_layers are new entries pinned at 0 spill and 0 JIT local bytes, mxfp8_w8a8_norm_gate is measured lower (364 to 340 spill bytes, JIT local 72 to 64), and the unsafe counts for gpu (2749 to 2764 blocks, 350 to 353 fns) and gpu-gates (106 to 109 blocks) cover the new code, each block with its SAFETY line.
  • cargo fmt and cargo clippy are 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 b8ce8b95146ce70d56b0331800b5e5d9467e4235 on upstream main 08047d8b5422432dccb31f9b77f8e00d3892981c. The runs below name the earlier head b56a2471f54bbff4cba6baa4190183986128fa67 where they ran on it. git range-diff shows 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 in labs/hip-native/Cargo.lock for the new bloomery-runtime dependency of bloomery-placement, which the locked build of that lab needs. No source changed.

Cards:

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
| 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 |
BLOOMERY_ARCH=sm_121a BLOOMERY_BOX_LOCAL=1 just gate-gpu-linear
BLOOMERY_ARCH=sm_121a BLOOMERY_BOX_LOCAL=1 just gate-gpu-linear --case recovery
BLOOMERY_ARCH=sm_121a BLOOMERY_BOX_LOCAL=1 just gate-gpu-mxfp8
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-e2e
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-mtp
BLOOMERY_ARCH=sm_121a BLOOMERY_BOX_LOCAL=1 just gate-ptx-spill
BLOOMERY_ARCH=sm_86 BLOOMERY_BOX_LOCAL=1 just ptx-compare 14dcdf9cd8c921fdadcca692cebb508fc0bcaccc generate_ds41 --features gpu,deepseek41
BLOOMERY_BOX_LOCAL=1 just gate-gpu-linear
BLOOMERY_BOX_LOCAL=1 just gate-gpu-mxfp8
BLOOMERY_BOX_LOCAL=1 just check
cargo test --release -p bloomery-model --lib slot_plans_count_every_term_per_slot
cargo test --release -p bloomery-placement --lib qwen38_cards

On the GB10 (sm_121a):

  • gate-gpu-linear on b56a2471f54bbff4cba6baa4190183986128fa67: 164 clauses, 0 failed. --case recovery exits 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-mxfp8 on 03045c5b9ba23ed9a2e6f9e744c3c24e602be694: 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-e2e on b56a2471f54bbff4cba6baa4190183986128fa67, with a fixture made from Qwen3.8-Flash-Next-UD-Q4_K_XL and its mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf draft (fixture SHA-256 d5e99a1f6b4e040ec75d41b3f6764cdcf4b1bc426f225ba4ab4bafb6c096cd62 for the target and bfd72ccdba0f98775dbc4956d4d3b2e8b3c505e1d6fb2b03036bac7e7c0c3262 for 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 its slots H3 line both PASS: one added sequence grows resident_bytes and seq_bytes by 42675588 bytes, the same as the sum derived from the header shapes, including the 64-byte replay table.
  • gate-gpu-qwen4exp-mtp on 4d3bdd78: exit 0. It ran before the later changes to RecoveryTable::new and the planners and was not run again.
  • gate-ptx-spill on 4d3bdd78 at sm_121a, sm_121 and sm_86: violations 0 PASS on every table. At sm_121a, mxfp8_gemv_mcol_staged has 52 registers, 4096 B of shared memory, 0 spill and 0 JIT local. gdn_delta_recovery_layers has 80 registers, 0 spill and 0 JIT local. The scan was not repeated after the replay kernel lost its position argument.
  • ptx-compare at sm_86 against main on 76dcfadb exits 3, as expected: added 2 (gdn_delta_recovery_layers, mxfp8_gemv_mcol_staged), removed none, changed 21. Of the 21, only fp8_b128_gemv changed 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-compare at sm_86 from 14dcdf9c to b56a2471 is 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.
  • The lane check and the staged-walk guard each failed first. With the lane check disabled, gate-gpu-linear --case recovery fails 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 of 03045c5b at the d6adc635 code, the same case fails 7 lines (PASSLINES recovery-old 66 FAILLINES 7), and gate-gpu-mxfp8 fails 12 (X_OFF4 old pass=84 fail=12): the staged shapes leave the output untouched when the activations are not 16-byte aligned.
  • The sequence-bytes check failed first too: with the two changed files from 03045c5b, the e2e gate fails its one slots H3 line and nothing else (PASSLINES e2e-old 172 FAILLINES 1).

On the RTX 5090 (sm_86, default x86 build), all on b56a2471f54bbff4cba6baa4190183986128fa67 except 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's beside bytes are the old terms plus 96 B. The placement tests qwen38_cards: 28 passed, 0 failed.
  • gate-gpu-mxfp8 on 03045c5b9ba23ed9a2e6f9e744c3c24e602be694: PASSLINES mxfp8 444 FAILLINES 0, with X_OFF4 pass=96 fail=0.

Lint on 03045c5b (an earlier commit): the clippy lint run exited 0, and contrib-check --tier t0 ended 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:

  • The staged walk's read stage index moved by one fails gate-gpu-mxfp8: gemv.bits ... m=4 equal=0/65536 FAIL, 4 FAIL lines
  • The replay's per-store block index replaced by the launch's global block index fails gate-gpu-linear: 17 FAIL lines
  • The replay's per-store fault sink replaced by the launch's sink fails gate-gpu-linear: 9 FAIL lines, fault layer 65535 for the planted layer 7
  • The planner's replay term removed fails slot_plans_count_every_term_per_slot on the RTX 5090: left: 368644, right: 368740

Not run: gate_qwen38_twocard, whose changed lines are a derived-value term, a doc line and the table's size; they compile in just check. The other gates just affected selects are not run either. A maintainer runs those on the workstation.

Speed

The timed model is nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, with the Q8_0 MTP draft file mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf (SHA-256 5ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6) 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 main d4af82e5a901048f237a17804311bbd7935c6d01. The head timed is 92d2624a85c71abb4845ef0b7e20e9484269133d. 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.

Arm Metric main head Change Ranges
Draft on, code-fn Decode tok/s 55.271 57.1408 +3.383% separate
Draft on, code-fn Prefill tok/s 2106.96 2111.55 +0.218% overlap
Draft on, code-fn TTFT p95 ms 1950.18 1946.53 +0.187% overlap
Draft on, prose-en Decode tok/s 40.0196 41.0671 +2.617% separate
Draft on, prose-en Prefill tok/s 2162.3 2161.52 -0.036% overlap
Draft on, prose-en TTFT p95 ms 1900.72 1901.97 -0.066% overlap
Draft off, code-fn Decode tok/s 30.6791 31.2567 +1.883% separate
Draft off, code-fn Prefill tok/s 2183.59 2194.98 +0.521% overlap
Draft off, code-fn TTFT p95 ms 1882.38 1871.93 +0.556% overlap

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

git checkout d4af82e5a901048f237a17804311bbd7935c6d01   # main
cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve
env BLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G BLOOMERY_MTP_DRAFT="<mtp-folder>" BLOOMERY_MTP_WIDTH=cost ./target/release/bloomery-serve -m "<folder>" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

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=off and leave out BLOOMERY_MTP_DRAFT and BLOOMERY_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 check ran 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 초안 리뷰는 제가 직접 했습니다.

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.
@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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 27, 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: 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 with blocks_lane_partials_mcol by hand. They share helpers and differ in staging.
  • Complexity: RecoveryTable::new 17 and enqueue_delta_recovery_layers 18 are new functions, complex on their own: load-time validation, one check per named refusal. enqueue_e4m3_gemv 21 to 26 is one match arm. Kernel bodies are complex by design.
  • Silent failure: 8 sites followed. Two build.rs unwrap_or_default give the bit-identical per-byte decode. Two else { return } in the replay kernel are unreachable behind RecoveryTable::new.
  • Adversarial: overlapping stores, a lane word inside a written range, exchange with a stale table, barriers in the staged walk, and an unaligned x or k are 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_gate move 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)

@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 27, 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 b9594b6 into midagedev:main Oct 27, 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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant