Skip to content

fix(ep/intranode training): restore replay-mode payload dispatch dropped by #532 - #675

Merged
isytwu merged 3 commits into
ROCm:mainfrom
sudhu2k:sudhu/mori_main_replay_fix
Oct 8, 2026
Merged

isytwu merged 3 commits into
ROCm:mainfrom
sudhu2k:sudhu/mori_main_replay_fix

Conversation

@sudhu2k

@sudhu2k sudhu2k commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Motivation

Restore correctness of replay-mode dispatch, which is used in MoE training
backward pass. Since #532 (ae9635f7, "feat(ep/intranode): bring MoE dispatch/combine
up 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

#532 refactored EpDispatchIntraNodeKernel_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 else branch that handled replay routing, so in
replay mode the kernel skipped every phase and moved zero payload into dispatchOut
(grad_x stayed stale).

Fix: re-add the replay branch. In replay mode we recover (destPe, destTokId) from the
dispDestTokIdMap written by the matching cache-routing dispatch, then copy metadata
(indices, weights, scales) and the token payload — exactly the pre-#532 behavior.
destPeTokenCounter / dispTokOffset are intentionally left untouched: in replay mode the
host takes total_recv from the routing handle rather than the kernel's signal, and the
completion handshake is a pure ordering barrier.

  • Scope: intra-node kernel only.

Why existing tests missed it

test_replay_correctness exercised replay-dispatch but only asserted routing-map
immutability 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

  • Unit: pytest tests/python/ops/test_dispatch_combine_routing_handle.py -k replay_correctness
    on 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

sudhu2k and others added 3 commits September 15, 2026 23:04
…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.
@sudhu2k
sudhu2k requested a review from TianDi101 September 16, 2026 15:41
@sudhu2k sudhu2k self-assigned this Sep 16, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

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 rows_with_new_payload=0 ... -> FAIL on both ranks; with this PR, rows_with_new_payload=63/64 rows_still_forward_payload=0 -> PASS.

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 jhchouuu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I also verified it on the gfx950 and it passed.

@jhchouuu
jhchouuu requested a review from isytwu October 8, 2026 04:55

@isytwu isytwu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@isytwu
isytwu merged commit 28d4973 into ROCm:main Oct 8, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants