Skip to content

perf(moe_sorting): prefer multi-phase dispatch when single-CU work exceeds crossover - #3521

Closed
akii96 wants to merge 1 commit into
mainfrom
multi-phas-moe-sorting
Closed

akii96 wants to merge 1 commit into
mainfrom
multi-phas-moe-sorting

Conversation

@akii96

@akii96 akii96 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Motivation

The oneshot MoE sorting kernel (moe_sorting_is_oneshot) executes entirely on a single CU, so its runtime scales linearly with tokens × num_experts. The multi-phase (MP) kernel distributes the same work across all available CUs. On gfx950 (256 CUs, 128 experts), the current dispatch heuristic over-selects the oneshot path at moderate decode batch sizes (32–56 tokens), leaving the vast majority of compute units idle during MoE token routing.

Technical Details

This PR adds an expert-aware work bound to moe_sorting_is_oneshot() in csrc/include/moe_sorting_opus.h. When the total work product (tokens × num_experts) exceeds 2560, the function returns false, routing to the multi-phase kernel instead.

The threshold was determined empirically on gfx950 with 128 experts and topk=4. The change is a strict Pareto improvement: token counts below the crossover retain the oneshot kernel (unchanged behavior), and large-token prefill was already on the MP path.

Kernel-op improvement (MoE sorting, gfx950, 128 experts, topk=4)

Tokens Before (µs) This PR (µs) Speedup
16 6.10 6.10 —
32 8.57 8.09 5.6%
40 11.82 8.05 32%
48 12.10 8.10 33%
56 15.17 8.02 47%
64+ (already MP) (already MP) —

E2E serving improvement (vLLM 0.22.0, gfx950 / MI355X, openai/gpt-oss-120b, TP=1, concurrency=16, ISL=1000 / OSL=100, 3-repeat averaged)

Metric Before This PR Delta
Output throughput 2181 tok/s 2280 tok/s +4.5%
Time per output token 5.99 ms 5.63 ms −6.1%
Inter-token latency 6.01 ms 5.65 ms −5.9%
End-to-end latency 726.9 ms 698.5 ms −3.9%

Test Plan

  • Ran op_tests/test_moe_sorting.py for all rerouted token counts (16, 32, 48, 64) with 128 experts and topk=4.
  • Verified sorted_ids, sorted_weights, sorted_expert_ids, and num_tokens_post_padded match the native reference.
  • Confirmed no regression at token counts below the threshold (oneshot path unchanged) or above 64 (already on MP).
  • Full E2E serving benchmark with openai/gpt-oss-120b on gfx950 to confirm no throughput or latency regression.

Test Result

All op_tests/test_moe_sorting.py checks pass. E2E serving shows +4.5% output throughput with no regressions at any batch size.

The oneshot MoE sorting kernel serializes on one CU, so its cost grows
with tokens * num_experts. The multi-phase (MP) kernel distributes work
across all CUs and wins past ~2560 token-expert pairs (e.g. >20 tokens
at 128 experts on gfx950).

Fall back to MP when the work product exceeds this threshold. This is a
strict Pareto improvement: small-token decode keeps oneshot, mid-range
decode gains 5-47% on the sorting op, large-token prefill was already
on MP.

Measured on gfx950 (MI355X), openai/gpt-oss-120b, 128 experts, topk=4.
E2E: +4.5% output throughput, -6.1% TPOT at concurrency 16.
@akii96
akii96 requested a review from a team June 3, 2026 15:34
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 3521 --add-label <label>

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