Skip to content

[Fix] MoE: require TopK layer_id to ensure routed expert captures - #40980

Merged
ch-wan merged 3 commits into
mainfrom
jiajun/mimo-v2-topk-layer-id
Sep 29, 2026
Merged

ch-wan merged 3 commits into
mainfrom
jiajun/mimo-v2-topk-layer-id

Conversation

@guapisolo

@guapisolo guapisolo commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

TopK now requires layer_id, so no MoE model can omit it and break routed-experts capture.

Symptom & Reproduction

  • Symptom: with --enable-return-routed-experts, MiMo-V2 fails decode CUDA-graph capture with a shape mismatch, Target sizes: [8, 1, 4, 8]; 20 other TopK calls on main (Nemotron-H, Mixtral, Llama 4, DeepSeek, Kimi, ...) omit layer_id the same way.
  • Reproduction: python -m sglang.launch_server --model-path <MiMo-V2 checkpoint> --trust-remote-code --tp 4 --enable-return-routed-experts; expected: graphs capture; observed: the error above.

Root Cause

  1. TopK.__init__ defaults layer_id to None, so omitting it is silent.
  2. capture_routed_experts_if_allowed forwards layer_id=None to the capturer.
  3. self.buffer[:batch, layer_id, :] (state_capturer/base.py:50) inserts an axis for None.
  4. The copy target becomes [batch, 1, num_layers, top_k], so the copy fails.

Fix

Verification

Review Focus

  • TopK.__init__: dropping the default makes out-of-tree models that build TopK without layer_id fail at init with TypeError; that is the intended guard.
  • dbrx.py / deepseek.py / xverse_moe.py / afmoe.py: the new MoE-block layer_id parameter has exactly one caller each.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #36065710223
Latest PR Test (Extra): ❌ Run #36065709688
Latest PR Test (AMD ROCm 10): ❌ Run #36065710061

