Skip to content

feat: Support flashinfer_cutedsl MoE runner with flashinfer alltoall backend - #22669

Merged
ch-wan merged 19 commits into
sgl-project:mainfrom
samuellees:feat/enable-fp4cutedslmoe+a2a
May 20, 2026
Merged

ch-wan merged 19 commits into
sgl-project:mainfrom
samuellees:feat/enable-fp4cutedslmoe+a2a

Conversation

@samuellees

@samuellees samuellees commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on flashinfer-ai/flashinfer#3021 for topk=10.

Summary

  • Enable CuteDSL FP4 MoE runner (--moe-runner-backend flashinfer_cutedsl) to work with FlashInfer one-sided alltoall dispatch (--moe-a2a-backend flashinfer) for DP attention + EP configurations
  • Fixes multiple issues discovered when combining CuteDSL with alltoall in DP mode where idle ranks have 0 tokens

Changes

server_args.py

  • Add "flashinfer" to cutedsl's moe_a2a_backend whitelist
  • Add "flashinfer_cutedsl" to flashinfer a2a's moe_runner_backend whitelist
  • Force-disable SGLANG_MOE_NVFP4_DISPATCH for cutedsl + flashinfer a2a (FP4 dispatch path not yet validated with cutedsl's scale factor layout)

qwen2_moe.py

  • M=0 guard: Idle DP ranks (0 tokens) skip shared_expert and gate (FP4 GEMM cannot handle empty tensors), but still call self.experts() to participate in alltoall collective
  • Skip TP allreduce in a2a mode: Alltoall combine already aggregates routed expert results across ranks; additional tensor_model_parallel_all_reduce causes NCCL size mismatch between active/idle ranks
  • shared_expert tp_size=1: In a2a mode, shared_expert must not be TP-sharded (same as deepep), because TP allreduce on shared_expert output fails when idle DP ranks have 0 tokens

flashinfer.py (token dispatcher)

  • Remove dummy token mechanism: Pass 0-size tensors directly to alltoall kernel (matching TRT-LLM behavior). The kernel natively handles local_num_tokens=0. Removed unused dummy tensor allocations
  • Rename has_dummy_token → is_idle_rank for clarity
  • Add invalid_token_expert_id: Mark padding slots with invalid expert ID so MoE kernels skip them
  • Increase default max dispatch tokens per rank from 1024 to 8192 to support longer sequences

flashinfer_cutedsl.py (MoE runner)

  • Register fused func ("flashinfer", "flashinfer_cutedsl") for flashinfer alltoall dispatcher
  • Scale wrapper max_num_tokens by dp_size in DP attention mode, since wrapper receives dp_size * local_tokens after allgather/dispatch

test_cutedsl_a2a.py (unit test)

  • E2E test: launch Qwen3.5-397B-A17B-NVFP4 server with cutedsl + flashinfer a2a on B200×4, run GSM8K > 90%

Reproduce

Hardware: B200 × 4

Baseline (cutedsl + DP, no a2a)

python3 -m sglang.launch_server \
  --model-path nvidia/Qwen3.5-397B-A17B-NVFP4 \
  --trust-remote-code --quantization modelopt_fp4 \
  --tp 4 --ep-size 4 --dp 4 \
  --enable-dp-attention --enable-dp-lm-head \
  --moe-runner-backend flashinfer_cutedsl \
  --mem-fraction-static 0.85 --max-running-requests 256 \
  --stream-interval 5 --attention-backend triton \
  --cuda-graph-bs 1 2 4 8 16 32 64 128 256 \
  --disable-radix-cache --disable-flashinfer-autotune \
  --watchdog-timeout 900 --port 8001

This PR (cutedsl + DP + flashinfer a2a)

python3 -m sglang.launch_server \
  --model-path nvidia/Qwen3.5-397B-A17B-NVFP4 \
  --trust-remote-code --quantization modelopt_fp4 \
  --tp 4 --ep-size 4 --dp 4 \
  --enable-dp-attention --enable-dp-lm-head \
  --moe-runner-backend flashinfer_cutedsl \
  --moe-a2a-backend flashinfer \
  --mem-fraction-static 0.85 --max-running-requests 256 \
  --stream-interval 5 --attention-backend triton \
  --cuda-graph-bs 1 2 4 8 16 32 64 128 256 \
  --disable-radix-cache --disable-flashinfer-autotune \
  --watchdog-timeout 900 --port 8001

GSM8K eval

python3 -m sglang.test.run_eval --port 8001 --eval-name gsm8k \
  --num-examples 1319 --max-tokens 10240 --repeat 1 \
  --num-threads 1319 --num-shots 8 \
  --temperature 0.6 --top-p 0.95 --top-k 20

GPQA eval

python3 -m sglang.test.run_eval --port 8001 --eval-name gpqa \
  --num-examples 198 --max-tokens 81920 --repeat 8 \
  --temperature 0.6 --top-p 0.95 --top-k 20

Accuracy

Config GSM8K (1319 examples) GPQA (198×8) Latency Throughput
Baseline (no a2a) 97.64% — 585s 6347 tok/s
This PR (flashinfer a2a) 97.56% 86.2% 576s 6399 tok/s

Test plan

  • Unit test: test/registered/moe/test_cutedsl_a2a.py — GSM8K > 90% on B200×4
  • Smoke test: The capital of France is → Paris.
  • GPQA: 86.2% (8 repeats: 0.859–0.874)
  • GSM8K: 97.56% (matches baseline 97.64%)

CI States

Latest PR Test (Base): 🚫 Run #26144561324
Latest PR Test (Extra): ❌ Run #26144561265

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@samuellees

samuellees commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

@samuellees
samuellees force-pushed the feat/enable-fp4cutedslmoe+a2a branch from ad51fab to 59c2c2a Compare April 13, 2026 14:42
…backend

Enable CuteDSL FP4 MoE runner (--moe-runner-backend flashinfer_cutedsl)
to work with FlashInfer one-sided alltoall dispatch (--moe-a2a-backend
flashinfer) for DP attention + EP configurations.

Changes:
- server_args.py: whitelist cutedsl + flashinfer a2a, force-disable NVFP4_DISPATCH
- qwen2_moe.py: M=0 guard, skip allreduce for a2a, shared_expert tp_size=1
- flashinfer.py: remove dummy token, pass 0-size tensors, add invalid_token_expert_id
- flashinfer_cutedsl.py: register fused func, scale max_num_tokens by dp_size
- test_cutedsl_a2a.py: E2E test on B200x4 with GSM8K

Tested: Qwen3.5-397B-A17B-NVFP4, B200x4, EP=4 DP=4
- GSM8K: 97.56% (baseline 97.64%)
- GPQA: 86.2% (8 repeats)
@samuellees
samuellees force-pushed the feat/enable-fp4cutedslmoe+a2a branch from 59c2c2a to 91e1434 Compare April 13, 2026 14:56
@YAMY1234

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Apr 13, 2026
Comment thread python/sglang/srt/server_args.py Resolved
Comment thread python/sglang/srt/server_args.py Resolved
@github-actions github-actions Bot added the quant LLM Quantization label Apr 15, 2026
@trevor-m
trevor-m force-pushed the feat/enable-fp4cutedslmoe+a2a branch from 01ea5d1 to 6eac935 Compare April 15, 2026 23:39
payloads,
self.runtime_max_tokens_per_rank,
invalid_token_expert_id=self.num_experts,

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.

This will trigger moe_a2a_sanitize_expert_ids kernel, we should confirm if it's necessary otherwise it will reduce the perf

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is necessary, the recv_buffer of A2A is allocated redundantly. If the invalid slots are not sanitized, they will be sent for useless MoE computation.

@ch-wan

ch-wan commented May 18, 2026

Copy link
Copy Markdown
Collaborator

@samuellees Could you ping me on slack when this PR is ready? Also, I removed the high priority label to save CI resources. Manually triggering cutedsl-related tests should be sufficient.

# Conflicts:
#	python/sglang/srt/layers/moe/moe_runner/flashinfer_cutedsl.py
#	python/sglang/srt/layers/moe/token_dispatcher/flashinfer.py
#	python/sglang/srt/layers/quantization/modelopt_quant.py
popen_launch_server,
)

register_cuda_ci(est_time=600, stage="base-c", runner_config="4-gpu-b200")

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.

let's move it to stage="extra-b"

@Kangyan-Zhou
Kangyan-Zhou dismissed trevor-m’s stale review May 20, 2026 07:01

dismiss stale requests

@ch-wan
ch-wan merged commit 044649c into sgl-project:main May 20, 2026
85 of 113 checks passed
Jiminator added a commit to Jiminator/sglang that referenced this pull request May 28, 2026
Adds an investigation report for the nightly-test-perf-4-gpu-b200 failure of
test_a_gsm8k under TestDeepseekV3FP4CuteDSLMoE. The regression is traced to
commit 044649c (PR sgl-project#22669) which under-sizes the CuteDslMoEWrapper buffer
for the EP=1, TP=4, no-DP-attention DeepSeek V3 FP4 configuration.

The report includes:
- pass/fail boundary (run sgl-project#624 pass -> sgl-project#625 fail on main)
- bisection across the 50 commits in 7f154ba..c4a7d12
- root-cause diff in flashinfer_cutedsl.py:ensure_cutedsl_wrapper
- direct repro at offending and parent SHAs (GPU 4 only)
- a four-line recommended patch and short-term workarounds

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Jiminator added a commit to Jiminator/sglang that referenced this pull request May 29, 2026
sgl-project#22669 changed ensure_cutedsl_wrapper to size the CuteDslMoEWrapper
CUDA-graph buffers from the first forward's token count (max(num_tokens, 1)),
which during startup is a small capture batch. A larger real forward then
trips FlashInfer's `num_tokens exceeds max_num_tokens` guard and crashes the
scheduler (repros on DeepSeek-V3-0324-FP4, tp4/ep1/flashinfer_cutedsl,
no dp-attention).

Size the buffer from the server config instead, via a shared
ServerArgs.cutedsl_moe_max_num_tokens() helper covering the prefill,
piecewise-prefill-capture, and decode/spec-verify bounds; scale by dp_size on
the allgather path. Reuse the helper in the A2A startup guard and drop the
unused num_tokens parameter.
Jiminator added a commit to Jiminator/sglang that referenced this pull request May 29, 2026
sgl-project#22669 changed ensure_cutedsl_wrapper to size the CuteDslMoEWrapper
CUDA-graph buffers from the first forward's token count (max(num_tokens, 1)),
which during startup is a small capture batch. A larger real forward then
trips FlashInfer's `num_tokens exceeds max_num_tokens` guard and crashes the
scheduler (repros on DeepSeek-V3-0324-FP4, tp4/ep1/flashinfer_cutedsl,
no dp-attention).

Add ServerArgs.cutedsl_moe_max_num_tokens() as a single source of truth for the
per-forward token bound: max over the prefill (max_prefill_tokens),
piecewise-prefill-capture, and decode/spec-verify (cuda_graph_max_bs *
num_tokens_per_bs) bounds. Use it both for the standard-allgather wrapper
buffers (* dp_size) and the FlashInfer A2A dispatcher budget check -- the latter
moved after speculative resolution so it sees the final num_tokens_per_bs,
replacing its weaker max_prefill_tokens-only check. Drop the unused num_tokens
parameter.
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

8 participants