Skip to content

[Moe] Honor swiglu_limit clamped activation in flashinfer_cutlass runner - #39939

Merged
hnyls2002 merged 13 commits into
sgl-project:mainfrom
Dovis01:fix/flashinfer-cutlass-swiglu-limit
Sep 24, 2026
Merged

hnyls2002 merged 13 commits into
sgl-project:mainfrom
Dovis01:fix/flashinfer-cutlass-swiglu-limit

Conversation

@Dovis01

@Dovis01 Dovis01 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Models with a clamped SwiGLU activation (GLM-5 / GLM-5-Next, Qwen3-Next, GPT-OSS; configured as swiglu_limit or gemm1_clamp_limit in MoeRunnerConfig) silently lose the clamp on the flashinfer_cutlass MoE runner and run plain SwiGLU experts, for two stacked reasons: the runner's _run_flashinfer_cutlass never 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_fp4 is auto-pinned to flashinfer_cutlass because 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_trtllm path 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 None and are bit-for-bit unchanged:

  1. python/sglang/srt/layers/moe/moe_runner/flashinfer_cutlass.py: add swiglu_alpha/beta/limit fields to FlashInferCutlassMoeQuantInfo (the mxfp4 sibling dataclass already had them) and pass them from _run_flashinfer_cutlass into cutlass_fused_moe.

  2. python/sglang/srt/layers/quantization/modelopt_quant.py (NVFP4 + cutlass branch): fill the fields from MoeRunnerConfig with the same gemm1_clamp_limit or swiglu_limit fallback 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 sets gemm1_alpha / gemm1_beta.

  3. 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 (see modelopt_quant.py trtllm branch). This was verified against flashinfer's own fp32-dequantized reference implementation in tests/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_moe against a dequantized-fp32 reference:

config rel err vs reference
no clamp (all swiglu args None) 0.0038
clamp=10 (alpha=1.0, beta=0.0) 0.0036

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_w13 in the mxfp4 path).

Integrated runner smoke test (single-process NCCL init, real _run_flashinfer_cutlass call with FlashInferCutlassMoeQuantInfo carrying 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 None by 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

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
Dovis01 force-pushed the fix/flashinfer-cutlass-swiglu-limit branch from 0ef7ed6 to 4bc40e1 Compare September 17, 2026 08:42
Signed-off-by: Shijin Zhang <[email protected]>
@b8zhong b8zhong added the run-ci CI: run the baseline test suite on this PR label Sep 17, 2026
b8zhong and others added 4 commits September 17, 2026 18:58
…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]>
@Dovis01

Dovis01 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

Dovis01 and others added 4 commits September 20, 2026 08:31
…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
b8zhong enabled auto-merge (squash) September 20, 2026 16:46

@JustinTong0323 JustinTong0323 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions github-actions Bot added the blackwell SM100/SM120 label Sep 21, 2026
Signed-off-by: Shijin Zhang <[email protected]>
@Dovis01

Dovis01 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@JustinTong0323 JustinTong0323 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Dovis01

Dovis01 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@b8zhong
b8zhong enabled auto-merge (squash) September 22, 2026 13:45
@hnyls2002
hnyls2002 disabled auto-merge September 24, 2026 03:09
@hnyls2002
hnyls2002 merged commit 7798386 into sgl-project:main Sep 24, 2026
301 of 329 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 quant LLM Quantization run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants