Skip to content

gpu: finish the MXFP8 gate projection and its output form in one epilogue - #819

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-dense-gdn
Oct 25, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-dense-gdn

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local의 선형 어텐션 층에서 gate projection이 공용 norm과 다음 층이 읽는 출력 양자화를 자기 store 단계에서 한 번에 끝내도록 합니다.

What and why

In a Qwen3.8 FP4-Local checkpoint, the z gate projection of each Gated DeltaNet layer is an MXFP8 W8A8 product. After it, two more launches ran: the shared sigmoid head norm (gdn_norm_gate_sigmoid) and mxfp8_cols, which quantizes the norm output into the MXFP8 form that ssm_out reads. A request ran each of them 36 times.

This PR lets the product's store epilogue do both. bf16_mma_norm_gate_body is now generic over the MMA operand views, so the block-scaled E4M3 tile (MXFP8) shares it with the BF16 tile. A new kernel mxfp8_w8a8_norm_gate and host entry enqueue_mxfp8_w8a8_norm_gate use it. The NormForm trait names what the epilogue writes beside the f32 values: nothing for the BF16 entry, and for the MXFP8 entry Mxfp8Out, which writes the E4M3 words, the UE8M0 scale words and the column refusal word (OR-ed across heads, zeroed by a memset before the launch). site::resident_gemm_norm_gate takes the output's readers and its scratch, reads the MXFP8 weight planes through the existing Weights::e4m3 owner, and uses the MXFP8 epilogue only when the readers take just the MXFP8 form from that scratch. In every other case it runs the split product, norm and resident_quantize. The wide Qwen3.8 gdn no longer calls quantize_for after the norm.

NVFP4 does not change. Its z projection is BF16, so it takes the BF16 arm, and the resident_quantize after it issues the same launches as before. The gate shows that the fused result is bit for bit the split result (split_bits) and that the output form matches enqueue_mxfp8_cols (out_form_bits).

Release notes: Changed: Qwen3.8 FP4-Local prompt prefill finishes the linear-attention output gate and its MXFP8 output form in the gate projection's store epilogue.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. The BF16 and MXFP8 gate projections share one tile body. ue8m0_block is now the one owner of the UE8M0 scale rule (mxfp8_cols_body uses it), GemmAct32::room the one owner of the form room check (form_launch uses it), mxfp8_mma_launch the one owner of the MXFP8 launch check (enqueue_mxfp8_w8a8 uses it), and reads_q32 the one owner of the question whether a site reads q8 blocks of 32 values, lifted out of resident_quantize.
  • Model code holds only architecture facts. The Qwen3.8 file only drops one call and hands on the readers; the common owners gained a trait and an argument, not a per-model branch.
  • Dead code is gone. The quantize_for call after the norm and the closure in resident_quantize are removed.
  • No silent failure. A scratch of another K, one without room for the form, a zero column count and a column count past the scratch are named errors, each with a gate row (cols_refused, mxfp8_refused).
  • Comments state what is true now.
  • No relaxed gate. The unsafe ratchet and the PTX shape table are raised for the new kernel and the new form code only, each with a PIN(2026-10-25): line and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": the duplicate scan reports three candidates. crates/gpu/src/gemm/nvfp4mma.rs:1403 and crates/gpu/src/gemm/nvfp4mma.rs:1346 are two kernel entries over the shared tile body with the flat arguments a kernel ABI needs. crates/gpu/src/gemm/nvfp4mma.rs:1403 and crates/gpu/src/gemm/kernels32.rs:1164 differ in tile, format and epilogue. crates/gpu-gates/src/bin/gate_gemm.rs:7615 and crates/gpu-gates/src/bin/gate_dspark_graph.rs:1176 are an arm-name match and an argmax comparison.

What I ran

Format and lint, on this head:

cargo fmt --all -- --check
just lint

cargo fmt --all -- --check was clean. just lint with the sm_121a target on a DGX Spark ended with rc 0 and 3 warnings, the same count as main.

GPU Evidence

Card conditions of the timed runs and of the gate, from nvidia-smi:

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |

The gated-projection cases (zgate) of gate_gemm ran on this head on a DGX Spark, both for the BF16 and for the MXFP8 form, on the normal edge at five shapes (the largest 6144 rows, K 2560 and 4095 columns) and on the NaN, out of range, overflow and gain edges. The output summary:

zgate pass=28 fail=0

All 28 zgate rows passed, none failed. The rows check split_bits, out_form_bits, eager_graph, the scratch contract, scratch_reuse and the fault sites. scratch_reuse runs one launch whose output columns are all refused and then a normal launch into the same output scratch, once eagerly and once as a graph replay, and compares the next product bit for bit with the split path. The refusal cases for the column and room checks are in the same run.

just gate-gpu-gemm not run as the full recipe: the zgate rows above ran from the same gate_gemm binary, and a maintainer runs the recipe on the workstation.

A mutant that drops the refusal OR from the epilogue fails out_form_bits on the MXFP8 normal and gain edge rows and on no BF16 row. A mutant that passes the replay length in value units fails split_bits on the MXFP8 NaN, range and overflow edge rows. A mutant that drops the column check from GemmAct32::room fails the cols_refused rows and out_past_cols. A mutant that removes the refusal word's memset before the launch fails only the MXFP8 scratch_reuse row (scratch_reuse=false); the other 27 rows pass.

Micro benchmark

On a DGX Spark, the 6144 x 2560 projection at 4095 columns (graph mean) takes 3234.90 us as separate product, norm and mxfp8_cols launches and 1990.55 us as one fused launch. The BF16 projection goes from 3179.15 us to 2499.66 us. The fused MXFP8 launch saves 1244 us, about 44.8 ms over the 36 launches of a request.

The new kernel has 364 bytes of spill and 64 bytes of JIT local, both in the epilogue and not in the MMA main loop; both are pinned in tools/ref/ptx-shapes/sm_121a-cc12.1.tsv.

Timed A/B

The timed A/B ran on a DGX Spark with main and with this change, three rounds per side in alternating order after a discarded lead-in round, medians below. Each request is a 4096-token prompt with 128 greedy tokens. The FP4-Local rows use the FP4-Local checkpoint without a draft and with the MTP draft (code and prose windows); the NVFP4 rows use the NVFP4 checkpoint without a draft.

Arm and metric Main Head Change
FP4-Local TTFT p95 (ms) 2000.54 1952.00 -2.427%
FP4-Local prefill (tok/s) 2053.76 2105.22 +2.505%
FP4-Local decode (tok/s) 30.1812 30.2797 +0.327%
FP4-Local MTP code TTFT p95 (ms) 2065.00 2025.10 -1.932%
FP4-Local MTP code prefill (tok/s) 1989.88 2029.64 +1.998%
FP4-Local MTP code decode (tok/s) 59.4896 60.0203 +0.892%
FP4-Local MTP prose TTFT p95 (ms) 2038.60 1995.77 -2.101%
FP4-Local MTP prose prefill (tok/s) 2015.60 2059.82 +2.194%
FP4-Local MTP prose decode (tok/s) 42.8200 43.1658 +0.808%
NVFP4 TTFT p95 (ms) 2102.51 2107.32 +0.229%
NVFP4 prefill (tok/s) 1953.96 1949.36 -0.235%
NVFP4 decode (tok/s) 22.557 22.5206 -0.161%

Greedy output was identical on main and on head in every part.

On FP4-Local the prefill and TTFT ranges of the two sides are separate. Decode on FP4-Local is inside the run-to-run noise: its ranges overlap. With the MTP draft the prefill and TTFT ranges are separate in both windows, and decode ranges overlap. NVFP4 is inside the noise in all three metrics: every range overlaps.

The timed runs were built before the launcher arguments moved into the two argument structs (Mxfp8NormGateArgs, NativeNormGateArgs) and before one is_multiple_of edit of a lane test in Mxfp8Out::store. The structs change no check, launch or order. The edit changes three PTX lines of mxfp8_w8a8_norm_gate, with the same register count, spill and shared memory (128 registers, 364 bytes of spill, 49152 bytes of shared memory). The gate rows above ran on this head. The ptx-scan MD5 block of gate_gemm built from it is identical across 377 entries to the one from the head that carries the is_multiple_of edit.

Reproduce one FP4-Local round (the NVFP4 round uses the NVFP4 checkpoint; the MTP rounds add BLOOMERY_DRAFT=mtp BLOOMERY_MTP_DRAFT="<mtp-folder>" BLOOMERY_MTP_WIDTH=cost), with base on main and head on this branch:

(cd base && cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve)
env BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./base/target/release/bloomery-serve -m "<folder>" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896 & server_pid=$!
until curl -fsS http://127.0.0.1:18731/health; do sleep 1; done
kill "$server_pid"; wait "$server_pid"

Hardware

DGX Spark (GB10), driver 595.84, CUDA 13.3, for the gate, the lint, the micro benchmark and the timed A/B.

AI help

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

The Qwen3.8 delta layer's gated norm output feeds the MXFP8 output
projection, which needs its MXFP8 form. A separate mxfp8_cols launch read
the 4096 x 4096 f32 rows back to write it. The MXFP8 norm-gate epilogue now
writes the form from the values it holds, bit for bit mxfp8_cols's, and
ORs each column's refusal across its heads. The site takes this path only
when that form is all the readers take from the scratch, and quantizes for
them itself otherwise.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app 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 25, 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 finding remains; the GPU evidence request is non-blocking.

Non-blocking

⚠ Complete the GPU evidence: crates/gpu/src/gemm/f32tile.rs:2043.
This folds launches into the projection epilogue: three graph nodes become two per MXFP8 projection. The PR body supplies gate summaries and A/B medians, but omits both measured commit hashes, actual model filenames, and the gate command with its output.
Attach the owning gate command and output, measured hashes, model filenames, and reproducible A/B commands and output to complete CONTRIBUTING.md's evidence list.

Checked

Duplicates: diagnostics report zero qualifying dryer pairs in crates/gpu; gpu-gates was outside the scan.
Complexity: diagnostics report norm_gate_case 88 → 190 and resident_gemm_norm_gate 6 → 21. Complexity alone produced no finding.
Dispatch: incompatible output readers retain the split path and resident_quantize. The fused launcher clears output refusal words before its kernel.
Tests: norm_gate_case checks split_bits, out_form_bits, graph parity, and scratch reuse. Removing the refusal memset at crates/gpu/src/gemm/nvfp4mma.rs:1786 fails scratch_reuse according to the author's mutant report. GPU gates and the mutant were not run here.
Gates: new unsafe and PTX resource allowances carry dated PIN reasons.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/arch/qwen3moe/wide38.rs, crates/gpu/src/gemm/act32.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 1ace8eb into midagedev:main Oct 25, 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 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