Skip to content

gemm: run MXFP8 prompt sites W8A8 on activations prepared once - #769

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-dense-mx8act
Oct 24, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-dense-mx8act

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

GB10에서 MXFP8 dense 곱셈이 활성값을 한 번만 MXFP8로 양자화해 두고 FP8 텐서 코어(W8A8)로 계산하게 해서 prompt 처리 속도를 높이는 속도 PR입니다.

Part of #565.

What and why

On a GB10, the MMA tile of a dense MXFP8 site decoded the weight's E4M3 values and rounded its F32 activation pieces to BF16 in every row block of the product, then ran a BF16 MMA. The walk now writes an MXFP8 form of each model-width input once, beside its Q8 scratch: E4M3 values, one UE8M0 scale per block of 32 values and a refusal word per column. mxfp8_w8a8_gemm multiplies the stored weight by that form with the block-scaled m16n8k32 E4M3 MMA, and the shared tile's cp.async pipeline, ldmatrix loads and exact replay serve both operand kinds.

A column holding a value the BF16 tile's rule refuses (mma_fits) and a weight row whose block scale byte lies outside 10..=165 replay on the exact owner from the F32 rows and the stored weight.

  • crates/gpu/src/gemm/act32.rs: GemmAct32 holds the BF16 form and the MXFP8 form (MmaForm, ColsForm, with_form). enqueue_mxfp8_cols fills the MXFP8 form. A quantizer launch or a fill forgets both forms, and a GEMM reads a form only when its rows, column count and kind match.
  • crates/gpu/src/gemm/nvfp4mma.rs (built for sm_120a and sm_121a): the kernels mxfp8_cols and mxfp8_w8a8_gemm, with host wrappers Kernels::mxfp8_cols and Kernels::mxfp8_w8a8. Other builds refuse both entries by name.
  • crates/gpu/src/gemm/f32tile.rs: MmaRows and MmaCols gain a SCALED operand kind with scale_word and mma. A scaled operand counts K in 16-bit units, so a pair of E4M3 values stages like one BF16 word. Each quad lane loads the scale words its MMA's thread-id selectors name.
  • crates/gpu/src/site.rs and the Qwen3.8 wide walk (wide38.rs, body38.rs, plan38.rs): resident_gemm takes the W8A8 entry for an E4M3 weight with MXFP8 scales when the rows hold the form. write_forms writes only the forms a site reads and forgets the rest.
  • crates/model/src/arch/qwen35moe/place.rs: on a unified card the named reserve for the forms is 14,772 B per position, the BF16 form's share and the MXFP8 form's share together. A discrete card reserves none.
  • crates/gpu-gates/src/bin/gate_gemm.rs: the new mxfp8_w8a8 case (details under Tests and FAIL-first), and the BF16 form's graph check in dense_mma now replays over a form rewritten from zeros after the capture, so a graph that lacks its form launch is caught.
  • tools/unsafe-ratchet.txt (with a PIN line), tools/ref/ptx-shapes/sm_121a-cc12.1.tsv (rows for the two new entries) and one sentence in docs/contrib/dgx-spark.md.

Release notes: Changed: dense MXFP8 prompt products on GB10 run on FP8 tensor cores over activations quantized once per input.

Code shape

  • No second copy. The W8A8 product reuses the existing MMA tile bf16_mma_body with block-scaled operands, so there is one tile, one exact replay and one tail rule. Column refusal reuses mma_fits, form_col and store_refused, shared with the BF16 form.
  • Model code holds only architecture facts. The Qwen3.8 walk names which inputs carry a form. A common owner gained no per-model branch.
  • Dead code is gone. PlaceError::Bf16FormReserve became ActFormsReserve, and the removed refusals of enqueue_bf16_cols live on in form_launch and held_form.
  • No silent failure. The new host entries refuse a wrong form kind, rows, column count, K that is not a multiple of 128, an unaligned weight and a non-native build, each by name with a gate row.
  • Comments state what is true now. No dates, issue numbers or measurements in the new comments.
  • No relaxed gate. No band or tolerance moved. The unsafe ratchet moved with a PIN line. The placement test that checked the BF16 reserve is replaced by a_unified_stage_reserves_the_act_forms with a PIN line.
  • cargo fmt is clean. cargo clippy with CUDA_OXIDE_TARGET=sm_121a was not run, because nvfp4mma.rs is built only for sm_120a and sm_121a and the default lint does not see it.

Duplication found or removed (path:line), or "none": none added. crates/gpu/src/gemm/nvfp4mma.rs:481 (the E4M3 m16n8k32 MMA with thread-id selectors) and crates/gpu/src/gemm/nvfp4mma.rs:305 (the FP4 routed MMA) use different instructions and operand shapes. mxfp8_cols and bf16_cols are separate kernel entries over different planes, and both call form_col, mma_fits and store_refused.

What I ran

Hardware and builds

The timed run and the gates ran on one DGX Spark (GB10) at the default sm_121a target. The card as nvidia-smi reports it on the gate run:

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

The same card on the timed run:

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

Speed

Upstream main 608c0909a8a4deeea2dcd3f33eef6a1ecd36e024 and the branch were built on the same machine at sm_121a with cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve. Each checkpoint was served with bloomery-serve -m <model> --host 127.0.0.1 --port <p> --parallel 4 --ctx-size 16896 and BLOOMERY_DRAFT=off. The models are the FP4-Local and NVFP4 Qwen3.8-Flash-Next checkpoints. The request is a 4,096-token code prompt on /completion at concurrency 1, temperature 0 and 128 output tokens. Main and head alternated in one sitting after a discarded warm load, and the GPU clock cap was lifted only while an arm's requests ran. A cell is the median of the arm's requests.

model metric main head delta
FP4-Local prefill tok/s, pair 1 1524.2 1718.3 +12.7 %
FP4-Local prefill tok/s, pair 2 1519.3 1715.3 +12.9 %
FP4-Local TTFT ms, pair 1 2692.8 2390.1 -11.2 %
FP4-Local TTFT ms, pair 2 2701.0 2394.0 -11.4 %
FP4-Local decode tok/s, pair 1 30.41 30.30 -0.36 %
FP4-Local decode tok/s, pair 2 30.14 30.22 +0.27 %

FP4-Local: prefill +12.7 % and +12.9 %, TTFT -11.2 % and -11.4 %, decode -0.36 % and +0.27 %

The two pairs agree within 1 % of each other, and decode does not move. This is one sitting with two pairs, not a significance test.

The kernel times of one profiled FP4-Local 4,096-token prompt show where the time went:

  • On main, mxfp8_mma_gemm took 624.4 ms over 396 launches. On the head, mxfp8_w8a8_gemm takes 247.6 ms over 396 launches and mxfp8_cols takes 53.2 ms over 192, which is 300.8 ms together. Summed kernel time falls from 2,678.8 ms to 2,355.1 ms.
  • A kernel microbenchmark at 4,096 columns, N=10240 and K=2560 shows the same direction: main's tile entry takes 5.51 ms, the W8A8 product 2.29 ms, and 2.49 ms with the form written in the same call.

Output parity

Greedy 128-token outputs on FP4-Local match main for two of three prompts. The third diverges at character 313 (main continues "# handle the individual names", the head "# handle the internal names"), and both continuations are valid code. The divergence sits at the same place in both repeats. The NVFP4 checkpoint's greedy output equals main's. KL was not measured.

Tests and FAIL-first

Each gate case ran with bash tools/gpu-gate.sh gate_gemm --case <case>, the gate step of the just gate-gpu-gemm recipe, on the card above:

just gate-gpu-gemm --case dense_mma (gate step: gate_gemm --case dense_mma)
HEAD_GATE gate_gemm --case dense_mma rc=0 pass=121 fail=0
just gate-gpu-gemm --case nvfp4_native (gate step: gate_gemm --case nvfp4_native)
HEAD_GATE gate_gemm --case nvfp4_native rc=0 pass=37 fail=0
just gate-gpu-gemm --case nvfp4_swiglu (gate step: gate_gemm --case nvfp4_swiglu)
HEAD_GATE gate_gemm --case nvfp4_swiglu rc=0 pass=21 fail=0

The dense_mma run includes the 32 new mxfp8_w8a8 rows. cargo test --release -p bloomery-model --lib -- qwen35moe::place gave test result: ok. 31 passed; 0 failed, including a_unified_stage_reserves_the_act_forms.

The new mxfp8_w8a8 case holds:

  • mxfp8_w8a8_form: the written form equals a host quantizer (mxfp8_reference, an independent implementation of the same rule) cell for cell.
  • mxfp8_w8a8: shapes (129,128,127), (129,128,128), (129,256,129), (257,128,257), (128,640,129) and (17,640,3) equal an f64 oracle bit for bit on exactly representable inputs, with eager equal to graph and the guard words after the output intact.
  • mxfp8_w8a8_neighbours: a column carrying 0x00000200 (subnormal), 0x57800000 or NaN takes the exact owner's bits, and every other cell keeps its W8A8 bits.
  • mxfp8_w8a8_scale_edges: weight rows with scale byte 9 or 166 go to the exact owner, rows with 10 or 165 stay on the MMA.
  • mxfp8_w8a8_refused: other rows, more columns, a BF16-only form, a stale read, a read after a quantize, an unaligned weight and K not a multiple of 128 are each refused by name.

FAIL-first, each mutant built and run against mxfp8_w8a8, both red with rc 1:

  • Scale exponent rounded down, UE8M0 bound 10..=166 and fill keeping the MXFP8 form: FAIL_FIRST M1 rc=1 pass=24 fail=8, with cells_off_reference=1592 in the form row, all six mxfp8_w8a8_scale_edges rows bytes_9_166_exact=false and after_quantize=false in the refusal row.
  • Scale bytes of a word read in the order 0,2,1,3 and the MXFP8 form refusing no column: FAIL_FIRST M2 rc=1 pass=19 fail=13, with cells_off_reference=14786 in the form row.

Device code on sm_121a: the PTX spill pin check over the dense MMA entries and the form kernels gave entries=17 pinned=17 with violations=0. The new mxfp8_cols and mxfp8_w8a8_gemm have spill 0 and local 0, with 28 and 128 registers.

Static checks: ./tools/mac-check.sh check with and without CUDA_OXIDE_TARGET=sm_121a exit 0 with no warnings, ./tools/mac-check.sh fmt is clean, and tools/check-unsafe.sh and tools/check-ptx-names.py pass.

Heads

The speed A/B ran on the branch before it was rebased onto current main and before the two graph checks in gate_gemm.rs changed. The device and host code of this PR and its build path are the same as the measured tree's, and range-diff over the rebase shows only changed context in the gate case list, one import line and the unsafe ratchet count. The speed deltas are each tree against its own base and are not a fresh measurement on current main.

After the rebase the gate cases ran again, on the DGX Spark at sm_121a and on an RTX 5090 at sm_120a, with the same result on both cards. The only later change boxes the two RouteX variants and turns two chunks_exact calls in the gate's reference into as_chunks, for clippy; it moves no device code.

HEAD_GATE gate_gemm --case dense_mma rc=0 pass=121 fail=0
HEAD_GATE gate_gemm --case mxfp8_w8a8 rc=0 pass=32 fail=0
HEAD_GATE gate_gemm --case nvfp4_native rc=0 pass=37 fail=0
HEAD_GATE gate_gemm --case nvfp4_swiglu rc=0 pass=21 fail=0
HEAD_GATE gate_gemm --case nvfp4_gate_up rc=0 pass=5 fail=0

The two graph checks now count the form launch inside the capture. With the capture leaving the form launch out, both cases turn red on the RTX 5090:

FAIL_FIRST M3 --case dense_mma rc=1 pass=109 fail=12
FAIL_FIRST M3 --case mxfp8_w8a8 rc=1 pass=26 fail=6

Reproduction

just gate-gpu-gemm --case dense_mma
just gate-gpu-gemm --case nvfp4_native
just gate-gpu-gemm --case nvfp4_swiglu
cargo test --release -p bloomery-model --lib -- qwen35moe::place

For the timing, build upstream main and the head at sm_121a, serve the FP4-Local checkpoint with the draft off, and send greedy requests of a 4,096-token prompt and 128 output tokens, alternating the arms.

