Skip to content

[Chore] flashinfer: Use flashinfer moe-ep API instead of deprecated NVLinkOneSidedAllToAll API - #46885

Closed
trevor-m wants to merge 3 commits into
sgl-project:mainfrom
trevor-m:moe-ep
Closed

trevor-m wants to merge 3 commits into
sgl-project:mainfrom
trevor-m:moe-ep

Conversation

@trevor-m

@trevor-m trevor-m commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Flashinfer has deprecated and removed the API we currently use for --moe-a2a-backend=flashinfer: flashinfer-ai/flashinfer#6621 flashinfer-ai/flashinfer#6047
If we don't update it, it will become unusable the next time we update flashinfer.

Modifications

Update the code to use the new moe-ep api instead. All changes outside of unit tests are contained to python/sglang/srt/layers/moe/token_dispatcher/flashinfer.py so there should be no side affects on other code paths.

Accuracy Tests

GSM8K

 python3 -m sglang.launch_server \
    --model-path nvidia/DeepSeek-R1-0528-FP4-V2 \
    --trust-remote-code \
    --tp 4 --ep 4 --attn-dp-size 4 \
    --moe-a2a-backend flashinfer \
    --moe-runner-backend flashinfer_trtllm_routed \
    --quantization modelopt_fp4 \
    --disable-flashinfer-autotune \
    --model-loader-extra-config '{"enable_multithread_load": true}' \
    --reasoning-parser deepseek-r1 \
    --host 127.0.0.1 --port 30000

 sgl-eval run gsm8k --base-url http://127.0.0.1:30000/v1 \
    --model nvidia/DeepSeek-R1-0528-FP4-V2 \
    --temperature 0.6 --top-p 0.95 --max-tokens 16384 --seed 0 --num-threads 128

Result without this PR: 94.92%
Result with this PR: 95.30%

Speed Tests and Profiling

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.

CI States

Latest PR Test (Base): ❌ Run #41927706980
Latest PR Test (Extra): ❌ Run #41927706597
Latest PR Test (AMD ROCm 10): ❌ Run #41927707112

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@trevor-m trevor-m changed the title [Chore] flashinfer: Use flashinfermoe-ep API instead of deprecated API [Chore] flashinfer: Use flashinfer moe-ep API instead of deprecated NVLinkOneSidedAllToAll API Oct 27, 2026
@github-actions

This comment has been minimized.

@nvpohanh

Copy link
Copy Markdown
Collaborator

@leejnau @wenscarl Could you review as well? Thanks

@nvpohanh nvpohanh 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.

[by Claude Code] This review is done by agents. Please feel free to disagree if they do not make sense.

[by Claude Code] Severity: nit | Confidence: High

Issue

The Accuracy Tests section gives a before/after GSM8K result (94.92% vs 95.30%) for nvidia/DeepSeek-R1-0528-FP4-V2, but it does not name the GPU.

Fix

Add the GPU or system used, for example B200 or GB200. This path depends on the NVLink setup, so naming it shows reviewers what was tested.

expert_id_payload_index=expert_id_payload_index,
topk_weights,
hidden_states_scale=x_sf,
max_tokens_per_rank=runtime_max_tokens_per_rank,

@nvpohanh nvpohanh Oct 28, 2026 •

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.

[by Claude Code] Severity: style | Confidence: High

Issue

This works with FlashInfer 0.7.2, which SGLang pins today. Heads-up for the next upgrade: FlashInfer main renamed this keyword to runtime_max_tokens_per_rank in flashinfer-ai/flashinfer#7099 and removed the old name. That change is not released yet. It will ship in the same release as flashinfer-ai/flashinfer#6047 and flashinfer-ai/flashinfer#6621, which remove MoeAlltoAll. On that release, max_tokens_per_rank= here raises TypeError, because NVLinkOneSidedAlltoAll.dispatch() has no **kwargs.

Fix

No change is needed for 0.7.2. When SGLang upgrades FlashInfer past 0.7.2, rename this keyword to runtime_max_tokens_per_rank= in that upgrade PR. The CPU test fakes take **_kwargs, so they will not catch this.

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.

@leejnau Is this a FlashInfer API breakage in their main branch?

@bobboli bobboli Oct 28, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, please on-hold until release v0.7.3 to directly adapt to the new keyword runtime_max_tokens_per_rank .

@bobboli

bobboli commented Oct 28, 2026 •

Copy link
Copy Markdown

Suggestion on naming: now that this dispatcher goes through flashinfer.moe_ep, --moe-a2a-backend flashinfer is ambiguous. flashinfer.moe_ep has several all-to-all backends (NVLink one-sided, NVLink two-sided, Cake, NCCL-EP and NIXL-EP), and SGLang already uses flashinfer_megamoe for the Mega mode. This dispatcher only uses NVLinkOneSidedAlltoAll.

Could we name it flashinfer_nvlink_one_sided, and keep flashinfer as a deprecated alias for compatibility? That matches vLLM's --all2all-backend flashinfer_nvlink_one_sided / flashinfer_nvlink_two_sided. It also leaves room to wire up another FlashInfer backend later without overloading flashinfer.

@trevor-m

Copy link
Copy Markdown
Collaborator Author

Thanks @nvpohanh and @bobboli!
Renaming to flashinfer_nvlink_one_sided works for me.

@trevor-m

trevor-m commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hi @bobboli, renaming the server arg turns out to be quite an invasive changes, making this PR go from a file 1 change + unit tests to touching over 40 files. I'd prefer to keep the server arg as is, we can also rename it later if a new flahsinfer a2a comes out.

@trevor-m

trevor-m commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Validating latest code against flashinfer 0.7.3, GSM8k is 96%, all of test_flashinfer_a2a_wide_ep.py, test_flashinfer_dispatcher.py and test_muse_spark_runner_dispatch.py tested passed on 4xGB200.

@Fridge003

Copy link
Copy Markdown
Collaborator

Closing this PR since it's included in #48468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants