Repository navigation
gpu: run the routed NVFP4 gate, up and SwiGLU as one native launch - #766
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix findings remain in the changed code.
Non-blocking
⚠ Complete the PTX move proof: crates/gpu/src/gemm/act32.rs:620. The PR reports changed digests for six existing entries after extracting quant32_lane. Attach just canon-check <base> output showing that these entries remain the same program, as required by AGENTS.md's move/split class.
⚠ Identify the tested commits: crates/gpu/src/gemm/nvfp4mma.rs:730. The PR identifies the short sitting as this head, but omits the revisions used for the pre-cleanup timing and pre-rebase gate runs. Add those tested commit hashes to complete CONTRIBUTING.md's evidence list.
Checked
Duplicates: 12 new functions, types and constants, plus one macro checked. No duplicate owner found. Dryer returned zero GPU pairs; GPU-gates was searched manually.
Complexity: nvfp4_gate_up_case (70) and nvfp4_gate_up_arm (31) are new fixture/execution/comparison pipelines; those stages provide the split. Benchmark run (16→18) and g32 run (18→19) add dispatch/case arms, harmless growth.
Silent failure: five sites followed through their consumers: unknown benchmark arm, padded route read, inactive quantizer values, zero scale and non-finite epilogue values. Invalid inputs reach a named error or fault.
Tests: dropping the second Q8 block, replay launch or down-K guard reaches failing assertions; FAIL-first results are reported in the PR. Static enumeration of route lengths 1–64 confirms one writer and one quantizer read per live tile value.
Gates: unsafe ratchet increase and lint exemptions have dated PIN reasons; the new spill row has reported FAIL-first evidence. No numeric band was relaxed.
Escape catalog: C1–C4 do not match the diff. Boundary tiles, refused routes, non-finite values and reset replay were traced against their guards and consumers.
Notes
Dryer did not scan GPU-gates. GPU gates and PTX tools were not run during this source review.
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)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 NVFP4와 FP4-Local의 prompt 처리에서 routed expert의 gate, up, SwiGLU를 kernel 하나로 합쳐 중간 F32 쓰기와 읽기를 없애고 prefill을 빠르게 하는 작업입니다.
Part of #565.
What and why
On a native FP4 build (the GB10 default,
sm_121a) with both routed stacks in NVFP4 planes, a Qwen3.8 layer computes the card slots' gate GEMM, up GEMM and SwiGLU as three launches. The first two write their products to F32 scratch (gandu), and the SwiGLU reads them back and quantizes its result to Q8 for the down GEMM. At 4,096 tokens with top-10 routing that scratch is large.This PR runs the three as one kernel,
gate_up_nvfp4_mma, incrates/gpu/src/gemm/nvfp4mma.rs. Each block holds 64 rows of the gate stack and the same 64 rows of the up stack for one route tile in shared memory, issues the gate and upmmaon the same activation fragment, applies SwiGLU in registers and quantizes each slot's two 32-value blocks from a shared tile. The F32 scratch round trip and one launch per layer go away.quantize_nvfp4_32then packs the down GEMM's FP4 from that Q8, as it already does for other callers.Gemm32Kernels::enqueue_gate_up_sel32andGateUp32Args(crates/gpu/src/gemm/gemm32.rs) are the one entry, andwide38.rsis its caller. It takes the fused path only on a native FP4 build with both stacks in NVFP4 planes and the activations in the native form. Every other build and stack runs the existing gate GEMM andenqueue_up_swiglu32, the launches main runs today.GateUpArgs, plus the stream, the activations and the fault sink, so it needs no lint allowance. Kernel entries keep the function-leveltoo_many_argumentsallowance the kernel-entry rule gives them.crate::elem::silu_mul, the function the activation path runs for SwiGLU, so the arithmetic has one owner. The kernel takes no activation-rule parameters.GemmAct32::fill, like every other quantizer launch, so the BF16 form is forgotten as well.gemm_nvfp4_mmaandgate_up_nvfp4_mmais one macro,nvfp4_walk!, so the protocol has no second copy.quant32_groupis split out asquant32_lane, and both the old quantizer and the new epilogue call it.tools/ref/ptx-shapes/sm_121a-cc12.1.tsvgains a pinned row for the new kernel (spill 0, JIT local 0).tools/unsafe-ratchet.txtcarries aPINline for the new kernel'sunsafeblocks (2297 to 2312). The module-widetoo_many_argumentsallowance innvfp4mma.rsis gone; the remaining function-level allowances carry the kernel-entry reason, and the two exemptions that need a dated pin (theswigludevice-core scope and thenvfp4_pack_q8range loop) have one.Release notes: Changed: Qwen3.8 NVFP4 and FP4-Local prompt prefill is about 3% faster on a DGX Spark.
Code shape
nvfp4_walk!, the Q8 rule isquant32_laneand the SwiGLU arithmetic iselem::silu_mul, each shared by all of its users.QuantColumn, a refused expert id raisesExpertId, and a down K that differs from the gate and up rows is refused by name. The gate's reset and replay faults are asserted, not dropped.PINline, and the gate that covers the fused launch now replays over reset buffers (see "What I ran").cargo fmtis clean (tools/mac-check.sh fmt, rc 0). Clippy atsm_121areports no warning in code this PR adds (see "What I ran into"); the default-target lint count is checked by CI.Duplication found or removed (
path:line), or "none": none left on the head. The duplicate scan matched the new kernel againstgemm_nvfp4_mma(the K walk, now the shared macro; the fragment step and the epilogue differ) and againstswiglu_nvfp4_32(it reads F32gandufrom global memory and packs FP4, while the new kernel computes both in registers and stores Q8). Both reuseelem::silu_muland the shared Q8 owner.What I ran
All gates and timings ran on a DGX Spark. The first timed sitting ran on the commit before the kernel's argument cleanup; the second, shorter sitting ran on this head. "What I ran into" lists what that changes.
Output is unchanged
nvfp4_gate_upcompares the fused launch with the existing split launches on the same route at four shapes (64x64 over 9 tokens, 128x128 over 50 with a refused expert id, 192x256 over 37 with a NaN in token 5, 640x2560 over 131), three card experts, one host place and top-2, and checks the down-K refusal. It checks every card slot's Q8 bytes, the down GEMM's output bits and the expected fault on eager and graph replay. After capture it resets the output to its sentinel and the down activations to the quantization of a zero input, replays the graph, and then reads the Q8 bytes and asserts that the replay's fault equals the eager fault. The fused path leavesganduat their sentinel.just gate-gpu-gemm --case nvfp4_gate_up, run as the recipe'sbash tools/gpu-gate.sh gate_gemm --case nvfp4_gate_upstep:GATE nvfp4_gate_up: tools/gpu-gate.sh gate_gemm --case nvfp4_gate_up rc=0 pass=5 fail=0, withq8_off=0 y_eq=true eager_graph_eq=true replay_fault_eq=trueon every shape andrefused_k=trueon the K refusaljust gate-gpu-gemm --case nvfp4_native, run as the recipe'sbash tools/gpu-gate.sh gate_gemm --case nvfp4_nativestep:GATE nvfp4_native: tools/gpu-gate.sh gate_gemm --case nvfp4_native rc=0 pass=37 fail=0just gate-gpu-gemm --case nvfp4_swiglu, run as the recipe'sbash tools/gpu-gate.sh gate_gemm --case nvfp4_swiglustep:GATE nvfp4_swiglu: tools/gpu-gate.sh gate_gemm --case nvfp4_swiglu rc=0 pass=21 fail=0These gates ran on the tree this head was rebased from; the rebase changed only the unsafe-ratchet lines.
FAIL-first
eager_graph_eq=falseon all four shapes andreplay_fault_eq=falseon the refused and poisoned shapes (mutant_red=yes). The mutant that never launches the replay does the same. A gate that replayed over the eager run's activations would pass the first mutant.let b = 2 * rt + blktolet b = 2 * rt(the fused Q8 block index drops the tile's second block) turns all four shapes red:q8_off=48 y_eq=falseon the 64 row shape, and the other three the same, with the gate endinggate_gemm: FAILED.act.k != rowscheck from the native launcher turns the new clause red:rows=64 act_k=128 refused_k=false FAIL, and the gate exits rc 1. The other four shapes stay green.generate_ds41 gate_up_nvfp4_mma unpinned spill=0 jit_local=0and exited rc 1. The pinned row (0, 0) fixes it.PTX
At the native arch (
sm_121a, ptxas 13.3.73, JITcc 12.1),generate_ds41:gate_up_nvfp4_mma: 256 threads, 116 registers, 37,376 B of shared memory, 0 spill, 0 JIT local, two blocks per SM.gemm_nvfp4_mmakeeps main's digest, 98 registers and 0 spill.swiglu_nvfp4_32andswiglu_nvfp4_32_seluse 72 registers andquantize_nvfp4_3280, all with 0 spill.BLOOMERY_ARCH=sm_121a PTX_SPILL_CACHE=off bash tools/ptx-spill-check.sh tools/ref/ptx-shapes.tsv tools/ref/ptx-shapes/ generate_ds41:mma:ptx-spill bin=generate_ds41 entries=18 pinned=18withviolations=0 PASS.ptx-compareagainst main lists six existing entries whose PTX digest moved and whose registers, spill and JIT local did not:gemm_nvfp4p_swiglu,quantize_gemm32,relu_sqr_quant32,swiglu_act_quant32,swiglu_quant32andswiglu_quant32_sel. They inlinequant32_group, whose per-lane core is nowquant32_lane: the same arithmetic in a different instruction order. Onlyquantize_gemm32is on the Qwen3.8 native prompt path: 11.28 ms on main and 11.32 ms on the measured head in the profiled prompt, 48 launches.Speed
Kernel bench (no model;
gate_gemm --bench-kernels, graph replay mean per layer). Shape: 4,096 tokens, top-10 (40,960 slots), 512 experts, 640 x 2560 NVFP4 gate and up. The Q8 output is checked equal between the two forms in every run.End to end, FP4-Local and NVFP4 Qwen3.8, one server load per arm,
bloomery-serve -m <model> --parallel 1 --ctx-size 16896withBLOOMERY_DRAFT=off. Planubatch=4096, all 24,576 routed experts on the card. Requests: two 4,096-id code windows (offsets 0 and 4096), one request at a time, 128 greedy tokens. Both trees built at the default arch (sm_121a), main at 346bbd7. Arm order: round 0 head then main, round 1 main then head, round 2 head then main, then the same for the second checkpoint. The clock cap was lifted only while an arm's requests ran. Models:nvidia/Qwen3.8-Flash-Next-FP4-Localat b9ce18a6 andnvidia/Qwen3.8-Flash-Next-NVFP4at fc694b54. Medians of three rounds:Delta (head against main): prefill +3.31% on FP4-Local (1521.6 to 1572.0 tok/s) and +3.61% on NVFP4 (1582.7 to 1639.9 tok/s); decode is within the run-to-run spread.
The prefill gain is outside the noise for both models: every head prefill sample is above every main prefill sample. FP4-Local decode reads 0.98% lower on head, but the per-round ranges overlap, so I read it as noise. This change does not touch decode.
Kernel time of one profiled 4,096-id FP4-Local prompt (round 2 of that sitting):
A second, shorter sitting ran this change against main at 608c090, FP4-Local only. Both binaries were warmed first; the arms ran head, main, main, head, each on the same two 4,096-id windows with 128 greedy tokens,
BLOOMERY_DRAFT=off bloomery-serve -m <model> --host 127.0.0.1 --port <port> --parallel 4 --ctx-size 16896, both trees at the defaultsm_121aarch:Over the two pairs, head against main: prefill 1524.6 to 1573.3 tok/s (+3.2%), TTFT p95 2726.0 to 2635.3 ms (-90.7 ms, -3.3%), decode equal within noise. Greedy tokens are equal between head and main on both windows in both rounds. This agrees with the first sitting (+3.31% prefill, -2.74% TTFT).
GPU evidence
A DGX Spark (GB10,
nvidia-smiof the gate run and of the short sitting):Builds ran in a CUDA 13.3.1 container at the default arch,
sm_121a:cargo oxide build --arch sm_121a -- --locked -p bloomery-gpu-gates --release --bin gate_gemm.What I ran into
None of this blocks the PR.
gate_up_nvfp4_mmaand changed no arithmetic, so that kernel's PTX digest moved (08cd504b) while its registers, shared memory and spill read the same, and every other entry's resource columns are equal. I did not repeat the three-round sitting; the short sitting above ran on this head and matches it. The fullptx-compareof this head against the timed commit did not run: the node's repository had no object for the commit it compares with, so the step stopped. Every gate and the spill check had already passed.sm_121a(CUDA_OXIDE_TARGET=sm_121a ./tools/mac-check.sh lint) reports seven warnings, the same seven as main: theswigluandproducthost launchers innvfp4mma.rs, each counted for the lib and the lib test, andgpu-gates/src/bin/shared/q38_combine.rs:111. None is in code this PR adds.quantize_nvfp4_32, which is a second launch per layer after the fused kernel. Packing the FP4 inside the epilogue needs each column's global scale, which depends on every row tile of the column, so it would need a cross-block reduction or a per-tile scale format. The top-k sum is main's.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.