Repository navigation
[MoE] Add FlashInfer SM90 MXFP4 W4A8 CUTLASS MoE - #34967
Merged
Merged
Conversation
yuan-luo
requested review from
Alisehen,
AniZpZ,
BBuf,
Edwardf0t1,
FlamingoPg,
Fridge003,
HaiShaw,
JustinTong0323,
OrangeRedeng,
Ying1123,
b8zhong,
ch-wan,
ispobock,
merrymercy,
mmangkad,
sogalin,
wisclmy0611 and
zijiexia
as code owners
August 15, 2026 17:11
yuan-luo
force-pushed
the
flashinfer-sm90-mxfp4-fp8
branch
from
August 16, 2026 04:58
c357163 to
7c02b25
Compare
yuan-luo
force-pushed
the
flashinfer-sm90-mxfp4-fp8
branch
from
August 16, 2026 15:15
7c02b25 to
f2c659b
Compare
Contributor
yuan-luo
force-pushed
the
flashinfer-sm90-mxfp4-fp8
branch
4 times, most recently
from
August 23, 2026 08:30
b0e2276 to
a2350e5
Compare
Fridge003
approved these changes
Aug 24, 2026
Fridge003
left a comment
Collaborator
There was a problem hiding this comment.
Wait for upgrade of flashinfer 0.6.18
kaixih
approved these changes
Aug 24, 2026
Collaborator
|
Flashinfer upgraded here #36954 |
5 of 6 tasks
Wire the corrected FlashInfer Humming-style MXFP4 x FP8 API into the Hopper MoE paths while preserving the W4A16 default and FlashInfer 0.6.17 compatibility. Add GPT-OSS and DeepSeek-V4 coverage, EP and padding checks, documentation, and a three-way SM90 benchmark.
FusedMoE rounds hidden_size up (GPT-OSS 2880 -> 3072) BEFORE create_weights whenever the flashinfer_mxfp4 backend is selected -- the same gate that later selects _fi_kernel = "cutlass_sm90". The SM90 post-load processor therefore sees K_un = 3072 = K_pad, so the preserve_expert_range fill guarded an empty region, while scale columns [2880, 3072) INSIDE K_un keep the _UE8M0_ONE (127 = 2^0) buffer fill that the naive-copy loader never overwrites. Humming derives each expert's residual from its min/max E8M0 exponents. The stale 127s sit far above any real per-expert max, so they inflate the range, shift the residual, and perturb the REAL weights on repack. Same story on w2's K rows. Fix: FusedMoE records hidden_size_unpadded before the round-up, create_weights stores it as _unpadded_hidden, and the w13/w2 scale copies stop at the checkpoint's K (ceil'd to the 32-wide group boundary) so the never-written tail is covered by the existing per-expert fill. The tail's weight bytes are zeros (never written), so whatever scale sits there multiplies zero -- numerically inert in the GEMM. The trim is gated on preserve_expert_range, so the W4A16 path stays byte-identical. The SM120 helper needs no change: it has no per-expert range statistic, and its stale scales multiply zero weights. Add test_humming_range_ignores_prerounded_hidden_tail, which builds the production shape (buffers at 3072, checkpoint data to 2880, real scales well below 127) and asserts the per-expert residual is invariant to the tail content. The existing tests missed this twice over: they construct the method at 2880 directly (never seeing FusedMoE's pre-round), and their random scales span 125..130, which straddles 127.
The 0.6.18 gate compared Version(...).release[:3] >= (0, 6, 18). The
release tuple drops prerelease markers -- Version("0.6.18rc1").release
is (0, 6, 18) -- so 0.6.18rc*/0.6.18.dev* builds, cut before the
corrected per-expert Humming API landed in the 0.6.18 release, slipped
through the gate. Compare full Versions instead:
Version(flashinfer_version) >= Version("0.6.18")
which rejects rc/dev prereleases of 0.6.18 while still accepting
0.6.18.post*/+local and anything newer (including dev builds of later
versions). Applied to all three copies of the gate: the module-level
_FI_HAS_SM90_CUTLASS_MXFP4_FP8 flag, the DSV4 runner's constructor
check, and the unit test's HAS_CORRECTED_HUMMING_API skip guard.
Replace both hand-rolled FlashInfer version gates (try/except around
__version__ parse + hasattr probe) with the existing
check_pkg_version_at_least("flashinfer_python", "0.6.18") helper. It
already does the prerelease-aware full-Version compare the previous
commit introduced, and returns False when the package is absent, so the
try/except scaffolding and the InvalidVersion handling collapse into one
call at each site.
Dropping the hasattr probe is safe: both weight processors import
preprocess_moe_weights_for_sm90_mixed_gemm_humming directly at use time,
so a build that misreports its version still fails loudly with a clear
ImportError there. As a kernel package, flashinfer_python also honors
SGLANG_SKIP_SGL_KERNEL_VERSION_CHECK=1 through the helper -- the
standard escape hatch for source builds with stale metadata.
The unit test's HAS_CORRECTED_HUMMING_API guard keeps its explicit
Version + hasattr form on purpose: under the skip env the helper returns
True unconditionally, which would un-skip the Humming tests on an old
FlashInfer and fail them spuriously; the test guard must reflect the
actually-installed API.
…0 cells
Switch the three H200 + FP4 low-latency single-node cells (flash-official,
flash, pro) to the new W4A8 path -- MXFP4 weights x FP8 activations via
FlashInfer's Humming kernels:
--moe-runner-backend flashinfer_mxfp4
--flashinfer-mxfp4-moe-precision fp8
flash-official and flash previously ran Marlin W4A16; pro already used the
FlashInfer W4A16 runner and only gains the precision flag. The cells carry
verificationStatus: "in-progress" until they are re-benchmarked with the
new kernel, and a comment records the FlashInfer >= 0.6.18 requirement and
the W4A16 fallbacks. Balanced / high-throughput cells are left on their
verified W4A16 commands for now.
Update the Hopper note in the MDX page accordingly: FP4 on Hopper is no
longer W4A16-only; the W4A8 opt-in and its version requirement are
documented, and the low-latency cells are called out as generating the
new form.
The MoE backend card is deliberately unchanged: backend-option requiresHw
filtering only applies to the MegaMoE entry, so a card-level W4A8 option
would be offered on Blackwell where --flashinfer-mxfp4-moe-precision fp8
raises by design.
yuan-luo
force-pushed
the
flashinfer-sm90-mxfp4-fp8
branch
from
August 31, 2026 07:02
2a80e18 to
cac2ea1
Compare
mmangkad
approved these changes
Aug 31, 2026
mmangkad
left a comment
Contributor
There was a problem hiding this comment.
Can we remove the defensive flashinfer version checks now?
Remove the four "flashinfer_mxfp4_moe_precision=fp8 selects the SM90 Humming path" ValueErrors (DSV4 cutlass constructor per review, plus the same guard in the trtllm SM100 constructor and mxfp4.py's SM100/SM120 _fi_kernel branches for consistency -- all four were added by this PR). The flag is an SM90 knob. The Blackwell paths (trtllm_sm100, cutlass_sm120) already compute the grouped GEMMs on MXFP8 activations, so precision=fp8 there matches actual behavior; rejecting it only broke config portability between H200 and Blackwell deployments. Outside SM90 the flag now simply has no effect (_use_sm90_humming stays False), which also matches the server-arg docstring, which scopes fp8 to SM90.
yuan-luo
force-pushed
the
flashinfer-sm90-mxfp4-fp8
branch
from
August 31, 2026 08:29
cac2ea1 to
eba9c45
Compare
Collaborator
Author
@mmangkad Removed the defensive flashinfer version checks and related import/comments. |
3 tasks done
Leoyzen
pushed a commit
to Leoyzen/sglang
that referenced
this pull request
Sep 5, 2026
Co-authored-by: luoyuan.luo <[email protected]> (cherry picked from commit 5b04408)
StevenChenSE
pushed a commit
to StevenChenSE/sglang
that referenced
this pull request
Sep 6, 2026
Co-authored-by: luoyuan.luo <[email protected]>
8 of 20 tasks
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.

Motivation
SGLang currently supports FlashInfer's SM90 MXFP4 W4A16 CUTLASS MoE path, which was introduced in SGLang #24816 on top of FlashInfer #3084. FlashInfer #3738 adds a different Hopper path that dynamically quantizes activations to FP8 and runs MXFP4-weight x FP8-activation MoE GEMMs using Humming-style pre-MMA E8M0 scale fusion.
This PR wires that path into SGLang as an explicit opt-in:
The existing
defaultandbf16behavior is unchanged.Related work:
FlashInfer version requirement
This integration intentionally targets the corrected API from FlashInfer #4431, where the FC1 and FC2 residual scales are FP32 tensors in local-expert order with shape
[num_local_experts]. FlashInfer reuses its internal expert permutation to map those scales to routed rows, including global-to-local expert mapping under EP.The original #3738 ABI briefly shipped before being reverted from FlashInfer 0.6.17 by #4411. It required downstream runtimes to construct routed-row residual tensors during every forward. SGLang does not support that older ABI.
The new option therefore requires both:
flashinfer-python >= 0.6.18preprocess_moe_weights_for_sm90_mixed_gemm_hummingSGLang currently pins FlashInfer 0.6.17. This PR does not change that global pin. With 0.6.17, selecting
fp8fails immediately with an actionable error, while all existing FlashInfer paths remain compatible. The dependency, cubin, and JIT-cache pins should be upgraded together in a follow-up change.GPU validation for this PR used FlashInfer 0.6.18 built from commit
8044d94bf9acc5369857baf88d28906bb32bf264, which contains the corrected API from FlashInfer #4431.Modifications
Runtime selection and compatibility
fp8to--flashinfer-mxfp4-moe-precision.flashinfer_mxfp4on SM90.fp8option on SM100 and SM120 to avoid confusing it with their existing MXFP8 activation paths.use_wfp4afp8_humming=Trueonly when the new path is selected. The keyword is omitted completely for FlashInfer 0.6.17 compatibility.Weight preprocessing
preprocess_moe_weights_for_sm90_mixed_gemm_hummingfor both FC1 and FC2 during post-load processing.residual * 64as one FP32 value per local expert for FC1 and FC2.Kernel invocation
Construct the five Humming quant-scale slots expected by the corrected FlashInfer API:
2^6compensation2^6compensationThe existing TP/EP topology is forwarded to FlashInfer so it can map global expert IDs to the corresponding local residual scale.
Tests and benchmark
Accuracy Tests
The registered SM90 MXFP4 suite passed:
The DeepSeek-V4 MXFP4 checkpoint was launched with:
DeepSeek-V4 accuracy was evaluated using the same 200-example GSM8K setup as SGLang #24816. Both runs used the same TP=4 configuration, dataset, sampling parameters, and server options; only
--flashinfer-mxfp4-moe-precisionchanged betweenbf16andfp8.bf16)fp8)W4A8 preserved the W4A16 GSM8K score while reducing evaluation latency by 11.7% and increasing output throughput by 11.7%. The score also matches the 0.985 W4A16 result reported in SGLang #24816.
Speed Tests and Profiling
The downstream benchmark uses the GPT-OSS-like shape from SGLang #24816: hidden size 4096, intermediate size 2048, 256 experts, and top-k 6. Each FlashInfer path was fully autotuned, followed by 5 warmup iterations and 30 timed iterations. The remaining token shapes were run in parallel with one independent shape per H20 GPU; each W4A16/W4A8 pair ran on the same GPU.
The benchmark can be reproduced with FlashInfer 0.6.18+:
Results on NVIDIA H20-3e:
FlashInfer CUTLASS W4A8 was faster at every measured token count, with speedups ranging from 1.63x to 2.08x. The gain reaches approximately 2.0x for token counts of 2048 and above. The GSM8K latency and throughput numbers above provide an end-to-end serving sanity check, but the kernel benchmark is the more controlled performance comparison because generated output lengths are not fixed.
Scope and Limitations
Checklist
CI States
Latest PR Test (Base): ⏳ Run #33373154332
Latest PR Test (Extra): ✅ Run #33373154123
Latest PR Test (AMD ROCm 7.2): ❌ Run #33373154379