Repository navigation
gemm, placement: the prompt GEMM admits NVFP4, its store scaling each slot by its expert's tensor scale - #545
Conversation
… slot by its expert's tensor scale
There was a problem hiding this comment.
Verdict: CLEAN: No behavior defect or proven quality defect survives the checks of the changed paths.
Non-blocking
⚠ Make the timed A/B reproducible: crates/gpu/src/gemm/gemm32.rs:809 adds one 4-byte scale read per active NVFP4 GEMM block [derived]; the body reports 16 extra shared-memory bytes per block on sm_121. The occupancy/geometry class requires an owning gate and timed A/B. Gate results are supplied, but the timing evidence gives only a ratio range from bench_nvfp4, whose source is absent. Attach the harness, per-shape alternating-run output, exact model filename and commands identifying the measured commits.
Checked
Duplicates: shape checks reuse Nvfp4Stack::experts. Dryer reported 0 pairs; gpu-gates was excluded from its search.
Complexity: nvfp4_routed_case 42→46 adds uploads and a rerun assertion; nvfp4_dense_case 46→48 and refusals 43→45 add upload error paths. No new model-dispatch branch.
Silent failure: invalid stack shapes return named errors. File NaN scales are refused at load. Refused route slots receive NaN outputs.
Tests: static mutation audit. Reading expert 0's scale at gemm32.rs:472 makes the routed contract assertion red (the body reports 14 failing rows). Dropping the multiplier at :487 fails the dense contract check. Skipping experts at :1144 fails the scale-count refusal. Removing card_buffers' dense scale buffer fails its size assertion; returning None for NVFP4 fails the admission assertion.
Gates: dated PINs cover admission, the dense scale buffer, replacement of the NaN-scale clause and the unsafe ratchet. No numeric band moved.
Adversarial checks: the final 16-row slab still stages its scale outside the active-warp branch. An entirely refused route exits before reading the shared scale. Stack rows and scale count agree with the route's expert count.
Escape catalog: C1–C4 do not match the changed code. No ledger lessons are in force.
Notes
Static review only; no build or GPU gate was run here. The PR supplies GB10 gate results and a FAIL-first scale-index mutant.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/arch/nemotron_h_moe/prefill.rs, crates/gpu/src/gemm/gemm32.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. |
프롬프트 배치에서 라우팅된 NVFP4 전문가를 기존 gemm_nvfp4p 커널로 계산하도록 합니다.
Part of #493 and #495.
Routed NVFP4 experts now run through the existing
gemm_nvfp4pprompt GEMM, becausekernels::gemmaccepts NVFP4. The prompt GEMM takes routed and dense NVFP4 weights with a scale per expert: its gate_gemm cases pass, its spill does not grow and no measured shape is slower than main.What and why
Main runs NVFP4 stacks only through the decode gemv. A prompt batch with routed NVFP4 experts has no GEMM entry, although each expert already has its own f32 tensor scale.
placement/kernels.rs:gemm(NVFP4)returnsGemmEntry::Nvfp4, and the pin test gains the pair.gpu/gemm/gemm32.rs,kernels32.rs:Gemm32Weight::Nvfp4Planesholds anNvfp4Stack, andgemm_nvfp4ptakes one scale per expert. The tile's expert scale is staged in one shared word before the K walk and read once for the stores, so the kernel needs no register for the expert index during the walk. The launcher check for NVFP4 is one call toNvfp4Stack::experts(madepub(crate)inmxfp4_sel.rs), the owner of the K % 64, plane shape, whole-expert and one-scale-an-expert checks, so the launcher keeps no copy of them.gpu/weights.rs,placement/placement.rs: a dense NVFP4 tensor uploads its scale as a one-element device buffer, which the card segment counts (4 bytes).nemotron_h_moe/prefill.rs: the dense NVFP4 prompt projection hands its planes to the GEMM as a one-expert stack.gate_gemm.rs:g32_nvfp4_routedgives each expert its own scale, compares every slot withdot32_nvunder that scale and repeats the launch.g32_refusegainsnvfp4_scales_count.g32_refuseno longer hasnvfp4_scale_nan. A NaN scale is refused by name at load, inweights::tensor_scales, andgate_nvfp4tests that refusal (a densenantensor and theexpert_nan_*stacks). The launch now owns only the scale count, so the clause becamenvfp4_scales_count. The change carries aPIN(2026-10-20)line before the new clause ingate_gemm.rs.card_buffersplacement test now expects[4*128, 4*16, 4]for a dense NVFP4 tensor, because its one scale is now a counted device buffer. It carries aPIN(2026-10-20)line.The maintainer's open #344 redesigns
gemm_nvfp4p. This PR does not touch the kernel's inner loops and moves only where the scale is read, which keeps the overlap with #344 small.Release notes: Added: Routed NVFP4 experts run in the prompt batch through
gemm_nvfp4p.Code shape
Nvfp4Stack::expertsfor its checks instead of repeating them.Nvfp4Stack::experts. The gate's single-useexpert_scaleshelper is gone, with its map written inline at its one call.nvfp4_scales_count), and the four NVFP4g32_refusecases still refuse, with the error text now coming fromNvfp4Stack::experts, and an id past the stack raisesexpert_id.tools/unsafe-ratchet.txtgoes fromgpu 1980togpu 1981: staging writes the shared word and the store reads it, two blocks, each with a SAFETY line.cargo fmtandtools/check-unsafe.shran on what I touched, with the new pin value above.Duplication found or removed: none.
What I ran
The oracle is
dot32_nvincrates/gpu-gates/src/gemm32.rs, whichgate_gemmcompares every slot against, with each expert's own scale. The gate also checksdecode_vs_ggmlagainst the Qwen3-30B-A3B Q4_K_M reference model. Commands on the GB10 machine, from the repository root withBLOOMERY_ARCH=sm_121:bench_nvfp4is a measurement-only harness that is not part of this PR. It runs the Qwen3.8 FP4-Local prompt shapes: 512 experts, top 10, gate 640 by K 2560, down 2560 by K 640 and a dense 2560 by 2560, each at 512 and 2048 tokens. Each arm captures 64 launches in a graph and takes the minimum over 7 rounds. The table gives the median of 4 runs per side, main and head alternating in one sitting. Main was built at5c5c9355cand the head atfc26e826. The head of this PR isb3f288d5, rebased onto upstreamd322507e. The kernel code is unchanged sincefc26e826, so the timing is carried and not measured again. The FAIL-first mutant and the sm_86 spill comparison also ran on thefc26e826tree.The sm_86 spill comes from
ptx-compareagainst the base, which listsgemm_nvfp4pas the only changed entry with no spill change, and from the 0 pinned intools/ref/ptx-shapes.tsv. On sm_121 the kernel already spills 40 B on main, and this PR does not add to it.What I ran into
This does not block the PR.
tools/ref/ptx-shapes/sm_121-cc12.1.tsvhas nogemm_nvfp4prow, so the 40 B sm_121 spill is not pinned on main or here. I did not add the row because other open PRs edit the pin files. Thegenerate_ds41andgate_qwen3vl_towerspill scans did not run on the GB10 machine.Hardware
DGX Spark (GB10), measured at head
b3f288d5against maind322507e.nvidia-smireportsNVIDIA GB10, 595.84, CUDA 13.3(name, driver, CUDA; compute capability 12.1, ptxas 13.3.73,BLOOMERY_ARCH=sm_121).just gate-gpu-gemm --case g32_nvfp4builds and runsgate_gemm. The recipe's container wrapper was not available on this machine, so I ran the same binary directly with--case g32_nvfp4: 32 rows PASS (17 dense, 15 routed), rc 0.--case g32_refuse: PASS, rc 0. The four NVFP4 casesnvfp4_k_not_64,nvfp4_qs_short,nvfp4_e_shortandnvfp4_scales_countare eachrefused.ptx-scan gate_e2e gemm_nvfp4p, sm_121:d322507eb3f288d5The 16 extra bytes of shared memory and the one extra scalar load are the staged scale word. Registers and spill are the same. The sm_86 spill comparison ran on an RTX 5090 with the cc 12.0 JIT.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.