What I ran into

This does not block the PR.

  • NVFP4 checkpoint prefill is undecided. Its dense sites hold BF16 weights, so they do not take the new path, but they share the widened tile. With one request per arm, prefill was 1451.7 tok/s on main and 1341.5 tok/s on the head, and a repeat sitting pointed the other way, so I cannot attribute the gap to this change or to noise.
  • Not run on the final head: the gate cases above after the last edit to the gate's two graph checks (the checks were Mac-compiled only), a FAIL-first of a graph that omits its form launch, the PTX spill pins for sm_121 and sm_86, ptx-compare, and cargo clippy for sm_121a.
  • Not measured: KL, and prompt lengths other than 4,096 tokens.
  • The form quantizer launches 192 times on the profiled prompt for 396 W8A8 products, 53.2 ms in all. Writing the form from the producing kernels (norm, attention output, SwiGLU) would remove those launches and one F32 read.

AI help

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

On GB10 an MXFP8 dense site's MMA tile decoded the weight's E4M3 values
and rounded its F32 activation pieces to BF16 in every row block of the
product, then ran BF16 MMA. The walk now writes an MXFP8 form of a
model-width input once beside its q8 scratch (GemmAct32::with_form with
MmaForm::Mxfp8, and mxfp8_cols: E4M3 values, one UE8M0 scale a block of
32 and a refusal word a column), and mxfp8_w8a8_gemm multiplies the
stored weight against that form with the block-scaled m16n8k32 E4M3
MMA, copying both operands with cp.async as the BF16 form's tile does.
A column holding a value the BF16 tile's rule refuses (mma_fits) and a
weight row with a block scale byte outside 10..=165 replay on the exact
owner from the f32 rows and the stored weight.

The shared MMA tile takes block-scaled operands (MmaRows::SCALED,
scale_word and mma, MmaCols::scale_word): K counts 16-bit units, E4M3
pairs stage like BF16 words, and each quad lane loads the scale words
its MMA's thread-id selectors name. GemmAct32 holds both forms through
MmaForm and ColsForm; a quantizer launch or a fill forgets both.
site::resident_gemm takes the W8A8 entry for an E4M3 weight with MXFP8
scales when the rows hold the form, and the Qwen3.8 wide walk reserves
the hidden, attention and FF inputs' forms (ACT_FORMS_TOKEN_BYTES). The
MXFP8 device code lives in nvfp4mma.rs, built for sm_120a and sm_121a;
other builds refuse the two entries by name.

gate_gemm's mxfp8_w8a8 case checks the form against a host quantizer,
the product against an f64 oracle at ragged shapes, the exact owner's
columns and rows, and the stale and misplaced forms. Its graph check and
dense_mma's BF16 form check replay over a form rewritten from zeros
after the capture, so a graph without its form launch fails.
@github-actions github-actions Bot added dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app 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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 24, 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 demonstrated behavior defect or proven quality defect survived review.

Non-blocking

⚠ Attach the precision-change gate: crates/gpu/src/gemm/f32tile.rs:1557. Activations now round to E4M3 instead of BF16. The precision change class in AGENTS.md requires the gate-gpu-e2e count pin. Attach that recipe's output for the final head; the kernel oracles do not exercise model integration.

⚠ Complete the A/B reproduction evidence: crates/gpu/src/site.rs:1050. The timing section omits the measured branch SHA, exact model file and runnable request command with output. Supply both measured SHAs and the complete commands. The card and gate output alone do not satisfy the evidence list.

Optimization headroom

  • G, Per-launch and per-sync fixed cost: crates/gpu/src/site.rs:1224. Write the form in its existing producer. For m columns of width K, this removes 1/m launches and 4K bytes of F32 reads per token [derived].

Checked

