Add NVFP4 RHT Support for SM120 and SM121 - #3300
Conversation
Greptile SummaryThe PR adds a dedicated SM120/SM121 fused NVFP4 columnwise RHT path while retaining existing dispatch behavior on other architectures.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the post-RHT amax now follows the same BF16 MMA arithmetic as the fused transform, and distributed reduction occurs before quantization consumes the resulting read-only amax. Important Files Changed
Sequence DiagramsequenceDiagram
participant Q as NVFP4Quantizer
participant A as Hadamard amax kernel
participant D as Distributed MAX
participant F as SM12x fused RHT+quantize
Q->>A: Compute rowwise and post-RHT columnwise amax
A-->>Q: Local amax values
Q->>D: All-reduce amax when enabled
D-->>Q: Global amax values
Q->>F: Input, RHT matrix, and reduced amax
F->>F: "BF16 A @ H via warp MMA"
F->>F: Derive block scales and FP4 codes
F-->>Q: Quantized rowwise/columnwise outputs
Reviews (9): Last reviewed commit: "perf(nvfp4): quantize SM12x RHT fragment..." | Re-trigger Greptile |
|
Good catch. The SM120/SM121 ATen path was initially reusing the columnwise amax produced earlier by |
|
Addressed the distributed-reduction issue in c7a3b2a. On SM120/SM121, the ATen-derived rowwise and post-RHT columnwise local amax values are now written during the existing amax-computation phase, before |
Signed-off-by: tony <864832769@qq.com>
Signed-off-by: tony <864832769@qq.com>
for more information, see https://pre-commit.ci
Signed-off-by: tony <864832769@qq.com>
c7a3b2a to
9142e86
Compare
for more information, see https://pre-commit.ci
Signed-off-by: tony <864832769@qq.com>
|
Added SM120/SM121 regression coverage in ea87075. The new tests (1) compare the stored post-RHT columnwise amax exactly against the ATen/reference RHT output with random-sign masking both disabled and enabled, and (2) exercise two-rank NCCL amax reduction with different rank-local maxima to verify the ATen-derived value is reduced globally before quantization. The distributed case skips unless two SM120/SM121 GPUs are available. |
Signed-off-by: tony <864832769@qq.com>
|
Implemented solution A in 7a0a0d0: the SM120/SM121 unfused path now materializes the ATen RHT intermediate once during post-RHT amax computation, derives local amax from that exact buffer, carries it across distributed MAX reduction, and reuses it for nvte_quantize_v2 instead of running transpose+matmul a second time. Validation on Spark GB10 (SM121):
The post-RHT amax remains derived before distributed reduction and from the same BF16 RHT data that is subsequently quantized. |
Signed-off-by: tony <864832769@qq.com>
11a9033 to
434f242
Compare
|
Implemented the SM120/SM121 no-TMEM fused RHT+NVFP4 quantize path in 434f242. Key points:
Spark GB10 (SM121) validation:
|
for more information, see https://pre-commit.ci
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Signed-off-by: tony <864832769@qq.com>
|
SM120/121 fused RHT update: replaced the per-thread scalar 16-point Hadamard reduction with BF16 warp MMA (WMMA), while matching ATen accumulation/rounding order for both small and large GEMM regimes. Spark GB10 (SM121) validation:
Square BF16 columnwise-only benchmark (post-RHT amax/sign mask), median us:
Compared with the preceding scalar-fused implementation, changes are -13.39%, +1.68%, +2.09%, -6.65%, -2.37%, and -1.86% respectively (positive means faster). Thus MMA improves 2K/4K slightly, but the current shared-memory staging and two-pass K=8 compatibility path regress the other sizes; this is correctness-first and not yet a net performance win. Commit: f9e28f4 |
Signed-off-by: tony <864832769@qq.com>
|
Updated the SM120/121 numerical contract to match Transformer Engine's native Hadamard implementation rather than the architecture-dependent ATen/cuBLAS result. Key changes (
Spark GB10 / SM121 validation:
Single-K16 median latency (us):
Relative to the two-masked-K8 implementation: 1K +2.66%, 2K +1.82%, 4K -5.13%, 8K -2.82%, 16K +0.47%, 32K +0.26% (positive means faster). Variance/memory traffic dominates at the larger sizes, but the redundant masked MMA work is now removed and the arithmetic exactly matches TE native K16 behavior. |
Signed-off-by: tony <864832769@qq.com>
|
Implemented all four follow-up SM120/121 RHT staging optimizations in
RHT-only extra dynamic shared memory is reduced from about 14.5 KiB/block ( Spark GB10 / SM121 validation:
Two final benchmark runs (median us; run-to-run variance is visible):
Using the second run versus the previous staged single-K16 version gives: 1K +10.67%, 2K +1.86%, 4K +2.71%, 8K +1.24%, 16K -0.14%, 32K +0.01% (positive means faster). Large shapes remain dominated by global-memory/TMA traffic. |
Summary
nvte_hadamard_transformpath on other architecturesMotivation
The fused RHT+quantize kernel is not eligible on SM120/SM121. The existing unfused BF16 MMA Hadamard kernel is mathematically equivalent to the Python reference, but its accumulation order can differ by one BF16 ULP. Values near FP4 rounding thresholds can therefore produce different exact FP4 codes or E4M3 scales.
Using the same block-matmul formulation as the reference on SM120/SM121 eliminates that numerical-path mismatch while leaving other architectures unchanged.
Validation
On NVIDIA GB10 (SM121):
tests/pytorch/nvfp4/test_nvfp4_rht_quantize_exact.py: 200 passedStandalone Hadamard matmul checks were also run for FP32, TF32, FP16, and BF16; all were deterministic across repeated runs and produced finite outputs.