Repository navigation
[HIP] [OPUS] [Perf] Route gfx950 large-expert decode to multi-phase MoE sorting - #5987
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The process-wide architecture cache can select the wrong policy in heterogeneous multi-GPU processes.
Review effort: Balanced
Findings: 1
What changed in this PR
Routes gfx950 large-expert decode workloads to multi-phase MoE sorting.
Changes:
- Adds gfx950-specific auto-dispatch thresholds.
- Adds boundary tests for automatic and forced policies.
| File | Description |
|---|---|
csrc/include/moe_sorting_opus.h |
Adds architecture-aware dispatch. |
op_tests/test_moe_sorting.py |
Tests dispatch boundaries. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Thread the target device through workspace sizing and remove the process-wide architecture cache so allocation and launch use the same policy in heterogeneous processes. Add explicit-device and architecture-switch coverage alongside the existing boundary test.
|
@valarLip — this PR changes the default gfx950 auto-dispatch policy for the shared MoE sorting path. Could you please provide explicit owner sign-off when convenient? The implementation now threads the target device through workspace sizing, removes the process-wide architecture cache, and adds boundary/device-switch coverage. I also enabled |
Cache gfx950 capability by device instead of querying properties on every auto dispatch. Expand boundary coverage to E=384, assert the unchanged non-gfx950 policy, and exercise auxiliary and local-ID outputs on the newly multi-phase ranges.
…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]>
…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]>


Opus auto dispatch uses one-shot sorting while rows fit in LDS, but its serial per-expert cumulative sum becomes slower on gfx950 as the expert count grows. On MI355X at E=385, one-shot versus multi-phase measured 11.63/6.57 us at M=1, 13.76/6.70 us at M=6, and 17.52/6.68 us at M=16; outputs were bitwise identical. At E=256, the same comparison measured 10.46/7.05 us at M=8, 13.62/5.75 us at M=16, and 19.19/5.57 us at M=20.
For
dispatch_policy=auto, select multi-phase on gfx950 at E>=385, or at E>=256 with at least 8 tokens. E>=512 already uses multi-phase through the existing LDS rule. Other architectures and forced policies remain unchanged. Workspace sizing receives the input tensor's device, so allocation and launch use the same architecture policy in heterogeneous processes.Added host boundary coverage for E=255/256/257/384/385 and M={1,7,8,12,16,24,25,31}, plus explicit-device, heterogeneous-architecture, auxiliary-output mapping, and local-ID tests. Local MI355X validation covered output equivalence and graph replay.
Repro:
python3 op_tests/test_moe_sorting.py -m 1 6 8 16 20 -e 256 385 -t 6 6 -dp 1 2 -p 0 -em f -accum t -rc valid.