@guapisolo
guapisolo force-pushed the jiajun/mimo-v2-topk-layer-id branch from 652b47b to 5cd6b5c Compare September 24, 2026 01:57
@guapisolo guapisolo changed the title [Fix] MiMo-V2: pass layer_id to the MoE TopK [Fix] MoE: require TopK layer_id (cherry-pick #38718) Sep 24, 2026
@guapisolo guapisolo changed the title [Fix] MoE: require TopK layer_id (cherry-pick #38718) [MoE] Require layer_id in TopK Sep 24, 2026
@guapisolo guapisolo changed the title [MoE] Require layer_id in TopK [Fix] MoE: require TopK layer_id Sep 24, 2026
@guapisolo guapisolo changed the title [Fix] MoE: require TopK layer_id [Fix] MoE: require TopK layer_id to ensure routed expert captures Sep 24, 2026
@guapisolo

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/moe/test_triton_fused_moe.py test/registered/moe/test_fused_moe.py test/registered/moe/test_topk_padded_region.py test/registered/moe/test_topk_renormalize_degenerate.py test/registered/rl/test_return_routed_experts.py test/registered/e2e/models/test_mimo_v2_flash.py test/registered/basic_perf/test_moe_throughput.py test/registered/e2e/models/test_kimi_linear_models.py test/registered/dllm/test_dllm_batching_fdfo.py test/registered/e2e/models/test_minimax_m25_basic.py test/registered/unit/models/test_granitemoe_split_expert_loading.py test/registered/unit/models/test_shared_experts_fusion_gates.py test/registered/unit/models/test_nemotron_h_mtp_reduction.py

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/moe/test_triton_fused_moe.py test/registered/moe/test_fused_moe.py test/registered/moe/test_topk_padded_region.py test/registered/moe/test_topk_renormalize_degenerate.py test/registered/rl/test_return_routed_experts.py test/registered/e2e/models/test_mimo_v2_flash.py test/registered/basic_perf/test_moe_throughput.py test/registered/e2e/models/test_kimi_linear_models.py test/registered/dllm/test_dllm_batching_fdfo.py test/registered/e2e/models/test_minimax_m25_basic.py test/registered/unit/models/test_granitemoe_split_expert_loading.py test/registered/unit/models/test_shared_experts_fusion_gates.py test/registered/unit/models/test_nemotron_h_mtp_reduction.py:

🚀 1-gpu-h100 (5 tests): ✅ View workflow run

cd test/ && python3 registered/moe/test_triton_fused_moe.py
cd test/ && python3 registered/moe/test_fused_moe.py
cd test/ && python3 registered/moe/test_topk_padded_region.py
cd test/ && python3 registered/moe/test_topk_renormalize_degenerate.py
cd test/ && python3 registered/dllm/test_dllm_batching_fdfo.py

🚀 4-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/rl/test_return_routed_experts.py

🚀 8-gpu-h200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_mimo_v2_flash.py
cd test/ && python3 registered/e2e/models/test_minimax_m25_basic.py

🚀 2-gpu-h100 (2 tests): ❌ View workflow run

cd test/ && python3 registered/basic_perf/test_moe_throughput.py
cd test/ && python3 registered/e2e/models/test_kimi_linear_models.py

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/models/test_granitemoe_split_expert_loading.py
cd test/ && python3 registered/unit/models/test_shared_experts_fusion_gates.py
cd test/ && python3 registered/unit/models/test_nemotron_h_mtp_reduction.py

@guapisolo

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/e2e/models/test_kimi_linear_models.py

@guapisolo

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/basic_perf/test_moe_throughput.py

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/e2e/models/test_kimi_linear_models.py:

🚀 2-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_kimi_linear_models.py

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/basic_perf/test_moe_throughput.py:

🚀 2-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/basic_perf/test_moe_throughput.py

@guapisolo

Copy link
Copy Markdown
Collaborator Author

/tag-run-ci-label

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Sep 24, 2026
@guapisolo
guapisolo force-pushed the jiajun/mimo-v2-topk-layer-id branch from 5cd6b5c to 3bd28b7 Compare September 24, 2026 19:59
guapisolo and others added 3 commits September 24, 2026 15:08
MiMoV2MoE built its TopK without layer_id, so with
--enable-return-routed-experts the routed-experts capture could not index
its per-layer buffer and the decode CUDA-graph capture failed with a shape
mismatch ("Target sizes: [8, 1, 4, 8]"). Pass the layer id like the other
MoE models do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cherry-picked from #38718 (merged into sglang-miles).
TopK defaulted layer_id to None, so a model that forgot it still built and
only failed once routed-experts capture was on: the capturer indexes
buffer[:, None, :], which inserts an axis and breaks CUDA-graph capture with
a shape mismatch. The same one-line fix has been made model by model
(#30363, #38718, and the MiMo-V2 commit above).

Make layer_id a required keyword and pass it in the remaining MoE models.
The DBRX, DeepSeek, Xverse and AFMoE MoE blocks now take layer_id from their
decoder layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@guapisolo
guapisolo force-pushed the jiajun/mimo-v2-topk-layer-id branch from 3bd28b7 to 56c23fb Compare September 24, 2026 22:08
@guapisolo guapisolo removed the run-ci CI: run the baseline test suite on this PR label Sep 24, 2026

@ch-wan ch-wan 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

guapisolo added a commit that referenced this pull request Sep 29, 2026
@ch-wan
ch-wan merged commit 3d49538 into main Sep 29, 2026
162 of 180 checks passed
@ch-wan
ch-wan deleted the jiajun/mimo-v2-topk-layer-id branch September 29, 2026 23:29
ziang-and pushed a commit to zianglih/sglang that referenced this pull request Oct 2, 2026
… graph registration (sgl-project#40648, sgl-project#40978, sgl-project#40979, sgl-project#40980, sgl-project#40977, sgl-project#41972)

Retain colocated training fixes above the release MiMo implementation, including address-stable Marlin reload and mandatory TopK layer IDs. Disable NCCL graph registration for TP LM-head all-to-all and pausable graph pools.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants