Skip to content

[HIP] perf(custom-ar): drop the gfx1250 fused AR final barrier - #7445

Merged
valarLip merged 9 commits into
ROCm:mainfrom
lirui927:fuse/f6-ar-barrier-v2
Nov 19, 2026
Merged

valarLip merged 9 commits into
ROCm:mainfrom
lirui927:fuse/f6-ar-barrier-v2

Conversation

@lirui927

@lirui927 lirui927 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

On gfx1250 at TP4 and above, prefill-sized fused all-reduce + RMSNorm calls (hidden ≥ 6144, messages above the 4 MiB low-latency limit) take the two-stage path: a reduce-scatter writes each rank's reduced shard, then ar_rmsnorm_gfx1250 reads all shards and normalizes. Each call took 5 launches (start_sync, stage 1, end_sync, stage 2, end_sync). It now takes 4. Both stage kernels are unchanged.

  • The final end_sync is removed. It only stopped a rank from rewriting its shard while a peer still read it. The only writer of a shard is the next call's stage 1, which runs after that call's first barrier, and no peer reaches that barrier before its own stage 2 has finished.
  • The barrier between the stages is the relaxed start_sync instead of the release/acquire end_sync. Stage 1's writes are published when that kernel completes, before the next launch on the same stream signals the barrier. The first start_sync already relies on this for the inputs.
  • Epoch comparison is wrap-safe. Barriers waited with observed < flag, which lets a barrier through early when the uint32 epoch wraps to 0. They now compare the signed difference. This applies to every gfx1250 custom-AR barrier.
  • Teardown waits for the peers. Without the end barrier, a drained stream on one rank no longer means its peers have finished reading its shard. On gfx1250, CustomAllreduce.close() now runs torch.cuda.synchronize() and a barrier on its group before it disposes or frees anything. The barrier is a gloo monitored_barrier capped at 60 s, and it is skipped when torch.distributed is not initialized or the group is already destroyed. torch.cuda.synchronize() is not bounded, so close() can still hang if a peer died in the middle of a collective. Only an explicit close() syncs the peers; __del__ calls close(sync_peers=False), so garbage collection never enters a collective on the group. GroupCoordinator.destroy() now destroys the device communicator before the process groups, so that barrier also runs in the normal teardown (all archs; the barrier itself is gfx1250-only).

Benefit

Per-call time, slowest rank, median of 6 interleaved rounds, HIP graphs of 20 calls. 4× MI455X, TP4, hidden 6144, gemma_norm=True, quick-reduce INT4 env. Baseline: the same tree without this change.

M bf16 out: before → after fp8 out: before → after
400 35.2 → 28.2 µs 35.9 → 29.2 µs
2517 90.6 → 82.9 µs 92.8 → 85.5 µs
4536 134.7 → 127.0 µs 134.9 → 127.8 µs

Eager calls are 3–7 µs faster too. rocprofv3 shows unchanged stage-kernel times; the two 6–9 µs end_sync launches become one ~6 µs start_sync. The teardown barrier runs once per communicator, at close().

Testing

On 4× MI455X (TP4):

  • _two_stage_barrier_case in op_tests/multigpu_tests/test_fused_ar_rms.py: 64 back-to-back two-stage calls at M = 400, 2517 and 4536 (hidden 6144, bf16 and fp8 output), each bitwise equal to the one-stage path, then again with the barrier epochs started just below 2^32. Before every 4th call one rank, in turn, lags on its stream.
    • Passes on this PR and on the baseline, with the default IPC transport and with VMM (AITER_CUSTOM_AR_FORCE_VMM=1).
    • Deliberately broken launch sequences: with the first barrier removed it fails (bytes differ) on both transports, with or without the skew. With the middle barrier removed it hangs to the timeout in 3 of 4 runs (both transports without the skew, VMM with it) and passes once (IPC with the skew), so that case is caught as a hang rather than a mismatch, and not every time.
  • A teardown stress: 40 create/close cycles of CustomAllreduce with one rank lagging on the last call and the ranks entering close() up to 0.3 s apart. Passes on both transports, bitwise equal, no hang. It also passes without the close() change, so it does not reproduce the teardown race; the barrier in close() is a guard for it, not a fix for an observed failure.
  • op_tests/multigpu_tests/test_custom_allreduce.py -t 4 --regression passes with this PR, including the teardown change (1000 rounds of mixed sizes), and on the baseline.
  • After the rebase onto main (03f9f375, which adds the LL two-shot all-reduce, the Lamport all-gather and the DCP merge on gfx1250), on 4× MI455X: _two_stage_barrier_case passes on IPC and VMM, and test_custom_allreduce.py -t 4 --regression passes, now including main's LL two-shot and LL in-place regressions. The two-stage shard sits in its own region of the meta buffer, apart from the LL and two-shot scratch, so main's new kernels never write it.
  • Author's earlier check: 3000 random-size back-to-back calls and graph replays, plus the wrap case, all bitwise equal.
  • CPU only: with gloo and 2 processes, close() waits for a peer that closes 2 s later, returns after the bounded wait when the peer never closes, and returns at once when the group is already destroyed or torch.distributed is not initialized. The baseline, this PR and both broken .cuh variants build for gfx1250.

Not covered

  • A full MiniMax-M3 serving run.
  • TP8.
  • The symm_mem transport.
  • CI: there is no gfx1250 multi-GPU runner, so the TP4 checks are run by hand.
  • pytest test_fused_ar_rms.py -k prefill_quant_tp4 times out on one rank in the test image both with and without this PR (same failure on the baseline), so the barrier case was run on its own.

PR Self-Review

Reviewed revision

86228e9

Behavior and intent

  • gfx1250 two-stage fused all-reduce + RMSNorm (TP4+, hidden >= 6144, above the 4 MiB low-latency limit) now takes 4 launches instead of 5: the final end_sync is dropped and the barrier between the stages is the relaxed start_sync. Both stage kernels are unchanged.
  • The final barrier only kept a rank from rewriting its shard while a peer still read it; the next call's barrier 1 already guarantees that, so the launch was pure overhead (6-9 us end_sync launches per rocprofv3).
  • Barrier epochs are compared by signed difference, so a uint32 wrap no longer lets a barrier through early (all gfx1250 custom-AR barriers).
  • CustomAllreduce.close() on gfx1250 syncs the device and runs a bounded (60 s) gloo barrier before freeing buffers (explicit close() only, not __del__), since a drained local stream no longer means peers are done reading its shard. GroupCoordinator.destroy() destroys the device communicator before the process groups so that barrier can run.

Validation and unverified scope

  • 4x MI455X, TP4: new _two_stage_barrier_case (64 back-to-back calls, M 400/2517/4536, bf16 and fp8 out, rotating lagging rank, epochs started near 2^32) bitwise equal to the one-stage path on IPC and VMM transports, on this PR and the baseline.
  • Negative check: removing the first barrier fails (bytes differ); removing the middle barrier hangs in 3 of 4 runs.
  • test_custom_allreduce.py -t 4 --regression passes; 40-cycle create/close stress passes (it does not reproduce the teardown race, so the close() barrier is a guard, not a fix for an observed failure).
  • Rebased on main 03f9f375: the barrier case (IPC and VMM) and test_custom_allreduce.py -t 4 --regression pass again; the regression now also covers main's LL two-shot and in-place paths.
  • CPU/gloo checks of the close() barrier: waits for a late peer, returns after the bounded wait, skips when the group is destroyed or distributed is not initialized.
  • Unverified: TP8, the symm_mem transport, a full MiniMax-M3 serving run, CI (no gfx1250 multi-GPU runner). pytest -k prefill_quant_tp4 times out on one rank in the test image on both the baseline and this PR.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

  • Arch: the launch-sequence change and epoch_before live only in custom_all_reduce_gfx1250.cuh; the close() barrier is gated on _is_gfx1250. Other archs only see the reordered GroupCoordinator.destroy().
  • Shape/dtype: the two-stage path is unchanged in its selection: !use_1stage && world_size >= 4 && hidden >= kArRmsTwoStageMinHidden, message above the low-latency limit, and the reduced shard fitting the staging region. Output dtype (bf16 or fp8) does not change the selection; both are tested.
  • Invariant: a shard's only writer is the next two-stage call's stage 1, which runs after that call's barrier 1, and no peer reaches barrier 1 before finishing its previous stage 2. Ranks are at most one barrier apart, so the signed epoch comparison is valid across the wrap.

Changed op tests

  • op_tests/multigpu_tests/test_fused_ar_rms.py
    • Covers: back-to-back two-stage calls with a lagging rank and near-wrap epochs must stay bitwise equal to the one-stage path; adds M 400 and 4536 to the prefill TP4 shapes.
    • Before this PR: the case passes on the baseline (it guards the new barrier removal rather than reproducing a baseline bug); it fails on launch sequences that drop a required barrier.
    • Not redundant: the existing prefill cases make single calls with host syncs, so they never let a peer run ahead into the next call's stage 1 or exercise the epoch wrap.

@lirui927
lirui927 force-pushed the xiaobingsuper/m3-mi455-perf-stack branch from 2c8902d to 3499407 Compare November 10, 2026 07:46
@lirui927
lirui927 force-pushed the fuse/f6-ar-barrier-v2 branch 2 times, most recently from de027ae to e06494b Compare November 12, 2026 05:08
@lirui927
lirui927 changed the base branch from xiaobingsuper/m3-mi455-perf-stack to main November 12, 2026 05:08
@lirui927
lirui927 marked this pull request as ready for review November 13, 2026 03:44
@lirui927
lirui927 requested a review from a team November 13, 2026 03:44
@github-actions github-actions Bot changed the title perf(custom-ar): drop the gfx1250 fused AR final barrier [HIP] perf(custom-ar): drop the gfx1250 fused AR final barrier Nov 13, 2026
@github-actions github-actions Bot added the HIP label Nov 13, 2026
@aiter-bot

aiter-bot commented Nov 13, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 86228e9f4023 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

- gfx1250 two-stage fused all-reduce + RMSNorm (TP4+, hidden >= 6144, above the 4 MiB low-latency limit) now takes 4 launches instead of 5: the final `end_sync` is dropped and the barrier between the stages is the relaxed `start_sync`. Both stage kernels are unchanged.
- The final barrier only kept a rank from rewriting its shard while a peer still read it; the next call's barrier 1 already guarantees that, so the launch was pure overhead (6-9 us `end_sync` launches per rocprofv3).
- Barrier epochs are compared by signed difference, so a uint32 wrap no longer lets a barrier through early (all gfx1250 custom-AR barriers).
- `CustomAllreduce.close()` on gfx1250 syncs the device and runs a bounded (60 s) gloo barrier before freeing buffers (explicit `close()` only, not `__del__`), since a drained local stream no longer means peers are done reading its shard. `GroupCoordinator.destroy()` destroys the device communicator before the process groups so that barrier can run.

Validation and unverified scope

- 4x MI455X, TP4: new `_two_stage_barrier_case` (64 back-to-back calls, M 400/2517/4536, bf16 and fp8 out, rotating lagging rank, epochs started near 2^32) bitwise equal to the one-stage path on IPC and VMM transports, on this PR and the baseline.
- Negative check: removing the first barrier fails (bytes differ); removing the middle barrier hangs in 3 of 4 runs.
- `test_custom_allreduce.py -t 4 --regression` passes; 40-cycle create/close stress passes (it does not reproduce the teardown race, so the `close()` barrier is a guard, not a fix for an observed failure).
- Rebased on main `03f9f375`: the barrier case (IPC and VMM) and `test_custom_allreduce.py -t 4 --regression` pass again; the regression now also covers main's LL two-shot and in-place paths.
- CPU/gloo checks of the `close()` barrier: waits for a late peer, returns after the bounded wait, skips when the group is destroyed or distributed is not initialized.
- Unverified: TP8, the `symm_mem` transport, a full MiniMax-M3 serving run, CI (no gfx1250 multi-GPU runner). `pytest -k prefill_quant_tp4` times out on one rank in the test image on both the baseline and this PR.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
- Arch: the launch-sequence change and `epoch_before` live only in `custom_all_reduce_gfx1250.cuh`; the `close()` barrier is gated on `_is_gfx1250`. Other archs only see the reordered `GroupCoordinator.destroy()`.
- Shape/dtype: the two-stage path is unchanged in its selection: `!use_1stage && world_size >= 4 && hidden >= kArRmsTwoStageMinHidden`, message above the low-latency limit, and the reduced shard fitting the staging region. Output dtype (bf16 or fp8) does not change the selection; both are tested.
- Invariant: a shard's only writer is the next two-stage call's stage 1, which runs after that call's barrier 1, and no peer reaches barrier 1 before finishing its previous stage 2. Ranks are at most one barrier apart, so the signed epoch comparison is valid across the wrap.

Changed op tests

- `op_tests/multigpu_tests/test_fused_ar_rms.py`
  - Covers: back-to-back two-stage calls with a lagging rank and near-wrap epochs must stay bitwise equal to the one-stage path; adds M 400 and 4536 to the prefill TP4 shapes.
  - Before this PR: the case passes on the baseline (it guards the new barrier removal rather than reproducing a baseline bug); it fails on launch sequences that drop a required barrier.
  - Not redundant: the existing prefill cases make single calls with host syncs, so they never let a peer run ahead into the next call's stage 1 or exercise the epoch wrap.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@valarLip valarLip 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.

⚠️ Action required before merge (4)

  1. Make teardown safe now that the last barrier is gone. Before this PR, a drained stream on rank A meant every peer had finished reading A's shard. That is no longer true, and the only guard is a comment (custom_all_reduce_gfx1250.cuh, block above ar_rmsnorm_reduce_scatter_gfx1250). CustomAllreduce.close() (aiter/dist/device_communicators/custom_all_reduce.py:3586) calls _ops_dispose, close_peer_buffers() and pool.close() with no cross-rank sync. As a result, a slower peer's stage 2 can read A's meta buffer after A has freed or unmapped it. The test only passes because it calls barrier_before_teardown() itself. Fix: on gfx1250, run torch.cuda.synchronize() and then a group barrier in close() before disposing or freeing (when dist is still initialized), or have dispose_gfx1250 run one end_sync_kernel first.
  2. Make the new check able to fail. The PR description says _two_stage_barrier_case also passes without this change, and no CI runner executes it, so it guards nothing. Restore the rank skew from the dropped validator: before every k-th call, add a rotating torch.cuda._sleep(...) on one rank, so peers really are in stage 2 while the fast rank finishes the call. Confirm it fails on a deliberately broken sequence, for example by also dropping the middle barrier.
  3. Drop the callable() probe. At op_tests/multigpu_tests/test_fused_ar_rms.py:1126, ptr = meta.data_ptr() if callable(meta.data_ptr) else meta.data_ptr: every _pool["meta"] entry (IPCBuffer, the VMM _Entry, symm_mem) exposes data_ptr as an int property, so the call branch is dead. Use ca._pool["meta"].data_ptr, as the product code does at custom_all_reduce.py:1926.
  4. Complete the aiter-bot PR Self-Review and fix the contradiction in the description. All the self-review sections are missing (reviewed revision a92f8b6, behavior, validation, arch/shape gate, changed op tests). "Testing" says the check passes under VMM, but "Not covered" lists the VMM transport. State which is true.

Verified OK: the shard at arRmsShardOffset is written only by stage 1, which is gated by the next call's first barrier. The relaxed middle barrier uses the same kernel-completion publish that the first start_sync already relies on for inputs. epoch_before covers every start_sync/end_sync wait, and the near-wrap memset layout matches Signal. No kernel overlap with #7396; it touches different lines of test_fused_ar_rms.py. CI is green, but the TP4 gfx1250 check is run only by hand.


Reviewed at a92f8b6.

@lirui927

Copy link
Copy Markdown
Contributor Author

1. Teardown safety. Fixed in df50aba. On gfx1250, CustomAllreduce.close() now runs torch.cuda.synchronize() and a barrier on its group before _ops_dispose, close_peer_buffers() and pool.close(). The barrier is a gloo monitored_barrier capped at 60 s. It is skipped when torch.distributed is not initialized or the group has been destroyed, and a second close() skips it, so close() cannot hang. GroupCoordinator.destroy() used to destroy cpu_group, the group the custom AR uses, before it destroyed the device communicator, so the barrier would never have run in the normal teardown. The device communicator is now destroyed first. The case's own final barrier_before_teardown() is dropped (88270d6). The worker's barrier_before_teardown() in its finally predates this PR and every multi-GPU test has it, so it stays. On 4x MI455X a teardown stress (40 create/close cycles, one rank lagging, ranks entering close() up to 0.3 s apart) passes on both transports. It also passes without this change, so it does not reproduce the race; the barrier is a guard.

2. Make the check able to fail. Done in 88270d6. Before every 4th call one rank, in turn, runs torch.cuda._sleep(1_000_000) on its stream, so the other ranks run ahead into the next call. On 4x MI455X it passes on this PR and on the baseline (IPC and VMM). With the first barrier removed it fails (bytes differ) on both transports, with or without the skew. With the middle barrier removed (your example) it hangs to the timeout in 3 of 4 runs and passes once (IPC with the skew), so that sequence is caught as a hang, not a mismatch, and not every time.

3. callable() probe. Done in 88270d6: ptr = ca._pool["meta"].data_ptr.

4. Description. The description now states the behavior, the validation and the unverified scope, and the VMM contradiction is fixed. The unskewed check did pass under AITER_CUSTOM_AR_FORCE_VMM=1, and the skewed check passes under VMM too, so VMM is no longer listed as not covered. I'm not adding the self-review section.

@lirui927
lirui927 requested a review from valarLip November 16, 2026 05:05
lirui927 pushed a commit that referenced this pull request Nov 16, 2026
This reverts commit 8eaddb1. The current #7445 is applied again after the main all-reduce commits it now builds on.

@valarLip valarLip 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.

⚠️ Action required before merge (4)

  1. Drop the new getattr on _is_gfx1250 in close(). At aiter/dist/device_communicators/custom_all_reduce.py:3603, getattr(self, "_is_gfx1250", False) guards an attribute that __init__ always sets (line 1278, before any early return). Write if self._is_gfx1250 and getattr(self, "_ptr", 0):, or set self._ptr = 0 next to line 1278 and drop that getattr too.
  2. Run the teardown barrier only from an explicit close(), not from __del__. __del__ calls close(), so a CustomAllreduce dropped without close() now enters monitored_barrier on cpu_group whenever GC happens to run on that rank. That collective can mismatch whatever its peers are doing on the group at that moment, or block GC for 60 s. Skip _sync_peers_before_free() on the __del__ path, since destroy() already closes explicitly on every rank. Also fix the comment at 3587-3592: torch.cuda.synchronize is unbounded, so close() can still hang if a peer died in the middle of a collective. Only the barrier is bounded.
  3. Add the PR Self-Review section to the description (item 4 of the last review is half done). The VMM contradiction is fixed. The aiter-bot sections (reviewed revision 88270d6, behavior, validation, arch/shape gate, changed op tests) are still missing.
  4. Minor: remove the barrier= flag on _prefill_quant_worker / _run_prefill_quant_regression (test_fused_ar_rms.py:1149,1181). The only caller always passes True, so call _two_stage_barrier_case(rank) unconditionally. Also move load_hip_runtime (line 1116) to the module imports.

Verified OK at head: no kernel other than stage 1 writes the shard region at arRmsShardOffset, including the LL, one-shot, AG and RS paths. The next call's barrier 1 cannot pass until every peer has finished stage 2, so the final end_sync really is redundant. Both two-stage barriers run on slot 0, so ranks stay at most one epoch apart, and epoch_before is correct at the wrap. The near-wrap case crosses 2^32 during its second combo. Moving the communicator ahead of the process groups in destroy() is required, because otherwise the barrier would run on an already destroyed cpu_group. The perf numbers are in the description: 7 µs/call saved at M=400 (35.2→28.2 µs), and 7-8 µs at M=2517 and M=4536. CI is green. Note that the skew test can only fail on a broken barrier 1, since the dropped barrier is redundant by construction, and no CI runner executes it (gfx1250 TP4 is run by hand).


Re-reviewed at 88270d6. Already fixed: teardown sync in close() + destroy() order (df50aba), rank skew in the barrier check (88270d6), callable() probe removed (test_fused_ar_rms.py:1126), VMM contradiction in the description.

@zufayu

zufayu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Review routing reminder: @TennyWang1223 is the primary reviewer for the communication/all-reduce scope on this PR. @zufayu is backup/co-review. Please route the next technical review/action to Tenny; CI status remains a separate merge gate.

lirui927 and others added 7 commits November 17, 2026 08:17
The two-stage fused AR + RMSNorm path launched five kernels per call:
start_sync, reduce-scatter, end_sync, ar_rmsnorm, end_sync. Keep both
stages unchanged and launch four:

- Drop the final end_sync. It only kept a rank from rewriting its staged
  shard while peers still read it, and the only writer of that shard is the
  next two-stage call's stage 1, which already waits behind that call's
  start_sync; no peer reaches it before its stage 2 has completed.
- Make the barrier between the stages a relaxed start_sync_kernel instead of
  the release/acquire end_sync_kernel. The shard is published by the
  completion of stage 1 before the barrier is signalled on the writer's
  stream, which is how start_sync already publishes the inputs. The
  system-scope release and the per-poll device-scope invalidate only cost
  time.
- Compare barrier epochs by signed difference so a slot's uint32 epoch can
  wrap: a plain "observed < flag" passes a barrier early once flag wraps to 0.

Both stages compile to the same code as before. Folding the barriers into
the stages instead costs more than the launches it saves. One acq_rel
arrival per block on a grid counter emits global_wb scope:SCOPE_DEV in every
block; in a one-GPU replay that per-block release is 73-85% of the previous
attempt's slowdown at 2517 and 4536 rows and about half at 400 rows, and the
same-word atomics are most of the rest. In the same replay a start_sync at
the top of every stage-2 block makes stage 2 as much slower as the two
launches it removes, and one epoch word polled by every block is a hot spot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- tests/test_custom_all_reduce_gfx1250_barrier_protocol.py (CPU only): a
  four-rank model of the four-launch protocol under random interleavings,
  across a uint32 epoch wrap, fails on stale or torn reads, on buffers
  overwritten while a peer reads them and on deadlock; it also confirms the
  model catches the races each barrier prevents and the plain comparison's
  failure at the wrap. Source checks pin the launch sequence.
- op_tests/multigpu_tests/validate_f6_ar_barrier.py (TP4): two-stage vs
  one-stage bitwise in eager calls with rank skew and in graph replays, plus
  --stress-steps (random-size back-to-back calls and multi-call graphs) and
  --near-wrap (barrier epochs just below 2^32), under a pool timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r_rms

Add one case to the gfx1250 TP4 prefill regression (test_prefill_quant_tp4):
at M = 400, 2517 and 4536, hidden 6144, bf16 and fp8 output, 64 two-stage
calls run back to back, alternating two inputs so every call rewrites each
rank's staged shard, and must match the one-stage path bit for bit. The run
is repeated with every barrier epoch set to 2**32 - 256, so it crosses the
uint32 wrap. M = 400 and 4536 are also added to the prefill shapes, whose
existing timing table then covers the shapes of the reported numbers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The TP4 check in test_fused_ar_rms.py replaces the stand-alone validator
and the CPU protocol model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without the end barrier, a rank whose stream has drained can still have its
staged shard read by a slower peer's stage 2. Say that the meta buffer may
be freed or unmapped only after every rank has synchronized. Comment only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gfx1250 two-stage fused AR + RMSNorm no longer ends with a barrier, so
a drained stream on one rank does not mean the peers have finished reading
its staged shard. On gfx1250, CustomAllreduce.close() now synchronizes the
device and joins a barrier on its group before it disposes or frees
anything. The barrier is a gloo monitored_barrier bounded at 60 s, and it is
skipped when torch.distributed is not initialized or the group is already
destroyed, so close() cannot hang on a peer that never closes. A second
close() skips it.

GroupCoordinator.destroy() destroyed cpu_group, the group the custom AR
uses, before it destroyed the device communicator, so that barrier would
never run in the normal teardown. Destroy the device communicator first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Before every 4th call one rank, in turn, sleeps on its stream, so the other
ranks run ahead into the next call while it lags. Without the skew the
ranks stay close to lockstep, and a missing barrier would rarely show.

Read the meta buffer address as ca._pool["meta"].data_ptr, an int property
on every transport, and drop the case's final barrier_before_teardown():
CustomAllreduce.close() now syncs the ranks before freeing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 force-pushed the fuse/f6-ar-barrier-v2 branch from 88270d6 to 0c2621b Compare November 17, 2026 08:50

@valarLip valarLip 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.

⚠️ Action required before merge (4)

  1. Keep the teardown barrier out of __del__, and fix the "cannot hang" comment. This was item 2 of the last review and is still open after the rebase. __del__ (aiter/dist/device_communicators/custom_all_reduce.py:3966) calls close(), which on gfx1250 runs _sync_peers_before_free() (line 3941). So a CustomAllreduce that is dropped without close() enters monitored_barrier on cpu_group whenever GC runs on that rank. That collective can be mismatched with whatever its peers are doing on the group, or block GC for 60 s. Fix: run the peer sync only from an explicit close(), for example with a close(sync_peers=True) that __del__ calls with False. destroy() already closes explicitly on every rank. Also correct the comment at lines 3927-3929: torch.cuda.synchronize is unbounded, so only the barrier is bounded. Optional: when the barrier fails or times out, skip freeing the meta buffer (leak it) instead of freeing memory a peer may still read.
  2. Drop the getattr on _is_gfx1250 in close(). This was item 1 and is still open. At custom_all_reduce.py:3940, __init__ always sets the attribute (line 1339, before any early return). Write if self._is_gfx1250 and getattr(self, "_ptr", 0):.
  3. Remove the barrier= flag and hoist the import. This was item 4 and is still open. The only caller passes barrier=True (op_tests/multigpu_tests/test_fused_ar_rms.py:1218). Drop the parameter from _prefill_quant_worker (line 1149) and _run_prefill_quant_regression (line 1181), and call _two_stage_barrier_case(rank) unconditionally. Also move load_hip_runtime (line 1116) to the module imports.
  4. Fix the comment that the destroy reorder made stale. At aiter/dist/device_communicators/communicator_cuda.py:136-138, the comment still says "destroy() runs after the groups are gone". After the change to GroupCoordinator.destroy(), the device communicator is destroyed before the groups.

