Repository navigation
[HIP] [Perf] Route gfx950 Opus MoE sort auto dispatch to multi-phase for E=384 decode - #7359
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
Logic LGTM. The gfx950 auto-dispatch change is narrowly scoped to E=384 with M<8, the boundary/correctness coverage is appropriate, and the supplied data supports the multi-phase selection without showing a regression outside the target range. Please rebase to resolve the current conflict and rerun the required Aiter Test Gate; approval/merge should wait for the updated head and green required CI. |
…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]>
a174710 to
b283700
Compare
|
Thanks for the review. Rebased onto |
|
AMD General
Rebased. Please proceed.
From: zufayu ***@***.***>
Sent: Tuesday, November 3, 2026 3:08 AM
To: ROCm/aiter ***@***.***>
Cc: Elkhamra, Yaakoub ***@***.***>; Author ***@***.***>
Subject: Re: [ROCm/aiter] [HIP] [Perf] Route gfx950 Opus MoE sort auto dispatch to multi-phase for E=384 decode (PR #7359)
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
[https://avatars.githubusercontent.com/u/8138883?s=20&v=4]zufayu left a comment (ROCm/aiter#7359)<#7359 (comment)>
Logic LGTM. The gfx950 auto-dispatch change is narrowly scoped to E=384 with M<8, the boundary/correctness coverage is appropriate, and the supplied data supports the multi-phase selection without showing a regression outside the target range. Please rebase to resolve the current conflict and rerun the required Aiter Test Gate; approval/merge should wait for the updated head and green required CI.
—
Reply to this email directly, view it on GitHub<#7359?email_source=notifications&email_token=BKGAN7H7UWAKRDCB42XDBU35XGG5TA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNJZHA2TKMZZGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-6598553905>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BKGAN7EUMCR4WIVW3U7XQQL5XGG5TAVCNFSNUABFKJSXA33TNF2G64TZHM4DQNRWGM3TSNRRHNEXG43VMU5TMMJWHE4DGOBXGY22C5QC>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/BKGAN7GPKODZ7MB5CJWZJN35XGG5TA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNJZHA2TKMZZGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG> and Android<https://github.com/notifications/mobile/android/BKGAN7CXLWA6Y4CM3WLA7735XGG5TA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNJZHA2TKMZZGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>. Download it today!
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
…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]>
Fixes #7358
Base:
mainat016a3efb695ebf15ba132422080e7dd4f1fc2831, one commit, now rebased ontomainat6a4fa17deb060989f12ec10c366775034defe5f2(after #7134 merged; theprefer_mpand boundary-test conflict was resolved by keeping #7134's E=128..255, M>=17 term and its test expectations and applying this change on top). GPU results below come from the earlier base and were not re-run on the new base.Summary
Lower the gfx950 Opus MoE-sort auto-dispatch expert bound from
>= 385to>= 384. This changes E=384 at M<8, including M=0, from one-shot to multi-phase; forced policies and other architectures retain their existing dispatch.The comparison below, on gfx950 with the base sources, found the multi-phase sort faster than the one-shot sort that auto dispatch currently selects for E=384 at M=1, 2, 4 and 7, for both plain auto dispatch and auxiliary outputs: E=384 sits on the multi-phase side of the crossover that #5987 established for E=385. Correctness checks passed on both builds, including dirty-memory and captured-graph checks at M=0. Our GPU validation covers gfx950 only; gfx942/gfx1250 coverage and the mixed-architecture subtest are left to upstream CI and are not validated by us. A command to measure the crossover yourself is under Reproducer.
Motivation
Problem
#5987 routes gfx950 auto dispatch to multi-phase at E>=385, or at E>=256 with M>=8. Its review added E=384 to the boundary test with the E=256/257 token expectations, so the base test requires one-shot at E=384, M=1 and M=7. The reported crossover timings in #5987 cover E=256 and E=385, not E=384.
Root cause
At E=384 and M<8, the LDS rule permits one-shot and no branch of
num_experts_ >= 385 || (num_experts_ >= 256 && tokens_ >= 8) || (num_experts_ >= 128 && tokens_ >= 17)selects multi-phase. The measured E=384 crossover therefore falls immediately below the expert bound.Evidence
Build provenance. BASE uses the MoE-sort sources at
016a3efb695ebf15ba132422080e7dd4f1fc2831; PATCH applies the change below. The diagnostic runtime checkout was78f416704fa989cc9db3765bcdccc10f89e8afb8: the six pinned source files match the earlier base016a3efbapart from the patched header and test, and the four commits between that checkout and the base change only Triton code, tests and configurations. Correctness and timing runs used the same image and reproduced identical built-library bytes for each arm.Gfx950 correctness. On PATCH, the affected-shape op-test command exited 0, including the added E=384 auxiliary-output and local-ID cases; its only skip was the architecture-switch subtest requiring gfx950 and non-gfx950 devices in one process. The patched test on BASE failed at the expected E=384, M=1 assertion; BASE with its own test exited 0.
The separate exact-reference check returned
GPU_CHECK PASSfor BASE and PATCH, 26 rows each: plain and aux paths at M=0..8, and plain withnum_local_tokensat static capacities 1..8. Every row completed 20 dirty-memory eager trials and 100 graph replays without a mismatch; captured outputs were poisoned before every replay. Both E=384, M=0 modes passed on both builds, with BASE one-shot and PATCH multi-phase.The comparator checks both valid-count entries, sorted IDs including padding, real-route weights, used expert blocks, capacities, real
moe_bufrows and auxiliary mappings. Withnum_local_tokens, capacities follow the static shape while the padding sentinel follows the real count loaded by the kernels. Allocation tails are excluded.The gfx950 default regression matrix exited 0 on BASE and PATCH. Real gfx942 correctness/regression and the mixed-architecture subtest were not run.
Changes
Fix
The host test now expects multi-phase at E=384 for every listed M, adds E=383 as the lower boundary case, and asserts E=384 remains one-shot off gfx950. The auxiliary-output and local-ID tests each add
(1, 384, 6). The bound is not generalized to lower expert counts.Why it works
Changing the expert bound routes the measured E=384 small-token cases through the existing multi-phase implementation. Python sizes workspace using
topk_ids.get_device(), and launch dispatch uses the same workspace predicate underHipDeviceGuard, preserving allocation/launch agreement.Reproducer
The crossover can be measured with the same op test that #5987 used as its reproducer. On a BASE build and on a PATCH build (gfx950):
-dp 0is auto dispatch,-dp 1forces the one-shot kernel and-dp 2forces multi-phase (csrc/include/moe_sorting_opus.h, comment above the workspace predicate). Compare theopus uscolumn of the summary table: on BASE,-dp 0should track-dp 1at M<8; on PATCH it should track-dp 2, which is the faster of the two forced policies at these M. At M=8 all builds already pick multi-phase. The op test's default profile budget is short (run_perftest(..., num_warmup=1, num_iters=2)), so repeat the command several times or raise that budget locally before reading small differences.Performance (if applicable)
Kernel timing on gfx950. One gfx950 GPU, HIP
7.2.53211, PyTorch2.10.0+rocm7.2.4.git3d3aa833; E=384, top-6, block_m=32, model_dim=7168, bf16moe_buf, Opus backend. BASE and PATCH repeats alternated within one job with fresh routes per repeat; each measurement replays a CUDA graph of repeated sort calls.dispatch_policy=0) and PATCH auxiliary-output auto were each faster than the matching BASE arm. PATCH plain auto selects the same multi-phase implementation as forced policydispatch_policy=2.In our experiments on the same single GPU the multi-phase sort was faster per call at these token counts, well outside the repeat-to-repeat spread of either build.
This is kernel time only and not a throughput or end-to-end result.
Testing
Tests
CPU rerun: the real BASE/PATCH headers were compiled with
hipcc -x hip --cuda-host-only -std=c++20; fake gfx950/gfx942 device queries let the extracted upstream host-test bodies run without a GPU. The expected negative controls below demonstrate that the boundary test distinguishes the old and new selectors.The explicit-device and architecture-switch host tests pass in all four test/header combinations on both fake devices. Those CPU simulations do not validate real mixed-architecture GPU execution.
The comparator self-test, source/oracle audit and dispatch probe were rerun on CPU:
Python compilation and
git diff --checkpass. The timing summarizer was also checked on synthetic CPU input. GPU results above come from the recorded diagnostics; this documentation revision ran CPU checks only.Black/Ruff re-check done. Black
26.10.1and Ruff0.16.0passed on the changed Python file,op_tests/test_moe_sorting.py, in a fresh clone at016a3efbwith this patch applied. Exact recorded output:On the branch rebased onto
6a4fa17d, Black and Ruff0.16.0are clean onop_tests/test_moe_sorting.py, and clang-format (repository.clang-format) reports no change on the changed lines ofcsrc/include/moe_sorting_opus.h.GPU validation plan
Done on gfx950: affected-shape tests except the architecture-switch subtest, negative/positive controls, exact-reference dirty-memory and graph-replay checks including M=0 and local-token counts, the default regression matrix, and the kernel timing comparison above.
Not validated by us: the diagnostic records leave these items open:
We have no gfx942/gfx1250 hardware. Coverage on those architectures and execution of the mixed-architecture subtest are left to upstream CI; they are not prerequisites to filing this PR. A skipped subtest does not establish coverage.
Documentation
No documentation change.
Dependencies
None.
Breaking Changes
Risk / compatibility
#7134 (merged) edits the same
prefer_mppredicate, adding an E=128..255, M>=17 term, andop_tests/test_moe_sorting.py; this branch is rebased on it. The dispatch changes affect different cases: this PR changes only E=384 at M<8 (E=384 at M>=8 was already multi-phase).Affected auto-dispatch calls now need multi-phase workspace. Multi-phase launches more kernels than one-shot, so kernel-time savings alone do not establish an application-level benefit. The measured correctness coverage is gfx950 only; gfx942/gfx1250 and mixed-device correctness remain unvalidated by us and are left to upstream CI.
PR Self-Review
Reviewed revision
b28370021910Behavior and intent
On gfx950, auto dispatch (
dispatch_policy=0) of the Opus MoE sort now selects the existing multi-phase sort instead of one-shot at E=384 for M<8, including M=0, by lowering the expert bound from>= 385to>= 384. Forced policies, other architectures and every other (E, M) keep their current kernel.Validation and unverified scope
Validated on CPU: the real base and patched headers compiled host-only with
hipccand run with fake gfx950/gfx942 device queries pass the host tests, the expected negative controls fail at E=384, M=1, and the dispatch scan finds changes only at E=384, M=0..7. Validated on one gfx950 GPU at the earlier base: the affected-shape op test exited 0, the exact-reference check returnedGPU_CHECK PASSfor 26 rows on both builds, the default regression matrix exited 0, and the kernel timing comparison under Performance was run. On the rebased branch Black, Ruff0.16.0and clang-format are clean. Unverified: exact-reference correctness and default regression on gfx942, gfx1250, the mixed-architecture subtest, end-to-end throughput, and a GPU re-run on the rebased branch.PR-specific question
The changed predicate in
moe_sorting_auto_is_oneshottakes only the token count, expert count and device; dtype does not enter it. It is evaluated only for auto dispatch, only after the existing LDS rule already permits one-shot, and only on gfx950 (moe_sorting_device_is_gfx950); other architectures and forced policies 1 and 2 are unchanged. The only newly selected inputs are E=384 at M<8 (M=0..7): E>=385 at every M and E>=256 at M>=8 were already multi-phase, and the CPU scan of E=1..1024, M=0..64 on gfx950 and gfx942 found no other change. The bound is not generalized to lower expert counts. Allocation and launch agree because Python sizes the workspace withtopk_ids.get_device()and launch dispatch uses the same workspace predicate underHipDeviceGuard; this PR does not change the multi-phase implementation, which is the one forceddispatch_policy=2already selects. The GPU checks used a bf16moe_buf, top-6, block_m 32 and model_dim 7168.Changed op tests
op_tests/test_moe_sorting.py: the host dispatch-boundary test now expects multi-phase at E=384 for every listed M on gfx950, adds E=383 as the lower boundary case, and asserts E=384 remains one-shot off gfx950; the auxiliary-output and local-ID tests each add(1, 384, 6)to cover the newly multi-phase auto route. The base test required one-shot at E=384, so the patched test fails on the base header at E=384, M=1.Credit
The gfx950 crossover policy comes from #5987.