Skip to content

[HIP] [Perf] Route gfx950 E=128..255 decode at M>=17 to multi-phase MoE sorting - #7134

Merged
zufayu merged 1 commit into
ROCm:mainfrom
lishuoshuo-amd:perf/gfx950-moe-sorting-mp-e128
Nov 3, 2026
Merged

zufayu merged 1 commit into
ROCm:mainfrom
lishuoshuo-amd:perf/gfx950-moe-sorting-mp-e128

Conversation

@lishuoshuo-amd

Copy link
Copy Markdown
Contributor

Summary

Opus auto dispatch keeps one-shot MoE sorting whenever the rows fit in LDS. On gfx950 with 128 to 255 experts that is M up to 24..56 tokens, and in that range one-shot is 1.25-3.01x (median 2.01x) slower than multi-phase, with bitwise-identical outputs. This is the decode range of speculative decoding (EAGLE3 with 3 draft tokens puts 4 rows per request through MoE) and of mid-concurrency serving for models such as gpt-oss (E=128), Qwen3-MoE (E=128), MiniMax-M3 (E=129 with the fused shared expert) and DeepSeek-V2 (E=160).

This extends the gfx950 crossover rule from #5987 with one more clause.

Change

csrc/include/moe_sorting_opus.h, moe_sorting_auto_is_oneshot:

bool prefer_mp = num_experts_ >= 385 || (num_experts_ >= 256 && tokens_ >= 8) ||
                 (num_experts_ >= 128 && tokens_ >= 17);

Unchanged: other architectures, E<128, M<=16, M beyond the LDS bound (already multi-phase), E>=256, and forced dispatch_policy=1/2.

op_tests/test_moe_sorting.py, test_moe_sorting_opus_host_dispatch_boundaries: adds M=17 and E=127 (control, stays one-shot), E=128 and E=192, and updates E=255, whose M=17 and M=24 now select multi-phase.

Results (MI355X, gfx950, ROCm 10.0)

Kernel latency

Measured on main 42c319b, which includes #7085 (bounds-checked top-k id loads in the multi-phase P0 kernels). aiter.moe_sorting, one-shot / multi-phase in us, block_size 16. Each call runs inside a CUDA graph after a 512 MB write that evicts L2 and MALL, minus a flush-only graph, median of 7 replays, mean of two rounds with the GPUs swapped:

shape (E, topk) M=17 M=24 M=32 M=40 M=48 M=56
gpt-oss (128, 4) 9.1 / 6.8 9.5 / 6.7 10.5 / 7.1 12.4 / 7.6 14.5 / 6.7 16.4 / 7.1
Qwen3-MoE (128, 8) 9.9 / 6.6 10.4 / 7.1 11.3 / 7.0 14.4 / 7.0 15.3 / 7.2 17.4 / 7.2
MiniMax-M3 (129, 5) 9.8 / 7.0 10.4 / 7.1 11.5 / 6.8 13.7 / 7.3 14.3 / 7.2 17.8 / 7.1
DeepSeek-V2 (160, 6) 10.5 / 6.9 10.9 / 6.5 11.8 / 6.9 15.8 / 7.1 17.0 / 7.4 already mp
E=192, topk 8 12.1 / 7.0 12.4 / 6.9 14.5 / 6.9 18.2 / 6.9 already mp already mp

Why the boundary is M=17 and E=128:

  • At M<=16 the two kernels are close or one-shot wins at E=128 (gpt-oss M=8: 5.9 / 6.7, M=16: 7.5 / 7.1), so M<=16 keeps one-shot.
  • One-shot has a step between M=16 and M=17. With row_ = ceil(M/8) odd, SubTokenTile drops to 1 and the count phase goes from 1 to 3 serial iterations (MiniMax-M3: 8.1 us at M=16, 9.8 us at M=17).
  • Below E=128 one-shot stays close to larger M: Mixtral (E=8) is faster up to M~56, and Qwen1.5-MoE (E=60) and OLMoE (E=64) are within 8% of multi-phase up to M=24. Those shapes are left alone. E=60/64 at M>=32, where one-shot is 1.1-1.7x slower, would need its own threshold.

Coverage: 13 shapes from E=8 to E=512, block_size 16 and 32, M=1..64 plus 72..256. Sweeping auto dispatch on main and on this branch, two rounds with the GPUs swapped: exactly the 352 points the new clause predicts switch from one-shot to multi-phase, and all are faster, at 0.33-0.76x (median 0.49x) of main's latency. The other 1520 points dispatch identically (latency ratio geomean 0.999).

An earlier independent re-measurement, before the rebase onto 42c319b, used eager hipEvent timing, cold and warm graphs, and torch.profiler, on three GPUs with different seeds. Under the three non-profiler methods every switched point was at least 1.18x faster. torch.profiler showed gpt-oss M=17 at 1.02-1.04x; in this environment profiler kernel times include dispatch wait, which penalizes the two-kernel multi-phase path.

End to end (vLLM main 5d35ce3, vllm bench serve, random 1024 in / 512 out)

The e2e arms use the image's aiter 0.1.26 build with the same statement changed. Both arms rebuild module_moe_sorting_opus from source; it is the only module that differs. A probe at graph capture confirmed the switched sizes: MiniMax-M3 and gpt-oss captured M=24..56 use one-shot on main and multi-phase with this change. The kernel sweep on 42c319b selects the same 352 points with the same speedups, so these numbers still apply; I did not re-run e2e after the rebase.

Method: fresh server per run, 4 runs per block, first run discarded. The block is repeated with the two arms' GPUs swapped. Medians below are over the 6 warm runs:

model concurrency (rows) total tok/s median TPOT median TTFT
MiniMax-M3-MXFP4 + EAGLE3 (3 tokens), TP4 13 (52) 6131 -> 6355 (+3.65%) 5.97 -> 5.76 ms (-3.5%) 195.7 -> 193.5 ms
MiniMax-M3-MXFP4 + EAGLE3 (3 tokens), TP4 7 (28) 3771 -> 3830 (+1.6%) 4.55 -> 4.47 ms (-1.8%) see note
gpt-oss-120b, TP1 23 10115 -> 10304 (+1.9%) 6.37 -> 6.24 ms (-2.0%) 227 -> 239 ms
gpt-oss-120b, TP1 41 13987 -> 14332 (+2.5%) 8.32 -> 8.11 ms (-2.6%) 251 -> 255 ms

TPOT improves in both GPU assignments for every row. For MiniMax-M3 at concurrency 13 and both gpt-oss rows, throughput ranges of the two arms do not overlap.

Notes:

  • MiniMax-M3 at concurrency 7: TTFT follows the GPU set rather than the arm, so throughput there is +6.2% with one assignment and -2.0% with the other. TPOT moves -2.0% and -1.5%.
  • gpt-oss TTFT is 1.5-5% higher in both assignments, with overlapping ranges. Prefill sorting (M>56) dispatches identically in both arms. The cause is not verified.

I measured only MI355X.

Correctness

One-shot and multi-phase outputs were compared bitwise: sorted_ids, sorted_weights, sorted_expert_ids for valid blocks, num_valid_ids and moe_buf. They were identical at all 1872 sweep points in both rounds on 42c319b. An independent check extended this to 13,824 points: 16 shapes x 6 routing patterns (random, skewed, single hot expert, ties, half invalid ids) x 2 block sizes x 72 M values. That check also compared both kernels against an exact torch reference and covered the output_aux, local_topk_ids, expert_mask and num_local_tokens paths. Since the outputs are identical, this change only affects latency.

Test plan

On gfx950, rebased on main 42c319b:

  • test_moe_sorting_opus_host_dispatch_boundaries: fails on main (unexpected auto dispatch for E=128, M=17) and passes with this change. Two deliberately wrong variants fail at their boundaries: tokens_ >= 16 fails at E=128 M=16, and num_experts_ >= 127 fails at E=127 M=17.
  • python3 op_tests/test_moe_sorting.py, the default matrix: all opus/ck/flydsl error columns are 0 (386 rows) and the FlyDSL graph capture tests pass, both on main and on this branch.
  • python3 op_tests/test_moe_sorting.py -e 128 129 160 192 255 256 385 -t 8 5 6 8 8 8 9 -m 1 16 17 24 40 56 128: all error columns are 0 (394 rows).
  • ruff 0.16.0 and black pass. clang-format leaves the changed lines unchanged.

Related

Powered by Hyperloom, with human review, writing and testing.

…phase MoE sorting

Opus auto dispatch keeps one-shot sorting while rows fit in LDS. On gfx950
with 128 to 255 experts this covers M up to 24..56, where one-shot is
1.15-3.05x (median 1.98x) slower than multi-phase; outputs are bitwise
identical.

For dispatch_policy=auto on gfx950, also select multi-phase at E>=128 with
at least 17 tokens. Other architectures, E<128, M<=16 and forced policies
are unchanged.

Extend the host dispatch boundary test with E=127/128/192 and M=17, and
update the E=255 expectation for M=17 and M=24.
@lishuoshuo-amd
lishuoshuo-amd requested a review from a team October 29, 2026 06:35
@lishuoshuo-amd

Copy link
Copy Markdown
Contributor Author

@xiaofei-zheng @zufayu @valarLip Could you review? It adds one clause to the gfx950 crossover rule from #5987: E=128..255 at M>=17 now selects multi-phase. The 352 switched sweep points are all faster with bitwise-identical outputs; every other point dispatches as on main (data in the description). Fork PR, so the workflows need a maintainer approval to run. Thanks!

@github-actions github-actions Bot changed the title [HIP] [OPUS] [Perf] Route gfx950 E=128..255 decode at M>=17 to multi-phase MoE sorting [HIP] [Perf] Route gfx950 E=128..255 decode at M>=17 to multi-phase MoE sorting Oct 29, 2026
@github-actions

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:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7134 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot added the HIP label Oct 29, 2026
@zufayu
zufayu self-requested a review October 30, 2026 01:27
@zufayu zufayu self-assigned this Oct 30, 2026
@lishuoshuo-amd

Copy link
Copy Markdown
Contributor Author

@zufayu Thanks for picking this up! Could you approve the workflows so CI can run? Happy to address any comments.

@zufayu zufayu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the gfx950 MoE sorting dispatch boundary change and its boundary tests. The main-vs-PR sweep shows the newly switched shapes are faster, with bitwise-identical sorting outputs, and the unchanged shapes retain their previous dispatch. Approved from my side. Please run and pass the required CI before merging.

@lishuoshuo-amd

Copy link
Copy Markdown
Contributor Author

@zufayu Thanks for the review! The workflows are still waiting for approval (fork PR), so CI hasn't started. Could you click "Approve and run workflows" when you have a moment? I'll follow up on any failures.

@aiter-bot

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision bc07d04076f9 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_moe_sorting.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@zufayu
zufayu merged commit 8e452d6 into ROCm:main Nov 3, 2026
3 checks passed
yelkhamra added a commit to yelkhamra/aiter that referenced this pull request Nov 3, 2026
…for E=384 decode

ROCm#5987 made gfx950 dispatch_policy=0 (auto) pick the multi-phase Opus MoE
sort for E>=385 at every token count, and for E>=256 from 8 tokens;
ROCm#7134 added E>=128 from 17 tokens. E=384 falls one expert below the
all-M bound, so it stays on the one-shot sort at M<8.
E=384 is DeepSeek-V4-Pro's routed-expert count (top-6) when the shared
expert is not fused into the routed MoE.

In a gfx950 diagnostic with E=384, top-6 and block_m 32 under CUDA-graph
timing, the forced multi-phase sort (dispatch_policy=2) is faster than
the one-shot sort that auto selects at M=1, 2, 4 and 7; at M=8 auto is
already multi-phase. Valid-region outputs were identical. To measure it,
run op_tests/test_moe_sorting.py -e 384 -t 6 -dp 0 1 2 at those token
counts.

Lower the expert bound from 385 to 384. Only gfx950 auto dispatch at
E=384 with M<8 changes; forced policies, other architectures and every
other (E, M) keep their current kernel.

