Repository navigation
[HIP] [Perf] Route gfx950 E=128..255 decode at M>=17 to multi-phase MoE sorting - #7134
Conversation
…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.
|
@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! |
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
@zufayu Thanks for picking this up! Could you approve the workflows so CI can run? Happy to address any comments. |
zufayu
left a comment
There was a problem hiding this comment.
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.
|
@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. |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
…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]>
…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]>
…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.
…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]>
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: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:Why the boundary is M=17 and E=128:
row_ = ceil(M/8)odd,SubTokenTiledrops 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).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.profilershowed 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_opusfrom 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:
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:
I measured only MI355X.
Correctness
One-shot and multi-phase outputs were compared bitwise:
sorted_ids,sorted_weights,sorted_expert_idsfor valid blocks,num_valid_idsandmoe_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 theoutput_aux,local_topk_ids,expert_maskandnum_local_tokenspaths. 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_ >= 16fails at E=128 M=16, andnum_experts_ >= 127fails 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).Related
tokens * E > 2560on all architectures) and Autotune MoE sorting dispatch: runtime kernel selection between oneshot and multi-phase paths #3525 (runtime autotuning) targeted the same E=128 gap. Both were closed by their author without review comments. This change is gfx950-only, uses the same form as the [HIP] [OPUS] [Perf] Route gfx950 large-expert decode to multi-phase MoE sorting #5987 rule, and is backed by the bitwise-equality and multi-model data above.Powered by Hyperloom, with human review, writing and testing.