Repository navigation
fix(ep/intranode training): restore replay-mode payload dispatch dropped by #532 - #675
Conversation
…ernel The gfx1250 bring-up split cache-routing dispatch into three non-replay phases and removed the replay branch, so MoriCombine.backward's replay dispatch sent no payload, leaving grad_x stale and causing exploding grad norms. Re-add the replay path: read (destPe, destTokId) back from the cached dispDestTokIdMap and scatter weights, indices, scales, and tokens. Token counters are intentionally untouched because the host derives total_recv from the routing handle in replay mode.
The replay-correctness test only checked routing-map immutability and the recv token COUNT, so the ROCm#532 regression that dropped the replay branch of EpDispatchIntraNodeKernel_body (replay dispatch moved zero payload) still passed. Route the same grad payload through a fresh cache-routing op and compare downstream combine outputs (source-token order, invariant to recv-slot assignment). Fails on the buggy kernel, passes with the restored replay branch. Co-authored-by: Cursor <[email protected]>
The cache-routing reference op in the replay-correctness payload guard still relied on a routing handle, making it vulnerable to the same class of bugs as the replay path. Switch the reference to the fully independent default path: default dispatch populates the op-owned routing maps, so the combine reads them directly and serves as a bug-independent oracle for the scattered payload.
|
Validated on MI355X (gfx950), 8 GPUs, with this PR's diff applied on current main (78b7a5f). The PR branch itself does not configure against a TheRock SDK without cmake/FindNUMA.cmake from main; it merges cleanly. Reproducer from #714 (2 GPUs): main gives A separate payload-tagged probe (replay after another dispatch, replay immediately after the cached dispatch, and combine after replay) now passes on every rank at EP2, EP4, and EP2 with top-k 2 / 1 expert per rank; on main all three replay checks fail with zero rows moved. tests/python/ops/test_dispatch_combine_routing_handle.py from this PR, 8 GPUs: against a main build, test_replay_correctness[intra] fails on all 8 ranks (max diff 22.8 to 28.3); against this PR, 7/7 pass. Non-replay dispatch timing is unchanged (EP4, hidden 7168 bf16, top-k 8, 256 experts, 4096 tokens/rank, median of 50, mean over ranks, A/B/A/B): default path 1098.7 / 1095.9 us on main vs 1097.8 / 1089.5 us with the PR; return_routing=True 1129.5 / 1131.9 us vs 1130.8 / 1117.6 us. Replay dispatch with the PR takes 1095.7 / 1080.1 us (on main it is a ~30 us no-op). Drafted with Claude (AI assistant) and reviewed by me. |
jhchouuu
left a comment
There was a problem hiding this comment.
LGTM
I also verified it on the gfx950 and it passed.
Motivation
Restore correctness of replay-mode dispatch, which is used in MoE training
backward pass. Since #532 (
ae9635f7, "feat(ep/intranode): bring MoE dispatch/combineup on gfx1250 (MI450)"), intra-node replay-mode dispatch moved no payload, so the
scattered activations/gradients were left stale. In Megatron-LM MoE training this surfaced
as an exploding gradient norm and immediate divergence,
while the forward loss stayed exactly correct.
The forward pass was unaffected because it uses cache-routing dispatch + replay-routing
combine (both intact). Only the backward pass uses replay-routing dispatch
(
MoriCombine.backward→op.dispatch(routing=...)), which was the single broken path.Technical Details
#532refactoredEpDispatchIntraNodeKernel_body(src/ops/dispatch_combine/intranode.hpp)into three block-cooperative phases (count tokens → reserve slots → scatter payload), and
gated all three on
if (args.tokenIndices && args.inpTokenBuf && !args.replayMode).This inadvertently dropped the pre-#532
elsebranch that handled replay routing, so inreplay mode the kernel skipped every phase and moved zero payload into
dispatchOut(
grad_xstayed stale).Fix: re-add the replay branch. In replay mode we recover
(destPe, destTokId)from thedispDestTokIdMapwritten by the matching cache-routing dispatch, then copy metadata(indices, weights, scales) and the token payload — exactly the pre-#532 behavior.
destPeTokenCounter/dispTokOffsetare intentionally left untouched: in replay mode thehost takes
total_recvfrom the routing handle rather than the kernel's signal, and thecompletion handshake is a pure ordering barrier.
Why existing tests missed it
test_replay_correctnessexercised replay-dispatch but only asserted routing-mapimmutability and the recv token count. A replay dispatch that moves zero payload leaves
the routing maps untouched and preserves the count, so all assertions passed while no
activation was scattered.
Regression guard added: after the replay dispatch, route the same payload through a
fresh op on the fully independent default path (no routing handle) and compare downstream
combine outputs. Combine outputs are in source-token order, so the check is invariant to
the recv-slot assignment that differs across ops; a broken replay (stale/zero payload)
diverges by ~activation magnitude and trips the assertion.
Files changed
src/ops/dispatch_combine/intranode.hpp— restore replay-mode payload dispatch.tests/python/ops/test_dispatch_combine_routing_handle.py— payload guard in_replay_correctness(covers IntraNode + InterNodeV1, single- and two-node).Test Plan
pytest tests/python/ops/test_dispatch_combine_routing_handle.py -k replay_correctnesson 8 GPUs, covering:
test_replay_correctness[intra]— IntraNode.test_replay_correctness[v1]— InterNodeV1, single-node.test_replay_correctness_v1_two_nodes— InterNodeV1, 2-node RDMA (gpu_per_node=4).Submission Checklist