Tests: E=384 now expects multi-phase at every listed token count in the
host boundary test, a new E=383 row keeps the E=256/257 expectations to
pin the new lower side, the non-gfx950 branch asserts E=384 stays
one-shot, and (1, 384, 6) is added to the auxiliary-output and local-ID
tests that check newly multi-phase auto routes.

Signed-off-by: Yaakoub El Khamra <[email protected]>
zufayu pushed a commit that referenced this pull request Nov 4, 2026
…for E=384 decode (#7359)

#5987 made gfx950 dispatch_policy=0 (auto) pick the multi-phase Opus MoE
sort for E>=385 at every token count, and for E>=256 from 8 tokens;
#7134 added E>=128 from 17 tokens. E=384 falls one expert below the
all-M bound, so it stays on the one-shot sort at M<8.
E=384 is DeepSeek-V4-Pro's routed-expert count (top-6) when the shared
expert is not fused into the routed MoE.

In a gfx950 diagnostic with E=384, top-6 and block_m 32 under CUDA-graph
timing, the forced multi-phase sort (dispatch_policy=2) is faster than
the one-shot sort that auto selects at M=1, 2, 4 and 7; at M=8 auto is
already multi-phase. Valid-region outputs were identical. To measure it,
run op_tests/test_moe_sorting.py -e 384 -t 6 -dp 0 1 2 at those token
counts.

Lower the expert bound from 385 to 384. Only gfx950 auto dispatch at
E=384 with M<8 changes; forced policies, other architectures and every
other (E, M) keep their current kernel.

Tests: E=384 now expects multi-phase at every listed token count in the
host boundary test, a new E=383 row keeps the E=256/257 expectations to
pin the new lower side, the non-gfx950 branch asserts E=384 stays
one-shot, and (1, 384, 6) is added to the auxiliary-output and local-ID
tests that check newly multi-phase auto routes.

Signed-off-by: Yaakoub El Khamra <[email protected]>
Co-authored-by: Yaakoub El Khamra <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…phase MoE sorting (ROCm#7134)

Opus auto dispatch keeps one-shot sorting while rows fit in LDS. On gfx950
with 128 to 255 experts this covers M up to 24..56, where one-shot is
1.15-3.05x (median 1.98x) slower than multi-phase; outputs are bitwise
identical.

For dispatch_policy=auto on gfx950, also select multi-phase at E>=128 with
at least 17 tokens. Other architectures, E<128, M<=16 and forced policies
are unchanged.

Extend the host dispatch boundary test with E=127/128/192 and M=17, and
update the E=255 expectation for M=17 and M=24.
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…for E=384 decode (ROCm#7359)

ROCm#5987 made gfx950 dispatch_policy=0 (auto) pick the multi-phase Opus MoE
sort for E>=385 at every token count, and for E>=256 from 8 tokens;
ROCm#7134 added E>=128 from 17 tokens. E=384 falls one expert below the
all-M bound, so it stays on the one-shot sort at M<8.
E=384 is DeepSeek-V4-Pro's routed-expert count (top-6) when the shared
expert is not fused into the routed MoE.

In a gfx950 diagnostic with E=384, top-6 and block_m 32 under CUDA-graph
timing, the forced multi-phase sort (dispatch_policy=2) is faster than
the one-shot sort that auto selects at M=1, 2, 4 and 7; at M=8 auto is
already multi-phase. Valid-region outputs were identical. To measure it,
run op_tests/test_moe_sorting.py -e 384 -t 6 -dp 0 1 2 at those token
counts.

Lower the expert bound from 385 to 384. Only gfx950 auto dispatch at
E=384 with M<8 changes; forced policies, other architectures and every
other (E, M) keep their current kernel.

Tests: E=384 now expects multi-phase at every listed token count in the
host boundary test, a new E=383 row keeps the E=256/257 expectations to
pin the new lower side, the non-gfx950 branch asserts E=384 stays
one-shot, and (1, 384, 6) is added to the auxiliary-output and local-ID
tests that check newly multi-phase auto routes.

Signed-off-by: Yaakoub El Khamra <[email protected]>
Co-authored-by: Yaakoub El Khamra <[email protected]>
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