Skip to content

[Perf] [SM120] gemm: Speed up decode-sized MXFP8 linears with a Triton GEMM - #42865

Closed
ormandj wants to merge 7 commits into
sgl-project:mainfrom
ormandj:sm120-mxfp8-skinny
Closed

ormandj wants to merge 7 commits into
sgl-project:mainfrom
ormandj:sm120-mxfp8-skinny

Conversation

@ormandj

@ormandj ormandj commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On SM120, block-FP8 checkpoints with 32x32 UE8M0 scales (DeepSeek-V4.1-Flash) can be served as MXFP8 through FlashInfer's CUTLASS mm_mxfp8. Its SM120 configs have no split-K, so at decode / speculative-verify row counts the weight read is spread over very few CTAs. For example, wqkv_a (N=1792, K=5120) runs with a 128-wide N tile on 14 CTAs of a 188-SM RTX PRO 6000 and reads its 9 MB weight at about 0.6 TB/s.

Modifications

  • kernels/ops/gemm/sm120_mxfp8_skinny_gemm.py (registered as gemm.sm120_mxfp8_skinny_gemm): Triton MXFP8 GEMM for small M. It uses tl.dot_scaled (native block-scaled MMA, E4M3 with UE8M0 scales, FP32 accumulate) and can split K across CTAs. Split-K partials go to an FP32 workspace and the last CTA of each N tile adds them in split order, so the result is deterministic. Per-layer arrival counters reset themselves, so the kernel is CUDA-graph safe, and a weight reload refills the layer's scale and counter buffers in place, so graphs captured before the reload stay valid; the counters must be a contiguous int32 tensor on the activation's device, zero on entry (not checked); a wrong dtype, device, layout or size raises ValueError. BN, BK and SPLIT depend only on (N, K), so a row's result does not change with the batch size. The weight is read in its checkpoint layout (E4M3 + FP32 power-of-two 32x32 block scales); nothing is copied. The activation is either taken prequantized as Mxfp8SwizzledInput (128x4-swizzled UE8M0 scales) or quantized in-kernel from BF16, FP16 or FP32. In-kernel quantization reuses the UE8M0 helper of the fused RMSNorm+MXFP8 epilogue and is bit-identical to flashinfer.mxfp8_quantize with the CuTe-DSL backend, which SGLang calls (tested for BF16).

  • Fp8LinearMethod: a block-FP8-as-MXFP8 linear uses the kernel only when all of these hold:

    • the GPU is SM 12.0;
    • the weight block is 32x32;
    • (N, K) is in the tuned table;
    • the call has at most 16 rows, no bias, and a BF16 or FP16 activation (or Mxfp8SwizzledInput);
    • --enable-deterministic-inference is off. Below and above 16 rows the two kernels reduce in different orders, so a row's result would depend on the batch size.

    Everything else keeps the existing MXFP8 backend. SGLANG_ENABLE_SM120_MXFP8_SKINNY_GEMM=0 turns the path off.

  • Backend selection: the kernel hooks the MXFP8 view of block-FP8 linears, and on SM120 that view exists only with --fp8-gemm-backend flashinfer_cutlass (or flashinfer_cutedsl where FlashInfer's CuTe-DSL MXFP8 GEMM supports the GPU). The SM120 default, auto, resolves to cutlass, which does not serve block-FP8 as MXFP8; 32x32-block linears then take the existing block-FP8 Triton kernel, and the automatic MXFP8 backend choice for DeepSeek-V4.1 applies to SM100/SM103 only. This PR does not change the SM120 default, so a default launch is unaffected; all measurements below use --fp8-gemm-backend flashinfer_cutlass.

  • Tuned table: seven DeepSeek-V4.1-Flash shapes with six (BN, SPLIT, BK) configurations, four of which split K.

    shape (N x K) layer BN SPLIT BK
    1792 x 5120 wqkv_a (replicated) 32 8 64
    8192 x 1280 wq_b (TP4) 64 1 128
    5120 x 2048 wo_b (TP4) 32 1 256
    25600 x 6144 Engram wkv (replicated) 64 1 128
    1280 x 5120 DSpark draft wq_a 32 8 128
    512 x 5120 DSpark draft wkv 32 10 128
    5120 x 15360 DSpark draft main_proj 64 4 128

    The shared-expert shapes (1152x5120, 5120x576) are left out on purpose. The kernel is faster on them in isolation (4.8 vs 16.5 µs and 3.3 vs 5.3 µs at M=6), but in serving they run on the MoE side stream, overlapping the routed experts, and the many-CTA split-K kernel competes with that work. Moving them back to CUTLASS raised decode steps/s by 0.4-2.6%.

Accuracy Tests

test/registered/kernels/ops/gemm/test_sm120_mxfp8_skinny_gemm.py (SM 12.0 only, registered for the 1-gpu-small runner), 63 test cases:

  • an FP64 reference over the dequantized MXFP8 operands at M = 1, 6, 16, 48 on six of the seven tuned shapes (24 cases), which cover all six configurations; Engram wkv shares the wq_b configuration and is left out for memory. Max absolute error < 8e-3 of the largest reference value.
  • FP16 and FP32 activations at M = 1 and 16 on a split-K shape (1792x5120) and the BK 256 shape (5120x2048) against the same FP64 reference, with the output in the input dtype (8 cases).
  • split-K counter validation: missing counters, a strided view, int64, too few entries, and counters on another device (CPU) each raise ValueError (5 cases).
  • BF16 activation operands, isolated with a selector weight and FP32 output (12 cases). In-kernel quantization is bit-identical to flashinfer.mxfp8_quantize (CuTe-DSL and CUDA backends), and so is the prequantized path, which reads the swizzled scales. This holds at M = 1, 6, 16, 32, 48 and 128 for rows from 2^-120 to 2^30 and for edge blocks: all zero, amax/448 exactly a power of two, and amax/448 at the smallest scale. FlashInfer's CUDA backend departs from CuTe-DSL on rows below about 2^-100, so it is compared from 2^-100 up. A block whose UE8M0 scale byte is 0 quantizes to zero, as in FlashInfer. The CuTe-DSL case is skipped only when flashinfer.cute_dsl.is_cute_dsl_available() is false; any other FlashInfer error fails the test.
  • determinism over 50 repeats and batch invariance on the six shapes: every prefix of 1-15 rows is bit-identical to the same rows of a 16-row batch (6 cases).
  • CUDA-graph capture and replay with new inputs, bit-identical to eager; the counters return to zero (1 case).
  • dispatch through a real block-FP8 ColumnParallelLinear and Fp8LinearMethod.apply with BF16 and FP16 activations on a split-K and a non-split shape (4 cases). Up to 16 rows (2D, 3D and, for BF16, Mxfp8SwizzledInput from FlashInfer's quantizer, CuTe-DSL when installed) take the kernel, and 17 rows keep CUTLASS. The kernel's output is bit-identical to calling it directly and within 1e-2 of FlashInfer CUTLASS. Split-K counters are allocated only for the shape that splits K.
  • a call with a bias keeps the existing path and its output matches the GEMM plus the bias within 1e-2; FP32 activations are not dispatched to the kernel (1 case).
  • a weight reload without recapture (as update_weights_from_disk does by default) keeps the scale and counter storage, takes the new scales and zeroes stale counters; a CUDA graph captured before the reload replays bit-identical to eager with the new weights (1 case).
  • an untuned shape, 128x32 weight blocks, --enable-deterministic-inference, and the environment switch keep CUTLASS (1 case).

All 63 tests pass on an RTX PRO 6000 Blackwell (torch 2.14.1+cu130, Triton 3.8.0), both with the published flashinfer-python 0.7.2 that main pins and with FlashInfer 0.7.2 built from its main.

The serving A/B below measured decode speed only; no end-to-end accuracy comparison between kernel on and off is reported here.

Speed Tests and Profiling

Hardware: 4x RTX PRO 6000 Blackwell (SM120, 188 SMs, PCIe).

Per-call microbenchmark at M=6, in µs, for the four target-model shapes (the DSpark draft shapes were not part of this microbenchmark). The kernels replay in a CUDA graph over enough weight copies to keep L2 cold, as in a decode step. The CUTLASS column includes mxfp8_quantize of the activation; this kernel quantizes in-kernel.

shape (N x K) layer Triton (this PR) FlashInfer CUTLASS
1792 x 5120 wqkv_a 8.9 16.7
8192 x 1280 wq_b (TP4) 8.6 10.9
5120 x 2048 wo_b (TP4) 8.8 11.5
25600 x 6144 Engram wkv 103 119

Above about 32 rows CUTLASS is faster. A serving trial that extended the kernel to 16 < M <= 64 lowered decode steps/s by 5% at batch 8/16, so the band stops at 16.

Serving A/B, kernel on (default) vs off (SGLANG_ENABLE_SM120_MXFP8_SKINNY_GEMM=0). DeepSeek-V4.1-Flash on 4x RTX PRO 6000 Blackwell Max-Q (PCIe, 250 W power limit), TP4, --fp8-gemm-backend flashinfer_cutlass, DSpark speculative decoding, temperature 1, top_p 0.95. All runs use the same server build and configuration, which also carries changes that are not part of this PR; only this switch differs between runs. The kernel-on configuration was measured before and after the kernel-off run.

Metric: steps/s is computed from SGLang's TP0 Decode batch log lines as gen throughput (token/s) / accept len, grouped by the logged running batch size, and taken as the median over a measurement window of about 30 s after warmup. It counts sequence decode steps per second (batch decode steps per second multiplied by the batch size), so it does not depend on the acceptance length. Each configuration ran 3 repetitions; each cell gives the median of the 3 repetitions followed by the 3 values.

In a verify pass the linears see M = batch x verify width rows, with a verify width of up to 6 tokens per sequence. At batch 1-2 every verify call is therefore within the kernel's 16-row band; at batch 4 and above only calls with at most 16 rows take the kernel.

decode batch on, before off on, after off vs mean of on medians
1 90.7 [92.5, 89.3, 90.7] 87.2 [87.1, 88.1, 87.2] 90.7 [89.3, 90.7, 91.2] -3.9%
2 146.9 [152.0, 146.7, 146.9] 141.1 [142.2, 141.1, 140.4] 147.4 [148.6, 147.4, 144.2] -4.1%
4 212.7 [216.8, 212.7, 211.4] 211.7 [209.8, 211.7, 216.1] 219.4 [225.8, 219.4, 218.4] -2.0%
8 339.1 [346.8, 339.1, 329.9] 330.5 [322.8, 330.5, 332.0] 339.3 [341.8, 339.3, 329.4] -2.6%
16 479.4 [479.4, 474.8, 479.4] 472.5 [472.5, 477.2, 469.1] 478.0 [478.0, 480.8, 471.6] -1.3%

At batch 1 and 2, every kernel-off repetition is below every kernel-on repetition, and the kernel-off median is about 4% lower. At batch 4, 8 and 16 the kernel-off median is 1.3-2.6% lower, but the kernel-off repetitions overlap the kernel-on ones and the two kernel-on medians differ by up to 3.1% (batch 4), so this sample does not resolve a difference at those batch sizes.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

Developed with AI assistance.


CI States

Latest PR Test (Base): ❌ Run #40984454672
Latest PR Test (Extra): ❌ Run #40984454634
Latest PR Test (AMD ROCm 10): ❌ Run #40984454495

@ormandj
ormandj force-pushed the sm120-mxfp8-skinny branch from 7719b51 to 2e33029 Compare October 7, 2026 05:42
@ormandj ormandj mentioned this pull request Oct 7, 2026
17 of 56 tasks
@ormandj
ormandj force-pushed the sm120-mxfp8-skinny branch from 2e33029 to 1a5573c Compare October 9, 2026 18:39
@ormandj ormandj changed the title [SM120] Speed up decode-sized MXFP8 linears with a Triton GEMM [Perf] [SM120] gemm: Speed up decode-sized MXFP8 linears with a Triton GEMM Oct 19, 2026
@ormandj
ormandj force-pushed the sm120-mxfp8-skinny branch from 1a5573c to 7d84b0e Compare October 19, 2026 17:33
detain added a commit to detain/sglang that referenced this pull request Oct 20, 2026
…ps.quantization in this tree

Upstream PR sgl-project#42865 forked before ue8m0_scale moved out of ops.layernorm into
ops.quantization (where dsv4_wo_a.py already imports it from). Point the new
sm120_mxfp8_skinny_gemm.py at the current location; identical symbol.
detain added a commit to detain/sglang that referenced this pull request Oct 20, 2026
…/deferred/avoid map

- 3A [24-35]: NVFP4 MoE boot sgl-project#39807/sgl-project#40173, block-FP8 TP refine sgl-project#42566, k-pool indexer split sgl-project#43619,
  SM120 skinny GEMM sgl-project#42865/sgl-project#42867, DeepGEMM warmup guards sgl-project#32686/sgl-project#43712, autotune sgl-project#43363/sgl-project#40420,
  mHC overlap sgl-project#42985, FP8-einsum precompile sgl-project#42821.
- 3B [36-43]: PCIe CustomAllreduce VMM sgl-project#44448, EP local expert ids sgl-project#44480, shm TP broadcast sgl-project#44202,
  PCIe-IPC all-gather sgl-project#42863 + multicast guard sgl-project#41888, TP-sampling consistency sgl-project#41916/sgl-project#38565,
  draft embed/lm_head VRAM sgl-project#37155.
- sgl-project#39807 toolchain commit verified safe against our CUDA_HOME=12.9 pin (cu13 fallback needs CUDA_HOME unset AND glibc>=2.41; we are 2.39).
- stack_want.txt: execution-status banner. Branch tip 5dd6ec7.
FlashInfer's SM120 MXFP8 CUTLASS GEMM has no split-K, so decode-sized GEMMs
with small N run on few CTAs. Block-FP8 (32x32, UE8M0) linears served as
MXFP8 now run tuned shapes at up to 16 rows on a Triton GEMM (tl.dot_scaled)
that can split K with a deterministic, batch-invariant reduction, and whose
activation quantization is bit-identical to flashinfer.mxfp8_quantize.
SGLANG_ENABLE_SM120_MXFP8_SKINNY_GEMM=0 turns it off.
Split-K counters must now be a contiguous int32 tensor on the activation's
device; anything else raises ValueError. Linear dispatch takes BF16 and
FP16 activations only, the dtypes the FlashInfer MXFP8 path accepts, and
the docs note that SM120 reaches the MXFP8 view only with
--fp8-gemm-backend flashinfer_cutlass or flashinfer_cutedsl.

Tests add FP16/FP32 inputs against the FP64 reference, counter rejection
(strided view, int64, too few, CPU, missing), FP16 dispatch, and a biased
layer that keeps the existing path; the CuTe-DSL case checks availability
explicitly instead of skipping on any RuntimeError.
update_weights_from_disk reruns weight postprocessing without recapturing
CUDA graphs by default, and _prepare_mxfp8_skinny replaced the layer's
FP32 scale and split-K counter tensors each time, leaving captured
launches with freed pointers. Buffers from an earlier call are now
refilled in place, so captured launches see the new scales and zeroed
counters.

A test captures a split-K layer, reloads its weights with stale counters,
takes over same-size allocations, and checks that replay matches eager.
@ormandj
ormandj force-pushed the sm120-mxfp8-skinny branch from 7d84b0e to 391c2a8 Compare October 29, 2026 22:19
Main moved mxfp8_epilogue from kernels/ops/layernorm to kernels/ops/quantization
(sgl-project#45112); the rebased skinny GEMM still imported the old path.
ormandj added a commit to ormandj/sglang-deepseek-v41-flash-sm120 that referenced this pull request Oct 30, 2026
Patch 11 (sgl-project/sglang#42865 at b2182fc605) imports ue8m0_scale from
main's kernels/ops/quantization (rc.2 failed the installed-image import
check); the dependency gate expects the 2026-10-29 vendor base's NIXL 1.5.1.
Same stack key.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @ormandj. Closing this because you have 25 PRs open and none updated in 7 days, over our soft cap of 5 for idle PRs.

Reopen the two or three you most want reviewed - a short active set moves faster than a long idle one.

Some directories moved recently, so an older branch may need retargeting:
sgl-kernel/ -> python/sglang/kernels/aot/, python/sglang/jit_kernel/
-> python/sglang/kernels/jit/, docs/ -> docs/docs/ (.mdx),
bench_serving.py -> benchmark/serving.py, test/srt/ -> test/registered/.

@github-actions github-actions Bot closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant