Repository navigation
[FlyDSL] [CI] [MoonEP] Balance MegaMoE v2 prefill with MoonEP placed inside the compact prepare - #6268
[FlyDSL] [CI] [MoonEP] Balance MegaMoE v2 prefill with MoonEP placed inside the compact prepare#6268JiaoliangYu wants to merge 24 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Port the virtual-id MoonEP meta (balance, top-B, owner rollback) plus a sticky slot settle into @flyc.jit emitters the prepare owner CTA can call on the gathered histogram, and split each logical (source, expert) route range into the virtual count matrix the destination plan consumes.
MegaMoEV2(moonep_slots=B) takes logical topk_ids over an [EPR | B] weight window. Prepare counts and exchanges the logical histogram once, places it with MoonEP on the owner CTA, and runs the unchanged destination plan, offset derivation and payload on the virtual count matrix it implies, so MoonEP adds no histogram exchange or barrier of its own. Fanout pairs and the aligned-pair Stage2 stay off in this mode; forward(after_prepare=...) lets the caller enqueue the slot weight copy before Stage1.
One MegaMoEV2 instance serves every shape-identical layer, so the slot tables move out of the shared workspace: new_moonep_slot_state() gives a window its own tables behind a dispatch-table copy, and bind_moonep_slot_state() selects it per call like the weight pointers.
Unplanned passes only need every expert on its owner; write that mapping directly instead of running the balance, top-B and settle rounds.
The [EPR | B] pool MoonEP fills from peers between prepare and Stage1: a VMM-stitched row-contiguous window and a prefetch kernel that skips slots already holding their expert. The placement helpers now carry their own wave/LDS helpers and the placement test its own CPU reference, so the fusion stands alone on main.
df8285b to
4ea3845
Compare
- close every VMM shareable fd once imported/exchanged instead of holding world_size fds per pool for the model lifetime - bootstrap the fd exchange over the pool's own process group with its leader's global rank, so several EP groups can share one world - settle up to 64 prefetch slots with a 64-bit bitmap; reject B > 64 - run after_prepare on the stream forward() prepared on, so the slot fill stays between prepare and Stage1 for an explicit stream Tests: EP sub-group pools and fd count, B=48 with >32 slots settled, explicit-stream forward.
Prepare keeps 8 waves; waves at or above the EP size join the barriers and store nothing. Reject weight windows above 4 GiB, which GEMM1/GEMM2 cannot address with 32-bit buffer offsets. Tests: placement R=8/4/2 x B=8/48; 8/4/2-GPU fused runs match plain MegaMoEV2 bit for bit (EP2 with B=2).
MegaMoEV2 rejects moonep_slots for other EP sizes; tests cover 8 and 4.
MoonEPVmmPool lays a rank's parts (w1, w1 scale, w2, w2 scale) back to back in one segment, each with its own [epn + B] window, so a layer needs one VMM allocation, one fd exchange and one prefetch launch instead of four. Only the segment is padded to the VMM granularity, so pad_experts goes away. Tests: slot cache with two parts (incl. a segment off the granularity), two EP4 groups in one world.
MoonEP no longer lives inside the compact prepare. MoonEPPlanner counts each rank's logical routes, exchanges the histograms once, runs the placement and rewrites every route to the virtual id of its replica; an ordinary MegaMoEV2 over R * (EPR + B) experts then runs it, so fanout pairs and the aligned-pair Stage2 stay on. Unbalanced passes only map ids to their owner. The MegaMoE files are back to main; the 4 GiB window check moves to MoonEPWeightPool. Kernels launch through _run_compiled, since flyc.compile() also runs them. Tests: planner placement and rewrite vs a CPU reference (R=8/4, B=8/48); 8/4-GPU outputs match plain MegaMoEV2 bit for bit, incl. B=48, CUDA graph, side stream; slot-cache prefetch.
With every block on the same slot the grid read one owner, over one xGMI link, at a time. DSv4-Pro EP8, 8 slots from 7 owners: 2.74 -> 1.51 ms, 102 -> 186 GB/s per rank. Tests: slot-cache prefetch (multi-part, resident skip, two EP4 groups).
|
@aiter-bot review |
[ROCm/aiter] PR #6268 — [FlyDSL] [MoonEP] Balance MegaMoE v2 prefill with MoonEP placed inside the compact prepareAdds a MoonEP planning layer in front of an unchanged MegaMoE v2: ranks exchange per-expert route histograms over mori symmetric memory, run one deterministic placement (balance to the all-rank average, top-B remote experts per destination, sticky prefetch slots), rewrite routes to virtual ids over R(EPR+B) experts, and pull the chosen remote experts' weights into local slots through a HIP-VMM pool so the plain MegaMoE runs them locally.* Review (advisory): 🔴 HIGH RISK 🔴 [verified] op_tests/test_moonep_slot_cache.py sits at op_tests/ depth 1, so the standard single-GPU op-test job shards it in and runs it as plain |
|
Where that review came from — I ran the bot on your PR to show what it does. It is not an automatic hook; nothing reviews your PR unless somebody asks. Any reviewer on the aiter allowlist can ask for one, on any PR including their own. The trigger is a comment containing the words below — shown quoted here, because quoted lines deliberately do not trigger it:
Feedback on the review itself is welcome; it is how the rules get better. |
| @@ -0,0 +1,115 @@ | |||
| # SPDX-License-Identifier: MIT | |||
There was a problem hiding this comment.
CI is red because of this PR. test_moonep_slot_cache.py is an 8-rank torchrun test sitting in the op_tests/ root, so the single-GPU job runs it with plain python and it dies with RANK expected, but not set. Please move it under multigpu_tests/ with a proper torchrun entry, or skip it when there's no distributed env.
| @@ -0,0 +1,268 @@ | |||
| # SPDX-License-Identifier: MIT | |||
There was a problem hiding this comment.
test_moonep_mega.py can't catch a regression yet.
- It fills the slots with torch.where/index_select, so the real MoonEPWeightPool.prefetch kernel is never exercised at production shapes.
- It never fails: on a mismatch it prints SOME_FAILED but still exits 0, and exact_ranks is printed, not asserted.
- It goes through _setup_dist() from test_mega_moe_v2.py, which needs torchrun, and that file is on the multigpu skip list for exactly this reason. So adding ci:multi-gpu alone won't run it.
| f"expert rows must be positive 16-byte multiples, got {row_bytes}" | ||
| ) | ||
| window = experts_per_rank + prefetch_slots | ||
| if any(window * b > 1 << 32 for b in row_bytes): |
There was a problem hiding this comment.
Off-by-one in the 4 GiB guard (moonep_weights.py:72). MegaMoE reads weights through a buffer descriptor with num_records = 0xFFFFFFFF bytes, so a window of exactly 2^32 bytes is already too big. I checked this on gfx950: at a 2^32-byte window, the last dword reads back as 0 and everything before it is fine. The guard should be >=, same as MegaMoE's own activation checks: if any(window * b >= 1 << 32 for b in row_bytes):
… checks - CI: move test_moonep_slot_cache.py to multigpu_tests; aiter_test.sh runs test_moonep_mega.py and test_moonep_slot_cache.py under torchrun on 8 gfx950 GPUs and skips elsewhere; test_shuffle_out.py runs under pytest. - test_moonep_mega.py fills the slots with MoonEPWeightPool.prefetch instead of index_select, requires bit-identical outputs on every rank, and exits non-zero on failure. - MoonEPWeightPool: the 4 GiB window guard is >= (MegaMoE's descriptors hold 2^32 - 1 bytes); prefetch checks experts_to_copy has one entry per slot and makes resident contiguous. - shuffle_scale_a16w4_out_shape(): the padded [rows, ceil8(k)] shape shuffle_scale_a16w4 returns, for sizing out= storage; shuffle_scale uses it. - Prefetch docstring states where its bandwidth table was measured.
|
No activity for 15 days, so this is now labelled |
Summary
MoonEP expert balancing in front of an unchanged MegaMoE v2. No existing file changes; the MegaMoE kernels are main's.
MoonEPPlanner(kernels/moonep_plan.py): each rank counts its logical routes per expert, the EP group exchanges the histograms once (mori symmetric buffer, epoch flags), and every rank runs the same placement on the gathered matrix: balance towards the average, keep each destination's top-B remote experts, return the rest to their owners, settle the prefetch slots stickily. Each route is then rewritten to the virtual iddest * (EPR + B) + slotof its replica. Three small kernels; one planner serves every layer, slot tables are per layer.MegaMoEV2overR * (EPR + B)experts runs the virtual ids, so fanout pairs and the aligned-pair Stage2 stay available. Unbalanced passes only map ids to their owner's copy (home_ids).MoonEPWeightPool: one P2P-readable VMM segment per rank and layer holding an[EPR | B]window for each of w1, w1 scale, w2, w2 scale (fd and device exchanged in one socket message), and one prefetch launch for all four that skips slots already holding their expert. Windows above 4 GiB (MegaMoE's 32-bit buffer offsets) are rejected.Tests
op_tests/test_moonep_plan.py(1 GPU): placement and slot tables vs a CPU reference, and the rewrite kernel's per-(source, virtual id) route counts vs a Python split of the same placement; R=8/4 x B=8/48, sticky slots, >32 slots, top-B cut, empty route slots.op_tests/multigpu_tests/test_moonep_mega.py(8 and 4 GPU): outputs bit-identical to plain MegaMoEV2 over steps, layers sharing one instance, balance on/off, B=48, CUDA graph, side stream. Negative controls (no slot fill, layers sharing slot tables) fail as expected.op_tests/test_moonep_slot_cache.py(8 GPU): multi-part prefetch, resident skip, two EP4 groups in one world, no fds kept.Results
DeepSeek-R1 fp4 on MI355X with ATOM ROCm/ATOM#2499, gsm8k (paired against plain mega, same session):
Prefill, DeepSeek-V4-Pro EP8, 1024/2 conc 2048, 1 warm + 2 timed rounds, same session: plain mega 66,687 tok/s, MoonEP 81,643 (+22.4%), mean TTFT 15.7 -> 12.8 s. The earlier prepare-fused version measured 81,711 vs 66,345 (+23.2%). Per MoE layer (EP8, 8k/16k tokens per rank) planning in front is within noise of the fused version except uniform routing at 8k tokens (+3%, ~170 us).