Repository navigation
[Perf] [NVIDIA] fp8: Use FlashInfer b12x for block-fp8-as-MXFP8 linears on SM12x - #45262
Conversation
With --fp8-gemm-backend flashinfer_cutlass, block-fp8 weights served as MXFP8 always ran FlashInfer's CUTLASS MXFP8 GEMM. On SM120/SM121 FlashInfer also ships the b12x warp-MMA backend, which has small-M tiles and is faster at every M (4.4x at M=1 and 1.4x at M=8192 for the DeepSeek-V4.1-Flash shapes on RTX PRO 5000). Use it when FlashInfer reports it as supported and K % 128 == 0; keep CUTLASS otherwise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --fp8-gemm-backend flashinfer_cutlass, block-fp8 weights served as MXFP8 always ran FlashInfer's CUTLASS MXFP8 GEMM. On SM120/SM121 FlashInfer also ships the b12x warp-MMA backend, which has small-M tiles and is faster at every M (4.4x at M=1 and 1.4x at M=8192 for the DeepSeek-V4.1-Flash shapes on RTX PRO 5000). Use it when FlashInfer reports it as supported and K % 128 == 0; keep CUTLASS otherwise. Co-Authored-By: Claude Opus 5.5 <[email protected]> sgl-project#45262, ported byte-faithfully: cherry-pick -x of the single PR commit 1b3f16f landed CLEAN with zero conflicts (the hunk pre-image is byte-identical to ours; only its line numbers differ because of drift elsewhere in the +41/-163 file), 1 file +14. No fork adaptation, no test gating (the PR ships no test). VERDICT ON THE FLAGGED SHAPE CHECK -- NOT a bug. The sweep asked whether `weight.shape[1] % 128 == 0` tests K as the comment claims, or N. It tests K. Proof chain for the only route that reaches this dispatch: * fp8.py:_prepare_block_fp8_as_mxfp8 unpacks `n, k = layer.weight.shape` and never rewrites layer.weight (only the scale gets a swizzled copy, weight_scale_inv stays in place for the Triton fallback), so the weight on this route is the standard PyTorch (out_features=N, in_features=K). * fp8.py apply() passes `weight=layer.weight` unchanged (:1279/:1287). * flashinfer_mxfp8_blockscaled_linear then derives output_shape from weight.shape[0] (=N) and validates K with `k_w = weight.shape[1]` against input_2d.shape[1], and hands FlashInfer `weight.t()`. A (K, N) weight would raise "Input K=... does not match weight K=..." on every non-square layer, so the layout is settled by the code that already ships. * The two `Parameter(x.t())` transpositions in fp8.py (:1102 per-tensor static, :1184 dynamic requant) belong to other routes and never reach this dispatch. So the new gate reads exactly the reduction dim it documents; nothing to annotate. GATE AVAILABILITY (executed probes, both venvs, cc passed explicitly): flashinfer.mm_mxfp8.is_backend_supported exists in .venv2 (0.6.18) and in the prod venv (0.7.2); b12x reports True for cc 120/121 and False for 100/103 on both wheels, cutlass True everywhere, cute-dsl only 100/103. So the branch is selectable on this box's SM120 hardware with the wheel we run, and never fires on SM10x (where the old cutlass partial is kept). The call also mirrors the in-tree precedent two functions above (:722 cutedsl check, :753 auto-selection) using the same _raw_flashinfer_mm_mxfp8 handle and get_device_sm(). IMPORT SAFETY: _raw_flashinfer_mm_mxfp8 is imported under a module-level `if get_platform().is_blackwell and is_flashinfer_available()`, so a FLASHINFER_CUTLASS dispatch on a non-Blackwell host would NameError. That is pre-existing (identical usage at :722/:753) and unreachable in practice: every path that produces FLASHINFER_CUTLASS is guarded by the same two conditions, is_blackwell() checks capability majors [10, 11, 12] + CUDA >= 12.8 (utils/common.py:290) so SM120 IS Blackwell here, and the new `and` short-circuits on backend.is_flashinfer_cutlass() first, which is why the AMD gfx95 file (test_mxfp8_amd_gfx95.py, calls dispatch directly) is unaffected. INERT FOR PROD / OPT-IN AS REQUESTED: the route needs (a) a block-fp8 checkpoint with weight_block_size[1] == 32 and scale_fmt == "ue8m0" (can_serve_block_fp8_as_mxfp8), i.e. the DeepSeek-V4.1-Flash family -- not Qwen3.8-Flash-Next, which is [128, 128] blockwise and stays on the Triton block kernel -- and (b) --fp8-gemm-backend flashinfer_cutlass, while prod pins cutlass. So nothing changes for the fp8 arm today; when we run a dsv41flash-style checkpoint with flashinfer_cutlass on the 4x SM120 box we get b12x, which is what makes the A/B arm (b12x vs cutlass) possible. `keep_plain_weight_layout` layers and legacy (q, scale) tuple inputs keep the block kernel as before (mxfp8_view False), unchanged by this port. DISCOVERED WHILE READING (pre-existing, NOT introduced here, NOT fixed): fp8.py:1256-1267 adds extra_kwargs["pin_tactic"] whenever mxfp8_prefill_autotune_min_tokens is not None, but that attribute is only ever set for the flashinfer_cutedsl backend (:553-554), whose dispatched callable is `partial(flashinfer_mxfp8_blockscaled_linear, backend="cute-dsl", pin_tactic=True)` -- a second pin_tactic for the same parameter, i.e. TypeError: got multiple values for keyword argument, at the first prefill of >= 4096 tokens. It cannot fire on this stack (cutedsl needs SM100/103: is_backend_supported("cute-dsl", 120) is False, and prod pins cutlass), and neither the CUTLASS nor the new b12x callable can see it because min_tokens stays None for them. Left for an SM10x owner: the honest fix is a setdefault on the dispatch side, which changes tactic-pinning semantics of a feature I cannot exercise here (batch-invariance-adjacent), so guessing it would be worse than reporting it. TESTS (CUDA_VISIBLE_DEVICES=9, per-file, PYTHONPATH=worktree/python, .venv2 python, all rc=0, nothing regressed): test_flashinfer_autotune_gate.py 9P (entry-229 baseline) test_fp4_gemm_backend_sm120.py 12P (entry-225 b12x baseline; NVFP4 mm_fp4 b12x is a different family from this mm_mxfp8 route) test_fp8_utils.py 1F/2P/5S/5sub (the 1F = pre-existing TestInverseTransformScaleUe8m0::test_round_trip) test_flashinfer_trtllm_fp8_fallback.py 1F/6P/1sub (1F PROVEN pre-existing at 3251fbd in r-red) test_fp8_blockwise_linear_backends.py 22 skipped (CUDA-gated) test_mxfp8_amd_gfx95.py 4 skipped (non-AMD) test_resolution_hook_registry.py 10P import smoke sglang.srt.layers.quantization.fp8_utils OK on this host. GPU-window debt: b12x vs cutlass numerics + throughput for a block-fp8 ue8m0/[x,32] checkpoint on SM120 (the PR's 4.4x@M=1 / 1.4x@M=8192 claim on RTX PRO 5000 is unverified here), including whether pin_tactic=True is the right call for b12x (its small-M tiles are exactly the case where the autotuner would change reduction order) and the 22 skipped test_fp8_blockwise_linear_backends.py cases. (cherry picked from commit 1b3f16f)
|
I ran the GEMM on an RTX PRO 6000 Blackwell Max-Q (SM120, 188 SMs), and the kernel speedup holds on this card too. I timed 8 DeepSeek-V4.1-Flash dense linears at 14 values of M from 1 to 8192, 112 points, each in two separate runs. b12x is faster in both runs at 108 points, slower in both at one, and faster in one run and slower in the other at three. Its output matched CUTLASS bit for bit at every point. This is kernel time only; I didn't run end to end. The timed call is
Over all 112 points the median is 0.67. The one point where b12x is slower in both runs is wqkv_a at M = 256: 23.3 us against 21.2 us (+9.8%). The three M = 128 cells above 1 go different ways in the two runs, so I can't call them either way. On random weights and activations, b12x, CUTLASS and FlashInfer's SetupShapes are the full weights from the DeepSeek-V4.1-Flash safetensors headers. The two shared-expert rows are the unsharded (TP1) case. With DP8 attention, EP8 and no a2a backend, sglang main splits the shared experts 8 ways, so per rank shared down is 5120 x 288 and goes to CUTLASS under this PR's K % 128 check. I didn't time the per-rank shared shapes. Both backends are pinned under |
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] LGTM. Let's wait for the related CI.
|
/tag-and-rerun-ci |
|
[BBuf Review Agent] Could you merge the latest main into this branch? CI's maintenance gate won't run the tests until it does. |
|
/tag-and-rerun-ci |
2 similar comments
|
/tag-and-rerun-ci |
|
/tag-and-rerun-ci |
Motivation
With
--fp8-gemm-backend flashinfer_cutlass, block-fp8 weights served as MXFP8 always use FlashInfer's CUTLASS MXFP8 GEMM. On SM120/SM121, FlashInfer 0.7.2 also ships the b12x warp-MMA backend. It has small-M tiles and is faster at every M. FlashInfer's ownbackend="auto"already prefers it on SM12x.Modifications
dispatch_block_fp8_mxfp8_linear: when FlashInfer reportsb12xas supported for the device, use b12x when K % 128 == 0 and CUTLASS otherwise. Non-SM12x devices are unchanged.Accuracy Tests
Speed Tests and Profiling
8x RTX PRO 5000 72GB, DeepSeek-V4.1-Flash, DP8 attention + EP8, MXFP4 MoE.
Kernel latency (us, CUDA graph):
End to end, CUTLASS → b12x:
Validation of the combined branches
I validated a clean tree: upstream
a90e9c5dplus #42371 plus this PR and the three companion SM120 PRs (DeepGEMM metadata, b12x MXFP8, mHC BLOCK_K, RTX PRO 5000 configs). It ran on 8x RTX PRO 5000, DP8 attention + EP8, with--fp8-gemm-backend flashinfer_cutlass:Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #42735360824
Latest PR Test (Extra): ❌ Run #42735360887
Latest PR Test (AMD ROCm 10): ❌ Run #42735360743
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: