Skip to content

[MoE] Optimize small-input preparation - #483

Draft
CaoE wants to merge 2 commits into
sgl-project:mainfrom
CaoE:ecao/moe_small
Draft

CaoE wants to merge 2 commits into
sgl-project:mainfrom
CaoE:ecao/moe_small

Conversation

@CaoE

@CaoE CaoE commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Optimize prepare_moe_input_small: parallelize token scatter across workgroups (1 WG per token row), cache topk_ids in SLM, and generalize fused small input prepare to all MoE datatypes (BF16, FP8, W4A16).
  • Relax n_experts % 8 == 0 constraint in Grouped GEMM dispatchers to support arbitrary positive expert counts.
  • Support 1D scalar scale tensor in _validate_fp8_weight_scale for compatibility with SGLang FP8 MoE.
  • Add unit test coverage for non-multiple-of-8 expert counts.

Micro-benchmark: Input Preparation Stage Latency

Config Batch (MM) Routes Speedup
E=8,TopK=2 M = 1 2 2.33x
E=8,TopK=2  M = 2 4 2.34x
E=8,TopK=2  M = 4 8 2.34x
E=8,TopK=2  M = 16 32 2.34x
E=64,TopK=6 M = 1 6 2.35x
E=64,TopK=6  M = 2 12 2.35x
E=64,TopK=6  M = 4 24 2.39x
E=256,TopK=8 M = 1 8 2.36x

Since the input preparation overhead accounts for a small percentage of the overall MOE, this optimization can typically reduce MoE time by up to ~5% for decoder M=1.

- Optimize prepare_moe_input_small: parallelize token scatter across workgroups (1 WG per token row), cache topk_ids in SLM, and generalize fused small input prepare to all MoE datatypes (BF16, FP8, W4A16).
- Relax n_experts % 8 == 0 constraint in Grouped GEMM dispatchers to support arbitrary positive expert counts.
- Support 1D scalar scale tensor in _validate_fp8_weight_scale for compatibility with SGLang FP8 MoE.
- Add unit test coverage for non-multiple-of-8 expert counts.
…ert counts

- Restrict prepare_moe_input_small for multi-token batches (num_tokens > 1) to models with num_experts <= 64 to avoid thread-0 serial loop overhead in the SLM histogram and prefix-sum phase.
- Retain fused small prepare for all single-token decode cases (num_tokens == 1), where routing sort is handled entirely within private registers without traversing the expert count E.
- Add unit test coverage in tests/test_moe_prepare_input.py.

This branch has not been deployed

No deployments
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.

1 participant