Repository navigation
fix(EPv2): map the gfx942 HF and VF device IDs to their models - #795
Conversation
On MI300X (gfx942, 304 CU) the flydsl EP v2 backend had no tuned geometry. lookup() fell back to _cu_scaled_default(), which sets combine_block_num to the CU count (304), and op construction asserted `combine block_num 304 exceeds xdb_flag_slots 256`. MI300X HF parts (PCI DID 0x74a9) were not in _DID_TO_MODEL either, so they never reached the MI300X entry at all. Part of ROCm#794 (MI300X only; other untuned parts above 256 CUs still need the clamp). This adds 0x74a9 to _DID_TO_MODEL and a measured MI300X schedule: dispatch 128x8 (128x16 above 1024 tokens), combine 64x8 up to 128 tokens and 32x8 above. Every block_num is <= 128, well under both the CU count and xdb_flag_slots. The MI325X schedule was not aliased, because its combine geometry is 13-19 % slower here at >= 256 tokens. How it was measured: 8x MI300X HF over xGMI, bench_ep.py with BACKENDS=flydsl COMB_MODE=pull MODES=graph, hidden 7168, topk 8, EPR 32, tokens 8..8192, bf16 and fp8 dispatch. Dispatch block {64..304} x warp {4,8,16} and combine block {32..256} x warp {2,4,8,16} were swept per leg. The minimum mean latency was picked per bucket, and the winners and runners-up were re-run twice (spread < 1 % from 128 tokens up). bf16 and fp8 pick the same geometry, so one schedule serves both. EP8 bf16 dispatch+combine pair, us, graph mode, mean of 3 rounds: | tok/rank | this table | MI325X schedule | CU fallback, combine capped 256 | |---|---|---|---| | 128 | 94 | 101 | 108 | | 1024 | 556 | 584 | 788 | | 4096 | 2048 | 2354 | 2975 | | 8192 | 4039 | 4642 | 6020 | Test plan (8x MI300X, gfx942, flydsl default backend, no geometry overrides): ``` torchrun --standalone --nproc_per_node={2,4,8} test_op.py # also TUNED=1, DTYPE=fp8 TUNED=1, HIDDEN=7168 torchrun --standalone --nproc_per_node={2,4,8} test_ep_backend_parity.py # also HIDDEN=7168 TOPK=8 EPR=32 torchrun --standalone --nproc_per_node=8 test_graph_capture.py pytest tests/python/ops/dispatch_combine_v2/test_dispatch_combine_v2_intranode.py # 17 passed, 1 skipped (fp4, gfx950-only) ``` Authored with Claude.
| # MI350X/MI355X (both 256 CU) are only separable here, not by CU count. | ||
| _DID_TO_MODEL = { | ||
| 0x74A1: "mi300x", # MI300X (gfx942, 304 CU) | ||
| 0x74A9: "mi300x", # MI300X HF (gfx942, 304 CU) |
There was a problem hiding this comment.
what is the diff in the two MI300X version?
There was a problem hiding this comment.
Sorry for the slow reply. They are effectively the same part (gfx942, 304 CU), so they can share the MI300X table. I also mapped the other gfx942 IDs from libdrm's amdgpu.ids that had no model (the VFs and the second MI300X HF ID); the PR description has the list.
detect_model() only knew the base device IDs, so an MI300X VF (0x74b5), the second MI300X HF ID (0x74bd) and an MI325X VF (0x74b9) found no model and, with no gfx942 arch fallback, fell back to the CU-scaled flydsl default that asserts on 304-CU parts. MI308X HF (0x74a8) fell back too and got an untuned geometry. The IDs and names are from libdrm's amdgpu.ids. gfx950 VFs already reach the MI355X table through the arch fallback, so they are left alone. Test: detect_model() with topology() stubbed returns mi300x for 0x74a1/0x74a9/0x74b5/0x74bd, mi325x for 0x74a5/0x74b9, mi308x for 0x74a2/0x74a8. Not run on VF hardware. Authored with Claude.
|
@jeffdaily Thanks for the contribution, and for including the sweep method and results in the table comment. Having a measured MI300X schedule instead of the CU-scaled fallback is useful. I read the diff only (I have no MI300X to run it on), and I have two comments. 1. The default no longer follows the CU count ( The module docstring says The model is picked by PCI DID, and 2. The comment and the first bucket disagree ( The header comment says the gather combine wants block 32 / warp 8 "at every count but 65..128 tokens (64x8)". The first bucket is |
…h#201225) ## Linked issue or supporting maintainer Part of pytorch#184147 ## BC-breaking? No ## Summary (human written only) There will certainly be follow-up work, but this is a verified initial implementation of TokenSwitch + MoRI. ## Agent details (if applicable) My agent came up with this analysis, but I've read and approved it. **What.** `TokenSwitchMoRI` implements the `TokenSwitch` contract from pytorch#198963 on MoRI EP v2 (https://github.com/ROCm/mori) with its flydsl kernel backend, intranode only. Both layouts are supported: flat directly, and expert_major built on MoRI's flat dispatch (slots ordered by local expert, then receive row; `max_expert_major_slots_per_rank` bounds the slot count). The first `dispatch` on a `Routing` computes the layout and later dispatches replay it. **Backward.** Since pytorch#201642, backends implement `_combine_backward` and `_dispatch_backward` themselves, and dispatch backward also returns `topk_weights` gradients. `TokenSwitchMoRI`'s combine backward replays the MoRI dispatch of the gradients. Its dispatch backward combines the token gradients, and gives each source weight `(t, k)` the gradient at its receive slot on expert k's rank: every rank's slot gradients are all_gathered in fp32 and indexed with MoRI's dest map (a MoRI combine would round them to the token dtype). **Changes to shared code.** - `_CombineAutograd.backward` sizes its gradient buffer as `max(max_recv_tokens_per_rank, rows of the combine input)`; MoRI's expert_major input can have up to `max_expert_major_slots_per_rank` rows. NCCL inputs never exceed `max_recv_tokens_per_rank`, so NCCL is unchanged. - In `test_token_switch.py`, the shared flat-layout mixin now holds pytorch#201642's weight-gradient tests (they get the backend from the test class instead of constructing `TokenSwitchNCCL`), so they run for MoRI too. Parametrized tests are expanded on the mixins that define them, which moves `TokenSwitchNCCLTest`'s two `explicit_rendezvous` tests into an NCCL-only mixin. `test_create_routing` checks the NCCL EP handle's receive count only for `TokenSwitchNCCL`, and `TokenSwitchMoRI.create_routing` raises the same `topk_idx` dtype `TypeError` as NCCL. **MoRI workarounds, in the code with comments.** - MoRI's routing handle aliases op-owned buffers that the next routing dispatch overwrites (ROCm/mori#715), so the adapter copies the dest map and receive count. ROCm/mori#733 adds `snapshot=True` for this; a TODO marks the copy for removal once a MoRI release includes it. - MoRI's kernels synchronize ranks on entry only, so two dispatches (or two combines) in a row can race a fast peer's writes into the receive buffers. The adapter fences with an `all_reduce` only when the same op repeats; alternating dispatch and combine is already ordered. **Known limitation.** On MI300X, MoRI's flydsl backend fails at op construction with default geometry (ROCm/mori#794, a MoRI tuning gap), so `TokenSwitchMoRI` currently works on MI355X but not MI300X. ROCm/mori#795 adds a tuned MI300X table. **Tests.** `TokenSwitchMoRITest` runs the flat, expert_major and contract test suites plus MoRI-only tests (38 tests) on 2+ GPUs. It skips when `mori` with flydsl is not importable, which includes current CI images, the same way the NCCL EP tests skip without `USE_NCCL_EP`. **Test Plan.** MI355X, 4 ranks and 2 ranks, torch nightly 2.16.0.dev20261117+rocm10.1 with this PR's `_token_switch.py` in place of the installed module, MoRI main e73ccc539 built from source, flydsl 0.5.0: ``` python test/distributed/test_token_switch.py -v ``` Each run: `TokenSwitchMoRITest` 38/38 passed, `TokenSwitchReferenceTest` 13/13 passed, NCCL EP classes skipped (no `USE_NCCL_EP` build). Lint (default linters and `lintrunner --take PYREFLY --all-files`) is clean. The NCCL side of the shared changes is covered only by NCCL CI. Pull Request resolved: pytorch#201225 Approved by: https://github.com/d4l3k
ROCm#1001 added per-shape MI300X EP8 schedules and ROCm#876 clamps the untuned fallback, so this branch's MI300X table is superseded; tuning_configs.py now matches main. What remains is the _DID_TO_MODEL entries for the gfx942 HF and VF device IDs, without which those parts never reach the MI300X, MI325X or MI308X schedules. Authored with Claude.
|
@kawhil-amd thanks for the review, and sorry for the slow reply. Since then #1001 added MI300X EP8 schedules covering more shapes and #876 clamps the fallback, so I dropped this PR's table in favor of #1001 (merged main in 16f3e4d). Both of your comments were on that table, so they no longer apply. For the record on the first bucket: in my sweep, combine 32x8 and 64x8 were within 0.1-0.7 us of each other from 8 to 64 tokens, and 64x8 was 7% faster at 128. What's left is the device-ID map: HF and VF gfx942 parts still miss #1001's schedules on main. @jhchouuu could you take a look too, since this routes those parts to your tables? |
|
GPU CI for
Test groups (the steps that run in those jobs): ep, kiwi, umbp, epv2, fused. Lanes follow the changed files. Adding |
|
@kawhil-amd @jhchouuu friendly ping: this is now just the five gfx942 device-ID map entries (MI300X HF/VF, MI325X VF, MI308X HF), so MI300X HF and VF hosts pick up the tuned EP8 schedules from #1001 instead of the untuned fallback. Could one of you take a look? |
jhchouuu
left a comment
There was a problem hiding this comment.
LGTM
sorry for the delay
|
/ci-rerun |
|
Re-running MoRI CI test against the current main. |
Motivation
_DID_TO_MODELmaps only the base gfx942 device IDs. MI300X HF (0x74a9, 0x74bd), MI300X VF (0x74b5), MI325X VF (0x74b9) and MI308X HF (0x74a8) resolve to no model, so the flydsl EP v2 lookup skips the per-device schedules, including #1001's MI300X EP8 schedules, and runs the CU-scaled fallback.Technical Details
utils.py: map those five IDs (from libdrm'samdgpu.ids) tomi300x,mi325xandmi308x. No table changes: the MI300X table this PR originally added is dropped in favor of #1001, and the >256-CU assert from #794 is fixed by #876.Test Plan
4x MI300X (DID 0x74a1), with
topology()reporting 0x74a9 through a wrapper outside the source tree: main resolves no model and uses the fallback (dispatch 304x16, combine 256x4); this branch resolvesmi300xand #1001's schedule.test_tuning_configs.py,test_op.py(default,TUNED=1, fp8TUNED=1),test_ep_backend_parity.pyandtest_graph_capture.pyat 2 and 4 ranks, and the intranode test matrix at 4 ranks pass, the same as on main.bench_ep.py, graph mode, bf16, hidden 7168, topk 8, 4 ranks, median of 6 rounds, dispatch+combine us:Not run on real HF or VF hardware.
Authored with Claude.