Repository navigation
Conversation
…ng/finalize and NVFP4 MoE GEMM for sm90
…ntize_act threads per row adapt to K
…arge T; activation quantizer 8 lanes per block
…MA, warp-specialized, PDL after the quantizer)
…rt GEMMs (fewer dequant instructions)
…roughput at large M, latency at small M)
…egister ring refilled after use
…keys, softmax on the FP32 scores)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
hopper_nvfp4, the sm90 kernels for running a Blackwell NVFP4 MoE inference recipe on Hopper with the same numerics. The recipe is vLLM onlinenvfp4_per_tokenMoE +mxfp8linears on the FlashInfer trtllm-gen backend.quantize_weight: vLLMscaled_fp4_quantas used by the online MoE weight quantization.quantize_act: FlashInfer per-token NVFP4 with 4/6 block-scale selection and IEEE division (FLASHINFER_NVFP4_4OVER6=1,FLASHINFER_DISABLE_FP4_QUANT_FAST_MATH=1). It reproduces the module's fast-math (FTZ) FP32 ops with explicit.ftzPTX. Each 16-element block runs on one lane (large inputs) or eight (small inputs, for latency), keeping the reference's sequential error-sum order.quantize_mxfp8/mxfp8_fake_quant: FlashInfer cute-dsl MXFP8.cvt.rn.satfinite.e2m1x2is replaced: a software RNE/satfinite conversion (NaN -> 0x7, -0 -> 0x8, as measured on B200).route: RenormalizeNaive = top-k of the router logits (ties go to the lower expert), then softmax over the k, with fast-mathex2.approx/div.approxand the warp butterfly sum. Takes BF16 or FP32 logits and, like trtllm-gen'sTopKRedType, ranks them in their own type (32-bit keys for BF16, 64-bit for FP32).moe_finalize: FMA accumulation in slot order, using the small-batch even/odd split when FlashInfer would.moe_gemm(CUDA,repack_weightlayout): grouped NVFP4 x NVFP4 expert GEMM with weights as the A operand (16 output features per tile) and tokens as B. block_m 8/16/32 (decode) stream the NVFP4 activations throughmma.sync; block_m 64/128 (prefill) dequantize the activations to FP16 once (dequant_act) and run WGMMA with 2 warpgroups and a cp.async ring. Both operands are dequantized exactly to FP16 (E2M1 by bit placement:repack_weightpositions each weight code's sign and magnitude so every A-fragment register takes one or two shift/mask steps; weight scales withcvt.e4m3x2; E2M1 x E4M3 has at most 6 significant bits), accumulated in FP32, and finished with the prime-rl trainer's NVFP4 epilogue (fused SwiGLU for GEMM1).nvfp4_moe_gemm(Triton, canonical layout) is the reference it is checked against.mxfp8_linear(repack_mxfp8_weightlayout): MXFP8 x MXFP8 linear for decode-sized inputs (up to 32 rows), with E4M3 weights at half the bytes of BF16.xgoes throughquantize_mxfp8, and the GEMM is launched with programmatic dependent launch, so its weight prefetch overlaps the quantizer.Verification
tests/hopper_nvfp4/test_b200_equivalence.py: quantizer outputs match sha256 hashes of outputs captured on a B200 (FlashInfer 0.7.3 / vLLM 0.34). Passes on H200.mxfp8_fake_quantvs dequantizingquantize_mxfp8's outputs in PyTorch (89M values, M 1-4096, partial CTAs, block magnitudes from 1e-30 to 1e30, all-zero blocks): 0 differ.moe_gemmvs float64 reference and vs the Triton GEMM (Qwen3.6 shapes, T 1-4096, every block_m): 0 BF16 ulps.mxfp8_linearvs float64 reference on the Qwen3.6 dense shapes: M 1-32 (the sizes it serves) at most 2 BF16 ulps, M 64 at most 32; the cuBLAS GEMM on the dequantized operands reaches 14 and 64. In both, at most about 1e-4 of the outputs differ at all.routeon FP32 router logits vs trtllm-gen on a B200 (vLLM 0.34 with FP32 Qwen3.6 router logits, layers 0/20/39, T 1-4096, plus 8th/9th-place ties and duplicated columns): ids in kernel column order and weights bitwise equal on all 30 captures. The BF16 path is unchanged bitwise.