feat: run FP4 and MXFP8 quantization and FP4 MoE on SM80 to SM90 #9959
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.57) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #9959"
general
weight: 0.35
lesj0610
<!-- .github/pull_request_template.md -->
📌 Description
This PR runs the FP4 and MXFP8 quantize ops and the FP4 fused MoE on SM80 through SM90. Below SM100, the FP4 configurations of the flat MoE APIs (TRT-LLM,
cutlass_fused_moe, CuTe-DSL) and of the unified runner run on new kernels incsrc/w4a16_moe_sm80.cu. SM100 and newer keep their paths; SM75 and older are unchanged.Status: implemented and tested on SM80, SM86, SM89 and SM90 (see Tests).
Fused MoE on records
The kernels run BF16
mma.sync(FP16 with FP16 activations) on records: each expert's E2M1 codes and block scales packed together in MMA fragment order, built once byprepare_records_nvfp4_weightsorprepare_records_mxfp4_weights. Narrower activations are restored to BF16 exactly, and GEMM1's output is quantized to the GEMM2 input format that SM100 uses.| Weights × activations | APIs below SM100 |
|---|---|
| NVFP4 × NVFP4 (NVFP4 input, or 16-bit input quantized in the op; per-token scales, 4over6) | TRT-LLM, cutlass, CuTe-DSL W4A4,
RecordsNvfp4Config|| NVFP4 × BF16 or FP16 | TRT-LLM (BF16), cutlass, CuTe-DSL W4A16,
RecordsNvfp4Bf16Config(BF16) || MXFP4 × MXFP8 | TRT-LLM, cutlass, CuTe-DSL W4A8,
RecordsMxfp4Config|| MXFP4 × FP8 per tensor | TRT-LLM, cutlass |
| MXFP4 × BF16 or FP16 | TRT-LLM (BF16), cutlass,
RecordsMxfp4Config(BF16) || MXFP4 × FP8 per token, Humming-style from 16-bit input | cutlass |
| MXFP4 × MXFP4 |
RecordsMxfp4Config|On SM90, cutlass MXFP4 × 16-bit (
cutlass_w4a16) and Humming-style MXFP4 × FP8 per token keep their SM90 kernels, and the rest of the table runs on records. MXFP4 × MXFP4 is on the unified runner only, as on cuTile, since TRT-LLM's launcher rejects MXFP4 activations. Non-FP4 weights keep their existing paths, since records hold E2M1 codes.MXFP4 records keep each expert's block scales relative to its largest one, so
prepare_records_mxfp4_weightsraises if an expert's largest and smallest nonzero block scales are 2^30 or more apart (each half of a gated w1 on its own); in gpt-oss-20b the widest gap is 2^15, at TP 1, 2, 4 and 8. With FP16 activations, values in MXFP4 blocks whose scale is more than 24 binades below their expert's largest can round to FP16 subnormals or zero; BF16 keeps the full 2^30 range.SM100 and newer never reach the records code (the dispatch checks
major < 10), and the shared quantization sources change only underFLASHINFER_FP4_SW_CVT, which only the SM80 to SM90 modules define, apart from a new optional argument that SM100 callers leave null. The CUTLASS sources are untouched. Built for sm_100a, sm_103a, sm_120a and sm_121a,quantization.cuandfp4_kv_quantization.cugive the same SASS as main at 100465cb, function by function, and so do the two routing sources for sm_100a and the CUTLASS fused MoE objects for sm_90a and sm_100a.Performance on SM80
On SM80, records time divided by Humming time is 0.780–0.885 (geomean per case; denominator: Humming 0.1.19, a standalone kernel package, W4A16 with BF16 activations; below 1 means records is faster) on Qwen3-30B-A3B, gpt-oss-20b and Nemotron 3 Nano shapes, at the autotuner's tactic.
<details>
<summary>Timing details</summary>
records / Humming (denominator: Humming 0.1.19, W4A16 with BF16 activations), records at the tactic the autotuner picked, over 1, 16, 128, 1024 and 4096 tokens, plus held-out token counts that no tuning decision used:
| Shape | records path | records activations | Geomean | Held-out geomean |
|---|---|---|---|---|
| Qwen3-30B-A3B | cutlass W4A16 | BF16 | 0.780 | 0.725 |
| Qwen3-30B-A3B | cutlass W4A4 | NVFP4 | 0.815 | 0.763 |
| gpt-oss-20b | TRT-LLM MXFP4 × BF16 | BF16 | 0.827 | 0.792 |
| gpt-oss-20b | TRT-LLM MXFP4 × MXFP8 | MXFP8 | 0.865 | 0.824 |
| gpt-oss-20b | cutlass Humming-style | FP8 per token | 0.885 | 0.856 |
| Nemotron 3 Nano | TRT-LLM W4A16, valid sizes | BF16 | 0.782 | 0.743 |
| Nemotron 3 Nano | TRT-LLM W4A4, valid sizes | NVFP4 | 0.806 | 0.754 |
Each ratio pairs both arms in one process: CUDA graph replay, 80 MB written to L2 before every call, 5 warm-up calls, then 9 rounds of 20 calls in rotated order; per arm, the mean of the 9 round means after dropping the fastest and the slowest. The SM80 rounds were measured before this rule was chosen; the SM90 rule was fixed before its run. These SM80 timings predate the unified NVFP4 alpha change in 0b84ace1a and the gated epilogue change in d08e508b4.
Shapes: Qwen3-30B-A3B is E=128, top-8, hidden 2048, intermediate 768, SwiGLU. gpt-oss-20b is E=32, top-4, hidden 2880, intermediate 2880, SwiGLU with biases. Nemotron 3 Nano is E=128, top-6, hidden 2688, intermediate 1856 padded to 1920, ReLU2. Held-out token counts: 64 and 2048 for Qwen3-30B-A3B, 8 and 512 for gpt-oss-20b, 32 for Nemotron 3 Nano. Both arms time the whole MoE call after routing. The one ratio above 1 is gpt-oss-20b with MXFP8 activations at 1 token (1.019); the same shape with BF16 activations is 0.954 at 1 token.
Calls that need no extension input run the default module. The gpt-oss-20b rows above run through an extension module, since they carry biases.
</details>
<details>
<summary>What the records paths take</summary>
Each API takes the activations it accepts on SM100 for that pair, with limits in that API's units, plus biases, the LoRA delta and
act_outon TRT-LLM, per-expert input scales and[E, 2]alphas on cutlass,fc2_input_outand valid sizes as on SM100, expert parallelism, cutlassenable_alltoall, fused shared experts,do_finalize=Falseand precomputed routing. SwiGLU at default scalars and ReLU2 run the default module. Other activations, biases, LoRA, MXFP8 or FP8 input restore and GEMM2-input requantization build one extension module per combination. TRT-LLM also takes BF16 hidden states with NVFP4 weights, a pair that SM100's launcher does not offer but CuTe-DSL and the unified runner do. GeGLU withgemm1_clamp_limit, a TRT-LLMworkspace_bufferorrouting_metadataand, on the cutlass records path (not SM90's own CUTLASS kernels), aworkspace_bufferorprofile_idsraise below SM100, and activation types, input types,hidden_states_scale_layout, thetopk_idswidth and CuTe-DSL's expert count are checked as on SM100.CuteDslMoEWrapperhands its calls tocute_dsl_fused_moebelow SM100 and offers the autotuner the records tactics there. The trtllm-gen routing module now also builds for SM8x and SM90. Below SM90 it skips the cluster and cooperative kernels; SM90 picks them as SM100 does.The unified records runners take the views that the configs'
prepare_weightsbuild, and refuse a view whose recorded hidden size, intermediate size or gating doesn't match the layer's. The records runner hashes by its configuration instead of the per-call extension tensors, so the autotuner's cache hits across calls. For NVFP4 × NVFP4,RecordsNvfp4Runnercomputes one alpha per expert for each GEMM in the routing prep, dividing each weight global scale by the matching input global scale (1 if omitted or with per-token scales), so eager calls and graph replays use the same calculation, and a replay sees in-place updates to the scale tensors it reads. The tuning inputs build FP8 block scales from random bytes, since PyTorch has no random fill forfloat8_e4m3fn.With CUDA 12.8 or newer, since their software conversions use its E8M0 type, the AOT list prebuilds the records' BF16 and FP16 default modules for SM80 and SM90, about 1.1–1.2 MB each per jit-cache provider, compressed; the extension modules are JIT-only.
</details>
<details>
<summary>Quantization</summary>
On main,
fp4_quantize,nvfp4_quantizeandmxfp4_quantize(#7987),mxfp8_quantizewithbackend="cuda"(#7986) andsilu_and_mul_nvfp4_quantizeraise below SM100: their CUDA kernels compile only for__CUDA_ARCH__ >= 1000, and the CuTe-DSL kernels fail in ptxas there. This PR runs them on SM80 and up; below SM80 they still raise.FLASHINFER_FP4_SW_CVT. Only the SM80 to SM90 FP4 and MXFP8 modules and the records modules define it. SM8x skips the TMA path.target_inline_asmreplaces only the instructions the traced target lacks with software sequences: E2M1, E4M3 below SM89,mul.bf16x2below SM90, and 256-bit loads below SM100.nvfp4_kv_quantize: the KV-cache quantizer has its own E2M1 conversion, which trapped below SM100. Below SM100 it now uses the same software encoder.e2m1_and_ufp8sf_scale_to_float: on SM80 to SM89, main's PyTorch fallback raises for swizzled scales (the FP4 quantize ops' default layout) and multiplies UE8M0 scales by the global scale, which the SM90 and newer host op applies to E4M3 scales only. On SM80 to SM89 it now untiles swizzled scales before the fallback and applies the global scale to E4M3 scales only.cuda_fp8.hbit for bit over all 2^32 FP32 inputs, and the E4M3 and E2M1 decoders over all codes.</details>
Performance on SM90
On SM90, records time divided by Humming time is 0.938–1.194 (geomean per case; denominator: Humming 0.1.19, W4A16 with BF16 activations; below 1 means records is faster), on the same shapes, at the autotuner's tactic. Records is faster at 1 and 16 tokens in every case, and at 128 tokens in every case except gpt-oss-20b (1.036 with BF16, 1.065 with MXFP8).
<details>
<summary>Timing details</summary>
records / Humming (time; denominator: Humming 0.1.19, W4A16 with BF16 activations), records at the tactic the autotuner picked, over 1, 16, 128, 1024 and 4096 tokens, plus the same held-out token counts as on SM80. Each arm: 15 rounds x 20 calls in rotated order; the first 3 rounds are warm-up and dropped, then the trimmed mean of the other 12 round means (the 2 fastest and 2 slowest dropped). The rule was fixed before the run.
| Shape | records path | records activations | Geomean | Held-out geomean |
|---|---|---|---|---|
| Qwen3-30B-A3B | cutlass W4A16 | BF16 | 0.938 | 0.989 |
| Qwen3-30B-A3B | cutlass W4A4 | NVFP4 | 0.967 | 1.035 |
| gpt-oss-20b | TRT-LLM MXFP4 × BF16 | BF16 | 1.165 | 1.218 |
| gpt-oss-20b | TRT-LLM MXFP4 × MXFP8 | MXFP8 | 1.194 | 1.252 |
| Nemotron 3 Nano | TRT-LLM W4A16, valid sizes | BF16 | 0.959 | 0.855 |
| Nemotron 3 Nano | TRT-LLM W4A4, valid sizes | NVFP4 | 0.963 | 0.858 |
Same shapes as on SM80. On SM90 the cutlass Humming-style pair keeps its SM90 kernel, so it has no row here. These SM90 timings were run at 50588a0a6. The later commits were not timed on SM90: dd1ffd01f skips building the (token, k) row map on TRT-LLM records calls that don't return it, and the twenty-five after it add input checks, type fixes, an import split, the review and test fixes (418441e90, de98296cc, dbeb40815, 0b84ace1a, c6f6c8bb6, 800e8bb36, 4806f1234, 78407c7e7, cd6a8e2c4, 972f3058e, 1d88c60d9, 0d1f6ee48, 6c593733e, 4c29171d9, d08e508b4), the FP16 records module in the AOT list (9a332953c), a test rewording (b97be8cde), a docstring note (14ea1b4eb) and the CUDA 12.8 condition for the records modules in the AOT list (576cb7ed2). Of these, d08e508b4 changes GEMM1's epilogue in the extension modules: under
[E, 2]alphas, a gated expert's linear half takes its own alpha from its first product, instead of the gate's alpha and then their ratio.</details>
Serving through vLLM
Served through vLLM at TP 1, records against vLLM's Humming MoE backend (humming-kernels 0.1.19), with the same build and server flags and only
--moe-backendchanged: Qwen3.6-35B-A3B-NVFP4 onflashinfer_cutedsland gpt-oss-20b onflashinfer_trtllm(MXFP4 × BF16). records / Humming (denominator: Humming; below 1 means records is faster), each arm's fastest of 5 rounds:| Arch | Model | 1 user, TPOT | 16 users, time | 32 users, time | 8k prompt, TTFT |
|---|---|---|---|---|---|
| SM80 | Qwen3.6-35B-A3B | 0.939 | 0.885 | 0.895 | 0.933 |
| SM80 | gpt-oss-20b | 0.936 | 0.863 | 0.910 | 0.996 |
| SM90 | Qwen3.6-35B-A3B | 0.944 | 0.941 | 0.965 | 1.034 |
| SM90 | gpt-oss-20b | 0.939 | 1.015 | 0.989 | 1.216 |
On SM90, records is faster at 1 user on both models and at 16 and 32 users on Qwen3.6-35B-A3B. It is slower on the 8k prompt on both models, by the most on gpt-oss-20b (1.216).
<details>
<summary>Serving details</summary>
vllm bench serveon the random dataset with seed 0 and--ignore-eos. 1 user: 16 prompts of 256 input and 64 output tokens at concurrency 1, mean TPOT. 16 and 32 users: 64 and 128 such prompts at concurrency 16 and 32, benchmark duration. 8k prompt: 4 prompts of 8192 input tokens and 1 output token at concurrency 1, mean TTFT. Server: CUDA graphs up to batch 32,--max-num-seqs 32,--max-num-batched-tokens 8192,--max-model-len 9216, prefix caching off, no MTP, and a fresh FlashInfer autotune cache per server. Each server ran a warm-up, then 5 rounds of the four points. The rules were fixed before the runs. With the trimmed mean of the 5 rounds (fastest and slowest dropped) instead of the fastest round, the ratios are, in table order: SM80 Qwen3.6-35B-A3B 0.939, 0.894, 0.897, 0.934; SM80 gpt-oss-20b 0.939, 0.865, 0.905, 1.004; SM90 Qwen3.6-35B-A3B 0.932, 0.965, 0.975, 1.046; SM90 gpt-oss-20b 0.936, 1.012, 1.004, 1.220.Only the MoE layers differ between the arms. Qwen3.6-35B-A3B's dense NVFP4 layers run on the linear kernel that vLLM picks, the same in both arms: Marlin on SM80 and Humming on SM90.
On SM80 the two arms ran at the same time on two GPUs of the same model. On SM90 the four servers ran one after another on one GPU, and the benches ran through the same
vllm bench servecode in one client process per server. SM80 was served at d08e508b4 and SM90 at 14ea1b4eb. The two commits after d08e508b4 change only a docstring (14ea1b4eb) and the AOT list's CUDA condition (576cb7ed2).GSM8K (30 questions, as a functional check), records / Humming accuracy: SM80 Qwen3.6-35B-A3B 0.367 / 0.400, gpt-oss-20b 0.367 / 0.333; SM90 Qwen3.6-35B-A3B 0.300 / 0.267, gpt-oss-20b 0.367 / 0.300.
</details>
🔍 Related Issues
Extends #3264, #3448 and #5152 below SM100.
Refs #7980: on SM80 through SM90 the quantize ops it names now run instead of raising.
#9837 adds a separate SM90 NVFP4 × BF16 fused MoE op; this PR instead runs the existing FP4 MoE APIs below SM100. #8402 (draft) rejects the FP4 quantize ops below SM100, which this PR runs.
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reason: <!-- e.g. cross-cutting change to shared infrastructure -->
Suggested CI test targets (optional; paths under
tests/, whitespace-separated — a startingpoint for
@flashinfer-bot run <targets>//bot run <targets>, reviewers may adjust):tests/moe/test_records_nvfp4_moe.py tests/moe/test_unified_moe_records.py tests/moe/test_unified_moe.py tests/moe/test_unified_moe_pack_contract.py tests/moe/test_trtllm_gen_routing.py tests/moe/test_trtllm_fp4_routed_moe_routing_metadata.py tests/moe/test_trtllm_cutlass_fused_moe.py tests/utils/test_fp4_quantize.py tests/utils/test_fp4_quantize_padding.py tests/utils/test_fp4_dispatch.py tests/utils/test_mxfp8_dispatch.py tests/utils/test_fp8_quantize.py tests/utils/test_fp4_kv_quantization.py tests/utils/test_nvfp4_per_token_quantize_large_m.py tests/quantization/test_nvfp4_dequantize.py tests/trace/The counts below are from SM80 at d08e508b4. Before 418441e90, the records, unified records, quantize and trace files also ran on SM86 and SM89: records 91 passed, unified records 12 passed, and the
tests/utilsandtests/tracecounts below, less the fourtest_fp4_kv_quantization.pytests that d08e508b4 adds.tests/moe/test_records_nvfp4_moe.py(new): 98 passed. It checks the flat-API rows of the table against an FP32 reference and across APIs bit for bit, plus tactics, expert parallelism, valid sizes and an autotuned call with FP8 block scales.tests/moe/test_unified_moe_records.py(new): 18 passed. It runs the unified-runner rows of the table against the same reference, and an expert shard routed from logits.tests/moe/test_unified_moe.py,test_unified_moe_pack_contract.py,test_trtllm_gen_routing.pyandtest_trtllm_fp4_routed_moe_routing_metadata.py: 1238 passed, 200 skipped.tests/utils/: 2130 passed, 940 skipped, one process per file as CI runs them.tests/quantization/test_nvfp4_dequantize.py: 8 passed, 6 skipped.tests/trace/: 8 passed.On SM90, at 50588a0a6:
test_records_nvfp4_moe.py76 passed, 15 skipped ("SM90 runs its CUTLASS Humming kernels");test_unified_moe_records.py12 passed; the four unified and routing files 1238 passed, 200 skipped; thetests/tracefiles 8 passed;tests/moe/test_trtllm_cutlass_fused_moe.py -k "hopper or humming"35 passed, 1 skipped. The seventests/utilsquantize files, one pytest process per file: 2167 passed, 899 skipped, 0 failed.An earlier SM90 run of the same seven files on the same FlashInfer head, all in one pytest process, had 48 failures (28 in
test_fp4_kv_quantization.py, 16 intest_fp8_quantize.py, 3 intest_mxfp8_dispatch.py, 1 intest_fp4_quantize.py); that single-process run was not repeated.<details>
<summary>Tolerance</summary>
Most records outputs quantize GEMM2's input, and the reference does so from FP32 while the kernel does so from BF16-rounded values, which flips some codes. Two references that differ only in that rounding are up to 0.0241 apart in relative error, the same size as the kernel's largest gap to the reference (0.0248). Against an unquantized reference, the kernel and an ideal quantized reference land at the same distance (0.1547 and 0.1546). The records tests therefore compare at 3e-2;
test_from_logitsandtest_mxfp4_w4a16, whose GEMM2 input is not quantized, keep 2e-2. Tactics that fuse GEMM2's NVFP4 input quantization into GEMM1 round GEMM1's output to BF16 before the activation, as the CUTLASS path does, and the others keep it in FP32. Under MXFP4 × MXFP4's E8M0 scales the codes that this flips cost up to 7e-2, so the unified test compares each output against whichever of the two references is closer.</details>
Served through vLLM on SM80, Qwen3.6-35B-A3B (NVFP4 W4A16, CuTe-DSL, MTP, TP 2), Nemotron 3 Super (NVFP4, TRT-LLM, MTP, TP 2), gpt-oss-20b (MXFP4, TRT-LLM) and Gemma 4 26B-A4B (NVFP4 GeGLU, TRT-LLM, and weight-only on CUTLASS, MTP) run on records. Teacher-forced on the 1319 GSM8K reference solutions, records' NLL per token matches vLLM's Humming MoE backend: 0.53277 against 0.53271 for Qwen3.6-35B-A3B and 4.11556 against 4.11341 for gpt-oss-20b. Gemma 4 is sensitive to FP4, so its weight-only run is also compared with the BF16 checkpoint: 1.00682 for records and 1.06806 for Humming, against 1.02756. On SM90 (TP 1), Qwen3.6-35B-A3B (NVFP4 W4A16, CuTe-DSL, MTP) and Gemma 4 26B-A4B (NVFP4, TRT-LLM, and weight-only on CUTLASS, MTP) serve end to end through vLLM; NLL was not measured there.
🔬 Experimental Track
<!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends").
Leave this section untouched for normal PRs. -->
flashinfer/experimental/and/or an@flashinfer_experimental_api. Tracking issue: #- [ ] The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release.
- [ ] Core changes are limited to a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff).
- [ ] Tests live in
tests/experimental/and were validated on the intended hardware; a runnable example is included.- [ ] Nothing is registered in
flashinfer/aot.py, and no experimental backend is reachable frombackend="auto"withoutFLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1. (Calling an@flashinfer_experimental_apior naming a backend explicitly is itself the opt-in and needs no environment variable.)- [ ] Test scope declared below. The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows.
<!-- Required for experimental PRs. Replace the commented lines below with your targets.
Do not delete the fence or change its
experimental-teststag — the experimental-trackwatcher reads it verbatim to decide which targets to ask CI for. -->
``
experimental-tests
``One target per line: a directory or a file. (A pytest ::selector is not
supported -- the sharding runner cannot consume one.) Must be under
tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.
# tests/experimental/test_my_backend.py
tests/experimental/my_backend/
# Declaring the whole tree (tests/experimental/) is allowed but means every
experimental PR pays for every other feature's tests, in every matrix cell.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Added records-based NVFP4 and MXFP4 MoE support on SM80–SM90, including additional weight formats, activations, and routing options.
Added W4A16 MoE support for BF16 and FP16 on SM80–SM90.
Extended FP4, MXFP8, and FP4 KV quantization support to SM80-class GPUs.
Bug Fixes
Improved FP4 conversion and MoE routing compatibility across GPU architectures.
Documentation
Updated API and hardware support documentation to reflect expanded quantization and MoE capabilities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->