Duplicates: 60 added definition headers checked, including renamed items and trait implementations; no actionable duplicate. Dryer returned zero pairs in model; GPU and gate owners were Grepped manually.
Complexity: new mxfp8_w8a8_case (90) spans form/oracle, product/graph, replay and refusal stages, the natural split points. gemm 38→41 adds dispatch; dense_mma_case 108→110 adds graph preparation; run 19→20 adds one case.
Silent failure: six production sites followed. Optional reserve/form absence is valid; tail clamps feed only live output stores; refused non-finite columns replay exact NaNs and reach the existing fault checks.
Tests: dropping the form launch breaks graph equality; reversing scale bytes breaks the oracle; retaining a form after fill breaks refusal checks; changing reserve bytes breaks the placement assertion. These are assertion checks, not a local GPU run.
Gates: no tolerance moved; unsafe-count and replacement reserve-test pins carry dated reasons.
Adversarial checks: minimum K=128 supplies both initial stages; ragged tiles keep accesses inside live operands; stale pointers and excess columns fail the form guards.
Escape catalog: C1–C4 do not match this diff. No ledger lessons apply.

Notes

Static review only. GPU gates and PTX comparison were not rerun. GPU evidence is incomplete because the supplied run does not identify both tested commits.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/plan38.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 4197866 into midagedev:main Oct 24, 2026
7 checks passed
@juliankang4

Copy link
Copy Markdown
Collaborator Author

Follow-up evidence for this PR, collected after the merge.

Precision-change gate. The activations at the MXFP8 sites now round to E4M3, so this change is in the float precision class of AGENTS.md, whose runtime gate is the gate-gpu-e2e count pin. It passed on the merged head, on an RTX 5090 (driver 595.99.02, CUDA 13.2, default sm_86 build, DeepSeek-V2-Lite-Chat Q3_K_M):

forced_exact positions=1056 disagree=42 buckets=[15 21 4 2] ge_floor=6 pin<=6 max_margin=2.018 ok
graph graph_nodes=648 want=648 eager_vs_graph_identical=true ok

V2-Lite has no MXFP8 weights, so this run shows that the count pin did not move. The W8A8 path itself is checked by gate_gemm --case mxfp8_w8a8 on DGX Spark (32 passed, 0 failed).

Reproducing the timing in the body.

  • Hardware: one DGX Spark (GB10, driver 595.84, CUDA 13.3).
  • Builds: main 608c0909a8a4deeea2dcd3f33eef6a1ecd36e024 and the branch, both with cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve. The branch build was an earlier commit with the same device code as the merged one. The merged commit adds only a host-side Box for clippy and sits on a newer base.
  • Models: nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300 and nvidia/Qwen3.8-Flash-Next-NVFP4 at fc694b54fb0174e0913e6adf86691ef85a4ead47.
  • Server: BLOOMERY_DRAFT=off bloomery-serve -m <model folder> --host 127.0.0.1 --port 18673 --parallel 4 --ctx-size 16896, one load per arm.
  • Requests: three 4,096-token windows of a code corpus sent to /completion with temperature 0, n_predict 128 and concurrency 1. The arms ran main, head, main, head in one sitting.
  • One profiled 4K prompt: on main, mxfp8_mma_gemm took 624.4 ms over 396 launches. On the branch, mxfp8_w8a8_gemm took 247.6 ms over 396 launches and mxfp8_cols 53.2 ms over 192.

NVFP4 checkpoint. The body left its prefill undecided. Its dense sites hold BF16 weights and do not take the new path, but they share the widened tile. I benchmarked the four shared entries (bf16_mma_cols_gemm, bf16_mma_gemm, mxfp8_mma_gemm, bf16_cols) on main and on the merged head, at sm_121a on the same DGX Spark, over 24 shapes with four alternated runs each. Register counts are the same (128, 127, 124 and 28), no entry uses local memory, and the outputs are bit-identical. Head over main time ratios range from 0.986 to 1.114 with a median of about 1.01; the 1.114 case is a 0.23 ms kernel. The single-request prefill gap in the body (1451.7 against 1341.5 tok/s, reversed in a repeat) is noise, not this change.

Lint and spill. On the merged head, cargo clippy with CUDA_OXIDE_TARGET=sm_121a reports two too_many_arguments warnings on new host wrappers in nvfp4mma.rs (9 and 10 arguments) and one type_complexity warning that main already has. The PTX spill pins and ptx-compare pass for this change's device code.

(AI 코딩 에이전트가 작성한 코멘트이며, 내용은 제가 확인했습니다.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app 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 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