Repository navigation
[Moe] Honor swiglu_limit clamped activation in flashinfer_cutlass runner - #39939
Merged
hnyls2002 merged 13 commits intoSep 24, 2026
Merged
Conversation
Dovis01
requested review from
Alisehen,
AniZpZ,
BBuf,
Edwardf0t1,
FlamingoPg,
Fridge003,
HaiShaw,
OrangeRedeng,
Ying1123,
b8zhong,
ch-wan,
ispobock,
merrymercy and
mmangkad
as code owners
September 17, 2026 08:24
The flashinfer_cutlass runner never passed the per-expert SwiGLU parameters to the kernel, and its construction sites (ModelOpt NVFP4 on SM120, unquantized bf16) never filled them, so models with a clamped SwiGLU (swiglu_limit / gemm1_clamp_limit, e.g. GLM-5, Qwen3-Next, GPT-OSS NVFP4 variants) silently lost the clamp on this backend and ran plain SwiGLU experts. On SM120 this path is unavoidable: modelopt_fp4 is auto-pinned to flashinfer_cutlass because trtllm-gen MoE kernels are SM100-only. Add materialize_swiglu_params_for_cutlass() next to the quant-info dataclass as the single source of the fill semantics (the same gemm1_clamp_limit-or-swiglu_limit fallback and SiTU exception as the ModelOpt flashinfer_trtllm branch; alpha/beta default to the silu-neutral 1.0/0.0). The tensors are materialized once per layer in process_weights_after_loading, not per forward. Add the swiglu fields to FlashInferCutlassMoeQuantInfo and pass them from _run_flashinfer_cutlass into cutlass_fused_moe. Models without a configured clamp keep passing None and are unchanged. The CUTLASS kernel applies the clamp on dequantized values, so the limit is passed in physical units (unlike trtllm-gen, which divides by g1_alphas). Kernel-level bf16 A/B on B200 (E=8, H=256, I=128, 5.8% of activations beyond the limit): kernel vs dequantized-fp32 reference rel err 0.0038 without clamp and 0.0036 with clamp=10; clamp effect size 0.2185 (kernel) vs 0.2183 (reference). An integrated runner-level smoke test (quant_info -> _run_flashinfer_cutlass -> kernel) reproduces these numbers and additionally checks the helper's fill semantics (defaults / None / SiTU / GPT-OSS alpha / gemm1_clamp_limit precedence).
Dovis01
force-pushed
the
fix/flashinfer-cutlass-swiglu-limit
branch
from
September 17, 2026 08:42
0ef7ed6 to
4bc40e1
Compare
Signed-off-by: Shijin Zhang <[email protected]>
…rst counting Upstream sgl-project#40006 added `_prev_prefill_end_ts` (initialized in `init_load_inquirer`) and the split-prefill `batch.split_index` read in `run_batch`, but did not update the CPU unit tests that stub the Scheduler with `__new__`: - test_disagg_idle_step_counters: `make_scheduler` now seeds `_prev_prefill_end_ts`, and `_record_step_counters` runs under the same scripted `time.monotonic` clock as `run_batch` so prefill busy time is derived from LAUNCH_TIMESTAMPS instead of real wall time (the new end-ts / prev-end-ts chaining). - test_auxiliary_output: the pdmux split-prefill batch stub gains `split_index=0`, mirroring the ScheduleBatch dataclass default. Signed-off-by: Shijin Zhang <[email protected]>
Resolve scheduler unit-test fixture conflicts by taking upstream sgl-project#40411. Signed-off-by: Shijin Zhang <[email protected]>
Contributor
Author
|
/rerun-failed-ci |
…the view Two defects in test_oot_dflash_hooks.py, both hidden behind the 401 the CI showed first: - The alias resolver in handle_speculative_decoding unconditionally fetches the draft HF config (Gemma4 assistant detection), and the fake speculative_draft_model_path "draft" is not a real repo, so the CPU unit test made a real network call. HF Hub answers anonymous requests for nonexistent repos with 401. Mock get_config at that boundary now. - The expected fallback value was asserted on the raw ServerArgs field, but the resolution pipeline records declarations in the stash without writing fields; read it back through resolving_view instead. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Shijin Zhang <[email protected]>
Resolve test_oot_dflash_hooks conflict by keeping main's offline resolver path (call _resolve_dflash_draft_attention_backend + resolution_result) instead of the full-hook/resolving_view approach. Co-authored-by: Cursor <[email protected]> Signed-off-by: Shijin Zhang <[email protected]>
b8zhong
enabled auto-merge (squash)
September 20, 2026 16:46
Collaborator
There was a problem hiding this comment.
Mechanism is fine, but the beta default breaks the headline case — GPT-OSS never sets gemm1_beta and every reference path uses beta=1.0 here (see inline). Please rerun the A/B with the GPT-OSS triple (1.702 / 1.0 / 7.0) and commit it as a test. Also either fill or explicitly punt the two other construction sites that still drop the clamp (
and ), and note in the PR body that GPT-OSS bf16 biases are still dropped (pre-existing gap).…r_cutlass GPT-OSS never sets gemm1_beta and every reference path uses beta=1.0: silu(gate) * clamp(alpha*up + 1, ±limit). With beta defaulting to 0.0, the up term lost its +1 and outputs were materially wrong on the SM120 NVFP4 path. Mirror trtllm/mxfp4, which pairs every alpha with beta = 1/g1_alphas; an explicit gemm1_beta still wins, and alpha-less configs stay silu-neutral at 1.0/0.0. Also fill the two construction sites that still dropped the clamp: ModelOpt FP8 and compressed-tensors W4A4 NVFP4 now pre-materialize the same per-expert SwiGLU triple and forward it (all-None without a clamp, so unchanged for models without gemm1_alpha/clamp today). The GPT-OSS triple (1.702 / 1.0 / 7.0) is pinned by a CPU unit test that also checks it against the reference epilogue and that it differs from the old beta=0 behavior. Known pre-existing gap (unchanged): GPT-OSS bf16 expert biases are still dropped on this path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Shijin Zhang <[email protected]>
auto-merge was automatically disabled
September 21, 2026 04:17
Head branch was pushed to by a user without write access
Signed-off-by: Shijin Zhang <[email protected]>
Contributor
Author
|
/rerun-failed-ci |
Signed-off-by: Shijin Zhang <[email protected]>
Contributor
Author
|
/rerun-failed-ci |
b8zhong
enabled auto-merge (squash)
September 22, 2026 13:45
hnyls2002
approved these changes
Sep 24, 2026
hnyls2002
disabled auto-merge
September 24, 2026 03:09
2 of 5 tasks
waynehacking8
added a commit
to waynehacking8/sglang
that referenced
this pull request
Nov 22, 2026
…o runners that apply it Llama 4 applies its top-1 router weight to the MoE input. sgl-project#35504 removed the CUTLASS assert against that in this method, since the CUTLASS runner pre-scales the hidden states, so Llama 4 runs on SM120/SM121 (sgl-project#34192); sgl-project#39939 added the assert back two days later. Remove it again. Marlin multiplies router weights into the expert output, which check_moe_marlin_supports_layer already records, so a router-on-input layer on Marlin ran with a silently wrong result. When this method's backend is Marlin, create_moe_runner now refuses such a layer at startup. Signed-off-by: WEI CHENG CHIU <[email protected]>
Merged
4 of 5 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
Models with a clamped SwiGLU activation (GLM-5 / GLM-5-Next, Qwen3-Next, GPT-OSS; configured as
swiglu_limitorgemm1_clamp_limitinMoeRunnerConfig) silently lose the clamp on theflashinfer_cutlassMoE runner and run plain SwiGLU experts, for two stacked reasons: the runner's_run_flashinfer_cutlassnever passed the per-expert SwiGLU parameters to the kernel, and its quant-info construction sites never filled them.This path is not theoretical: on SM120 (RTX 50 series)
modelopt_fp4is auto-pinned toflashinfer_cutlassbecause trtllm-gen MoE kernels are SM100-only (arg_groups/overrides.py), so NVFP4 GPT-OSS variants on SM120 hit exactly this gap today. The unquantized bf16 path is affected the same way.For reference, the identical activation bug on the FP8
flashinfer_trtllmpath cost GLM-5.3-Flash ~0.9pp GSM8K (92.77 -> 93.60, restored to the triton baseline; see companion PR #39920).Modifications
Three files, all in the flashinfer_cutlass path; models without a configured clamp keep passing
Noneand are bit-for-bit unchanged:python/sglang/srt/layers/moe/moe_runner/flashinfer_cutlass.py: addswiglu_alpha/beta/limitfields toFlashInferCutlassMoeQuantInfo(the mxfp4 sibling dataclass already had them) and pass them from_run_flashinfer_cutlassintocutlass_fused_moe.python/sglang/srt/layers/quantization/modelopt_quant.py(NVFP4 + cutlass branch): fill the fields fromMoeRunnerConfigwith the samegemm1_clamp_limit or swiglu_limitfallback and SiTU exception already used by the ModelOpt flashinfer_trtllm branch. When a clamp is configured, alpha/beta default to the silu-neutral 1.0 / 0.0 unless the model setsgemm1_alpha/gemm1_beta.python/sglang/srt/layers/quantization/unquant.py(bf16 + cutlass branch): same fill.Unit convention: the CUTLASS kernel applies the clamp on dequantized values, so the limit is passed in physical units -- unlike trtllm-gen, where the limit must be divided by
g1_alphas(seemodelopt_quant.pytrtllm branch). This was verified against flashinfer's own fp32-dequantized reference implementation intests/moe/test_trtllm_cutlass_fused_moe.py.Accuracy Tests
No SM120 GPU was available, so verification was done at the kernel and runner level on B200:
Kernel-level bf16 A/B (E=8, H=256, I=128, T=64, top-2; 5.8% of gemm1 activations beyond the limit), comparing
flashinfer.cutlass_fused_moeagainst a dequantized-fp32 reference:Clamp effect size matches the reference: 0.2185 (kernel) vs 0.2183 (reference). This confirms the kernel formula
silu(clamp(gate, max=L)) * (clamp(up, -L, L) + beta)with the up half stored first in w13 (matching_stack_up_gate_w13in the mxfp4 path).Integrated runner smoke test (single-process NCCL init, real
_run_flashinfer_cutlasscall withFlashInferCutlassMoeQuantInfocarrying the clamp tensors): plain rel err 0.0038, clamped rel err 0.0036, clamp effect 0.2185 -- the full quant_info -> runner -> kernel chain is verified. This smoke test also caught (and verified the fix of) a missing-dataclass-field error before commit.Speed Tests and Profiling
Not affected. The change adds three optional kernel arguments (already
Noneby default) and three per-expert fp32 tensors materialized once at weight-load time only when a clamp is configured. The hot kernel call is unchanged for unconfigured models.Note
Known pre-existing gap: GPT-OSS bf16 expert biases are still dropped on the flashinfer_cutlass NVFP4 path — FlashInferCutlassMoeQuantInfo has no bias fields and _run_flashinfer_cutlass never passes fc1/fc2_expert_biases (only the MXFP4 sibling does). Fixing it needs a flashinfer cutlass_fused_moe API extension; out of scope here.
CI States
Latest PR Test (Base): ✅ Run #35684292947
Latest PR Test (Extra): ❌ Run #35684292431
Latest PR Test (AMD ROCm 10): ❌ Run #35684292662