Repository navigation
gpu-gates: carry the GEMM contracts' exceptional range through the host transcriptions - #704
Conversation
…st transcriptions The GEMM epilogues walk a block in F32 and walk it again with scaled_sum when a step leaves the F32 normal range; the NVFP4 walk keeps that sum in F64 until the expert scale. The host transcriptions (gemm32's dot32 and dot32_nv, gate_gemm's dot_ref) still summed in F32 alone, so dot32_nv returned infinity where the kernel stores a finite value (K 64, codes 2, sub-block scales 0.5, d_a 2^120, expert scale 2^-120: 8128), and a step whose product falls under the normal range rounded differently from the kernel. All three now walk with one host transcription of scaled_sum in rounding.rs, the NVFP4 one in F64 as the kernel does. Its exceptional step is one fused F64 multiply-add, as the kernel's `inner * scale + acc` contracts to one; a separate product and sum would cancel two opposite steps to 0 where the kernel keeps their residual (K 64, sub-block dots (24384, 127) then their negation, sub-block scales (224, 2^-10), d_a (1 + 2^-23)·2^120, expert scale 2^-120: 2^-33). g32_nvfp4_dense checks both boundaries.
There was a problem hiding this comment.
Verdict: CLEAN: The host transcriptions preserve the device contracts' exceptional range and rounding.
Non-blocking
⚠ Complete the card evidence: crates/gpu-gates/src/bin/gate_gemm.rs:5304.
The pasted output uses stored_8128; this head emits stored_eq and adds the cancellation row. Attach both tested commit hashes and this head's just gate-gpu-gemm --case g32_nvfp4 output, including both boundary rows. This makes the card run traceable to the reviewed code.
Checked
Duplicates: 4 new functions checked by Grep. No duplicate host owner; the device implementation cannot run on the host. Dryer supplied no pairs.
Complexity: nvfp4_dense_case 48 → 69 adds a boundary-fixture stage. New scaled_sum at 20 implements one range decision in three stages: inner eligibility, F32 result, F64 fallback.
Silent failure: 0 new default/discard sites. Added fallible operations propagate errors; numeric and fault failures reach the case verdict.
Tests: mutation review covers dot32_nv's F64 accumulator, scaled_sum's fused fallback, and dot32/dot_ref's exceptional steps. Restoring F32 accumulation gives infinity; unfusing the cancellation gives zero; restoring either old subnormal epilogue gives bits 2 instead of 1. Assertions reject each mutant. The device rows also reject a dropped block or an unwritten output. The recipe selects the K-quant regression by name.
Gates: no threshold moved or case removed. Overflow, cancellation, subnormal, and zero-scale paths checked against the device rule. The GLM gate reuses the changed common transcription.
Escape catalog: no matching pattern.
Notes
Dryer did not run, as reported in diagnostics. Rust tests and card gates were not run during this review. Card evidence is incomplete because the PR body omits both tested commit hashes and output for the added cancellation row.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/gemm32.rs, crates/gpu-gates/src/rounding.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. |
GEMM gate의 host 계산이 kernel의 예외 범위 처리를 따르게 해서, 올바른 유한 결과를 gate가 틀렸다고 판정하던 문제를 고칩니다.
What and why
The GEMM gates compare each kernel output bit for bit with a host transcription of the kernel's contract. Three of those transcriptions (
dot32_nv,dot32andgate_gemm::dot_ref) still walked the blocks in plain F32. The production epilogue (scaled_sum) leaves F32 when an intermediate leaves the normal range and finishes in F64, and for NVFP4 it keeps the sum in F64 through the expert scale.Fixes #702. For K 64, weight codes 2, sub-block scales 0.5, activations
127 * 2^120and expert scale2^-120, the NVFP4 transcription overflowed to infinity while the kernel stores 8128, so the gate would have rejected a correct kernel. The same gap shows on the plain 32-value and K-quant paths where a step lands in the subnormal range: withd_a2^-149 and an inner sum of1.5 - 2^-24, the F32 transcription gives 2^-148 and the kernel gives 2^-149. The transcriptions came in with 2bf3a7d.crates/gpu-gates/src/rounding.rsnow holds one hostscaled_sumwith the production rule, and all three transcriptions walk with it. The NVFP4 one accumulates in F64 and storesscaled_sum([acc, 0], [scale, 0], 1, 0)as F32; the others keep an F32 accumulator and round each step. For inputs in the normal range the new walk gives the same bits as before, so existing gate rows keep their values. No kernel code changes.g32_nvfp4_densegets the boundary from the issue as one extra row (K 64, inputs127 * 2^120, scale2^-120): every output must store 8128 and match the contract bits. Three host tests pin the three transcriptions. Thegate-gpu-gemmrecipe's test filter now also nameskquant_contract_keeps_a_subnormal_step_exact, whichworkers_must_completedid not select, so that test runs with the recipe.Release notes: internal: the GEMM gates' host transcriptions follow the kernels' exceptional-range rule, so a correct finite NVFP4 result is no longer rejected. No user-visible change.
Code shape
rounding::scaled_sum, and the old F32 epilogue copies are gone.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line): the productionscaled_sum(crates/gpu/src/gemm/grouped.rs:115) is written with device intrinsics that cannot run on the host, so the gate's host version incrates/gpu-gates/src/rounding.rsis its independent transcription and the only host copy.What I ran
Host tests, before the fix (two of the three new tests fail):
After the fix:
GPU, on the machine below:
The recipe's first step runs
workers_must_completeand passes 3 tests. The new K-quant test passes under the same gate command with its name as the filter, and fails whendot_refgoes back to the old F32 epilogue:Not run:
cargo clippyand the contribution checks on this head, and the otherg32_*cases.Hardware
The NVFP4 gate cases ran with
BLOOMERY_ARCH=sm_86.What I ran into
Nothing here blocks this PR. No gate case yet exercises the K-quant range boundary on the GPU; the K-quant fix is covered by the host test only.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.