Verified OK at head:

  • Protocol model: I modelled the 4-launch protocol on CPU: 4 ranks, random interleavings with skew, epochs starting at 2^32-6, and mixed one-stage and LL calls. No stale read and no overwrite while a peer reads, over 400 seeds for each setup.
  • Negative checks in the model: the old < compare fails at the wrap, and dropping barrier 1 or barrier 2 fails. Teardown without the close() barrier frees a buffer a peer still reads (399/400 seeds); the old 5-launch sequence never does. So the close() sync is required, not just a guard.
  • Shard writes: stage 1 is still the only writer of the arRmsShardOffset region, including after main's lamport all-reduce (#7927).
  • Destroy order: the reorder runs the barrier on a live gloo cpu_group.
  • Perf: the numbers in the description show about 7 µs/call saved.
  • Merge and CI: the PR merges cleanly with main. The one failing check, C++ Interface Tests (MI35X), is a Docker Hub pull rate limit. No CI job runs this test: test_fused_ar_rms.py is in skip_tests, and there is no gfx1250 TP4 runner.

Re-reviewed at 0c2621b (rebased onto 03f9f37). Already fixed: PR Self-Review section in the description; earlier: teardown sync in close() + destroy() order, rank skew, callable() probe, VMM contradiction.

__del__ now calls close(sync_peers=False), so GC never enters a collective
on cpu_group; destroy() still closes explicitly on every rank. Drop the
getattr on _is_gfx1250 in close(), and say in the comment that only the
barrier is bounded, not torch.cuda.synchronize. Fix the gluon_ar comment
in communicator_cuda.py that the destroy() reorder made stale. In the test,
drop the barrier= flag (the only caller passed True) and hoist the
load_hip_runtime import.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927

lirui927 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks. All four items are addressed in 86adcea:

  • Teardown barrier out of __del__ + comment. close() now takes sync_peers=True; __del__ calls close(sync_peers=False), so GC never enters monitored_barrier on cpu_group. destroy() still calls close() explicitly on every rank, so the normal teardown keeps the sync. The comment now says only the barrier is bounded (60 s): torch.cuda.synchronize is not, so close() can still hang if a peer died in the middle of a collective. I did not add the optional leak-on-failure path.
  • getattr on _is_gfx1250. Dropped: if sync_peers and self._is_gfx1250 and getattr(self, "_ptr", 0):.
  • barrier= flag + import. Removed from _prefill_quant_worker and _run_prefill_quant_regression; _two_stage_barrier_case(rank) now runs unconditionally. load_hip_runtime is now a module import.
  • Stale comment in communicator_cuda.py. It now says destroy() does not free the Gluon inboxes, instead of claiming that it runs after the groups are gone.

Checked on CPU: black (clean on the changed lines; the remaining black diff in communicator_cuda.py is at line ~915 and already on main), ruff, py_compile, and pytest --collect-only on test_fused_ar_rms.py (16 tests).

On 4 x MI455X (TP4) at 86adcea: the two-stage barrier case passes over IPC and over VMM, and test_custom_allreduce.py -t 4 --regression passes. Interleaved TP4 timings (5 rounds each, M 400/2517/4536, bf16 and fp8) match the PR head within noise. pytest -k prefill_quant_tp4 fails the same way at the PR head and at 86adcea (as noted in the description, it fails on the baseline too).

@lirui927
lirui927 requested a review from valarLip November 18, 2026 02:27

@TennyWang1223 TennyWang1223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@valarLip valarLip 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

All four items from the last review are fixed at head. I checked each one in the code:

  • Teardown barrier kept out of __del__: close(sync_peers=True) and __del__ calls close(sync_peers=False) (custom_all_reduce.py:3940-3944,3970). The comment at 3924-3930 now says only the barrier is bounded and torch.cuda.synchronize is not.
  • getattr on _is_gfx1250 dropped: line 3943 reads self._is_gfx1250 directly. The remaining getattr(self, "_ptr", 0) is needed: __init__ returns early (e.g. line 1349) before _ptr is ever set.
  • barrier= flag removed: _two_stage_barrier_case(rank) runs unconditionally (test_fused_ar_rms.py:1170), and load_hip_runtime is a module import (line 33).
  • Stale comment fixed: communicator_cuda.py:137-139.

Re-verified at head: stage 1 is still the only writer of the arRmsShardOffset shard, and main has not touched custom_all_reduce_gfx1250.cuh since the base. epoch_before covers every start_sync/end_sync wait. final_sync/end_sync_kernel are still used elsewhere, so nothing is dead. The destroy() reorder runs the barrier on the live gloo cpu_group. The near-wrap memset (66048 words) matches Signal. The PR merges cleanly with main.

CI: the two failing shards are already failing on main (88f8a55386, run 44186759543), so this PR did not cause them. One is test_flydsl_allreduce_rank_agreement.py ('CustomAllreduce' object has no attribute '_is_gfx1250', from #7801's _init_fly_rms on a __new__ stub). The other is the test_flydsl_hgemm.py graph-replay mismatch. Two shards are still pending. No CI runner executes the TP4 gfx1250 case, so it is checked only by hand.


Re-reviewed at 86adcea. Already fixed: teardown barrier out of __del__ + comment, _is_gfx1250 getattr, barrier= flag + import, stale communicator_cuda.py comment; earlier: Self-Review section, teardown sync + destroy() order, rank skew, callable() probe, VMM contradiction.

@valarLip valarLip 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

The only new commit since my last review, 86228e9f40, merges main into the branch and changes nothing in the PR. The PR's diff against main matches 86adcea1b3 line for line (only hunk offsets moved). I re-checked the parts that main's #7927 (gfx1250 Lamport all-reduce, which touches the same files) could affect:

  • Shard writers: stage 1 is still the only writer of the arRmsShardOffset shard (custom_all_reduce_gfx1250.cuh:784; stage 2 only reads it at :885). The Lamport kernels use their own inbox and never touch Signal or the meta buffer. The LL two-shot scratch starts after the shard (ar2sScratchOffset).
  • Barrier layout: Signal is unchanged, so the near-wrap memset (66048 words) still matches it. epoch_before still covers every start_sync/end_sync wait.
  • Earlier fixes still in place: close(sync_peers=True) / __del__ -> close(sync_peers=False) (custom_all_reduce.py:4003-4007,4032-4033), self._is_gfx1250 read directly, no barrier= flag (test_fused_ar_rms.py:1170), load_hip_runtime imported at module level (:33), and the corrected communicator_cuda.py:137-139 comment.

Minor, not blocking: the PR Self-Review "Reviewed revision" still says 86adcea1b3. aiter-bot (shadow mode) asks for the head 86228e9f40.

CI: all 8 Standard Tests (1 GPU) (MI35X) shards and the gate failed because Docker Hub hit its pull rate limit while fetching rocm/pytorch:rocm7.2.4... (toomanyrequests, exit 125) before any test ran. This is not from this PR. They need a rerun. No CI runner executes the gfx1250 TP4 case, so it is checked by hand.


Re-reviewed at 86228e9 (merge of main, no PR change). Already fixed: teardown barrier out of __del__ + comment, _is_gfx1250 getattr, barrier= flag + import, stale communicator_cuda.py comment; earlier: Self-Review section, teardown sync + destroy() order, rank skew, callable() probe, VMM contradiction.

@valarLip
valarLip merged commit 0ece886 into ROCm:main Nov 19, 2026
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 20, 2026
main (ROCm#7445) now releases the device communicator in GroupCoordinator.destroy
before the process groups, which is what the FlyDSL all-to-all heaps need to
agree with their peers when freeing IPC buffers; the docstring now says why
the order matters. If a heap is still closed after its group is gone, it logs
a warning with the buffers it leaves mapped instead of leaking them silently.

CPU test: the communicator is destroyed before either process group, borrowed
communicators and groups are only dropped, and the late close warns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 21, 2026
- create_tensor maps one dcp_mailbox PeerBuffer instead of a second copy of
  its alloc / exchange / open loop. The ranks agree on the mapping outcome,
  so a failed hipIpcOpenMemHandle raises on every rank (none waits in the
  next collective) and the failing buffer's allocation and opened mappings
  are released. Ranks asking for different sizes raise on every rank.
- close(): synchronize + barrier before unmapping the peers, barrier before
  freeing the own buffers. Skipped when the group is already destroyed: the
  ranks can no longer agree that the peers are done. GroupCoordinator.destroy
  releases its device communicator before its process groups (ROCm#7445), so
  destroy_dist_env() reaches this with the group alive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 21, 2026
main (ROCm#7445) now releases the device communicator in GroupCoordinator.destroy
before the process groups, which is what the FlyDSL all-to-all heaps need to
agree with their peers when freeing IPC buffers; the docstring now says why
the order matters. If a heap is still closed after its group is gone, it logs
a warning with the buffers it leaves mapped instead of leaking them silently.

CPU test: the communicator is destroyed before either process group, borrowed
communicators and groups are only dropped, and the late close warns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants