Skip to content

[HIP] fix(custom_ar): make 6-rank custom collectives correct - #7149

Merged
TennyWang1223 merged 4 commits into
mainfrom
yitingw1/allgatherv_world_size
Nov 2, 2026
Merged

TennyWang1223 merged 4 commits into
mainfrom
yitingw1/allgatherv_world_size

Conversation

@yitingw1

@yitingw1 yitingw1 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

CustomAllreduce offers four collectives, but not at the same group sizes:

Collective Kernels instantiated for (off gfx1250)
all-reduce 2, 4, 6, 8 ranks
all-gather, all-gatherv, reduce-scatter 2, 4, 8 ranks

The Python gates that decide whether a collective takes the custom path read the all-reduce list (_SUPPORTED_WORLD_SIZES = [2, 4, 6, 8]), or no list at all. At 6 ranks all three gather / scatter collectives are sent to a kernel that does not exist:

Entry Gate at 6 ranks What happens
custom_all_gatherv no world-size check inputs copied into the pool, then throw "allgatherv world_size error": the process dies
custom_reduce_scatter (should_custom_rs → should_custom_ar) passes dispatch hits default: printf(...) and returns: no kernel launches, the output is uninitialized memory
custom_all_gather (should_custom_ag; GroupCoordinator.all_gather(use_custom=True) skips even that) passes when fully connected same: silent garbage

The crash is at least visible; the other two degrade accuracy with nothing but a line on stdout.

The all-reduce, which does run at 6 ranks, has its own bug there. cross_device_reduce_1stage (the small-message path, under 80 KiB at 6 ranks) splits its 512 threads into one group per rank, tnum_gpu = 512 / ngpus. At 6 ranks that is 85, so threads 510 and 511 get warp_id == 6: they read through dp.ptrs[6], which a 6-rank group never fills (zero after graph registration, uninitialized in eager), and store into tmp_smem past the six rank groups. The 2-stage path already sends 6 ranks to its _naive kernel; the 1-stage path did not. test_custom_allreduce.py -t 6 hits it at once (illegal memory access), and so does any 6-rank model decode: rocm-debug-agent named cross_device_reduce_1stage<bf16, 6, false> (MEMORY_VIOLATION).

ATOM hits all of this at -pcp 6: in prefill each MoE layer gathers the routed rows across ranks with all_gatherv and reduce-scatters the result back, and in decode it all-reduces the MoE output across the same 6 ranks. Today the gather crashes; with only the gather fixed, the reduce-scatter would return garbage; with both fixed, decode still faults in the 1-stage all-reduce. So all of them are fixed together.

Technical Details

  • One gate. _GATHER_SCATTER_WORLD_SIZES = (2, 4, 8) and _has_gather_scatter_kernel(). Every entry to the three collectives asks it and declines without a kernel, the same way they already decline past their size limits, so the caller falls back to NCCL:
    • custom_all_gatherv returns None;
    • should_custom_rs and should_custom_ag return False;
    • GroupCoordinator.all_gather(use_custom=True), which calls the custom all-gather directly without should_custom_ag, checks it before choosing the custom path.
  • gfx1250 unchanged. gfx1250 runs its own *_gfx1250 gather / scatter kernels with their own group sizes; the gate is always true there.
  • Fail loudly. The reduce-scatter and all-gather dispatches throw on a world size or split dim they have no kernel for (7 places) instead of printing and returning, so an entry a future change misses crashes instead of corrupting outputs.
  • all_gather without a device communicator. GroupCoordinator.all_gather reads device_communicator.ca_comm only when use_custom is set and a communicator exists; the world group has none, and all_gather on it worked on main.
  • Custom-only entries raise clearly. GroupCoordinator.custom_all_gather / tensor_model_parallel_custom_all_gather take the custom kernel with no fallback (callers check should_custom_ag() first, as ATOM's indexer does). At a size without a kernel they now raise a RuntimeError naming all_gather(use_custom=True) before launching, instead of the dispatch's allgather world_size error.
  • CI at 6 ranks. .github/scripts/aiter_test.sh runs test_custom_allreduce.py -t 6 --regression and test_custom_allgatherv.py -t 6 after their default sizes when the runner has at least 6 GPUs.
  • 1-stage all-reduce. In cross_device_reduce_1stage the THREAD_NUM % ngpus leftover threads (warp_id == ngpus) skip the loads and shared-memory stores and only join the barriers. 2, 4 and 8 divide 512, so nothing changes for them. Of the other kernels sized by THREAD_NUM / ngpus, the 2-stage ones are not used at 6 ranks (_naive instead) and the gather / scatter ones are 2 / 4 / 8 only.

Once this lands, ATOM can drop its 2 / 4 / 8 special case (ROCm/ATOM#2789 already does).

Test Plan

python op_tests/multigpu_tests/test_custom_allgatherv.py -t 6   # new: declines + NCCL results
python op_tests/multigpu_tests/test_custom_allgatherv.py -t 8   # unchanged path
python op_tests/multigpu_tests/test_custom_allreduce.py -t 6 -m graph   # existing test, 6 ranks
python op_tests/multigpu_tests/test_custom_allreduce.py -t 6 -m eager
python op_tests/multigpu_tests/test_custom_allreduce.py -t 8 -m graph   # unchanged path
python -m pytest tests/test_group_coordinator_all_gather.py             # CPU: all_gather path choice

At a group size with no kernel the test checks that custom_all_gatherv returns None and should_custom_rs / should_custom_ag are False, and that the NCCL fallbacks come out right: all_gatherv (uniform, ragged, one rank empty), reduce_scatter_tensor (small integers, so the sums are exact in bf16) and all_gather(use_custom=True). Whether a group size has a kernel comes from the communicator itself, so gfx1250 still runs the custom checks.

Test Result

MI355X, 8 GPUs:

Run Result
-t 6, this PR OK: 0 bad bytes for all_gatherv (uniform, ragged, one rank empty), reduce_scatter_tensor and all_gather(use_custom=True), rows 1 to 384
-t 8, this PR OK, timings as before (one launch 8–45 µs vs 18–58 µs per tensor)
-t 6, custom_all_gatherv gate removed fails: RuntimeError: allgatherv world_size error
-t 6, should_custom_rs gate removed fails at assert not should_custom_rs
-t 6, should_custom_ag gate removed fails at assert not should_custom_ag
-t 6, GroupCoordinator.all_gather gate removed fails: RuntimeError: allgather world_size error (silent garbage before the throw)
test_custom_allreduce.py -t 6 -m graph, before the 1-stage fix fails: HIP error: an illegal memory access was encountered
test_custom_allreduce.py -t 6 --regression (new (79, 512) tail shape, one-stage) OK; with the 1-stage fix reverted: illegal memory access
test_custom_allreduce.py -t 6, eager size sweep OK
test_custom_allreduce.py -t 8, graph sweep OK
ATOM DeepSeek-V4-Pro -tp 1 -pcp 6, custom all-reduce on, gsm8k 100 q 0.97 (before: decode graph capture faults; with custom all-reduce off: 0.94). Run on aiter 3511006 with this PR's changes applied

Unrelated failure: the first tail check, (1023, 512) bf16 (two-stage), can mismatch on the first call of a fresh process (480 elements in one -t 6 run, 956 in one -t 8 run). Both runs came right after a test that had crashed with a GPU memory fault on the same GPUs; reproducing that order failed 5 / 5, while 27 runs not preceded by a fault all passed. The one-stage kernel is not launched before the failure and at 8 ranks the new guard is always true, so it predates this PR and is not covered here.

PR Self-Review

Reviewed revision

5dd0493

Behavior and intent

At 6 ranks (off gfx1250) the custom all-gather, all-gatherv and reduce-scatter fall back to NCCL and the one-stage all-reduce no longer reads or writes out of bounds. The all-gather, all-gatherv and reduce-scatter have no 6-rank kernels: custom_all_gatherv, should_custom_rs, should_custom_ag and GroupCoordinator.all_gather(use_custom=True) now decline, so they run through NCCL, where before the all-gatherv crashed and the other two returned uninitialized memory; their C++ dispatch throws on such a size instead of printing. The one-stage all-reduce does run at 6 ranks, but its two leftover threads per block read through a peer pointer slot the group never fills; they now skip the memory accesses. GroupCoordinator.all_gather no longer reads a device communicator a group may not have (the world group), and the custom-only all-gather entries raise a clear error at 6 ranks.

Validation and unverified scope

MI355X, 8 GPUs: python op_tests/multigpu_tests/test_custom_allgatherv.py -t 6 passed (0 bad bytes for all_gatherv, reduce_scatter_tensor, all_gather(use_custom=True)), -t 8 passed with unchanged timings, and removing each of the four gates alone makes -t 6 fail at that gate. test_custom_allreduce.py -t 6 --regression with the new one-stage shape (79, 512) passed, and failed with an illegal memory access with the one-stage fix reverted; the -t 6 eager sweep and -t 8 graph sweep passed. In ATOM, DeepSeek-V4-Pro at -tp 1 -pcp 6 with the custom all-reduce on scored gsm8k 0.97 (100 q, aiter 3511006 plus these changes); before, decode graph capture faulted. At 5dd049325, the two multi-GPU tests as the updated aiter_test.sh runs them passed: default size, then -t 6 --regression / -t 6. python -m pytest tests/test_group_coordinator_all_gather.py passed, and fails with main's AttributeError when the all_gather line is reverted.

Unverified: gfx1250 (the gates are always true there and the one-stage change only affects group sizes that do not divide 512) and MI300X / MI250X were not tested. The CI multi-GPU job has not run the new 6-rank commands yet. The prefetch guard in the one-stage kernel is defensive at 6 ranks (the dispatch keeps one iteration there). A first-call two-stage mismatch that appears only right after another process faulted on the same GPUs (see Test Result) predates this PR and is not covered.

PR-specific question

The CI change runs two more commands inside the existing multi-GPU job: after python3 "$file" for test_custom_allreduce.py and test_custom_allgatherv.py, the same file again with -t 6 --regression / -t 6 when torch.cuda.device_count() is at least 6. It runs with that job's existing permissions and environment, adds no secrets, tokens or new inputs, and reads no PR text or labels; the only PR-controlled code it executes is these two test files, which the job already ran from the PR checkout. So it does not widen what fork PR code can reach.

Changed op tests

op_tests/multigpu_tests/test_custom_allgatherv.py: it is the only test of custom_all_gatherv, and it only ran at group sizes that have the kernel. It now also covers a group size without one (-t 6): every custom entry must decline and the NCCL fallbacks of all_gatherv, reduce_scatter_tensor and all_gather(use_custom=True) must match the reference byte for byte. No existing test runs these collectives at 6 ranks; before this PR it fails there (the all-gatherv throws, the others return garbage).

op_tests/multigpu_tests/test_custom_allreduce.py: at 6 ranks the tail regression adds (79, 512) bf16, the only shape in --regression under the 80 KiB one-stage cutoff, so -t 6 --regression reaches cross_device_reduce_1stage<T, 6>; its existing shapes all take the two-stage path. It fails with an illegal memory access without the one-stage fix. Other group sizes keep their shapes.

Submission Checklist

🤖 Generated with Claude Code

… kernel

The custom all-reduce runs at 2, 4, 6 and 8 ranks, but the all-gather,
all-gatherv and reduce-scatter kernels exist for 2, 4 and 8 only. At 6
ranks custom_all_gatherv threw after copying into the pool, and the
reduce-scatter and all-gather printed and returned, leaving their outputs
uninitialized.

- _has_gather_scatter_kernel() (always true on gfx1250, which has its own
  kernels) gates custom_all_gatherv, should_custom_rs, should_custom_ag and
  GroupCoordinator.all_gather(use_custom=True), so they fall back to NCCL.
- The reduce-scatter and all-gather dispatches throw on a world size or
  split dim they have no kernel for instead of printing.
- test_custom_allgatherv.py at 6 ranks checks every path declines and that
  all_gatherv, reduce_scatter_tensor and all_gather come out right.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@yitingw1
yitingw1 requested a review from a team October 29, 2026 09:21
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7149 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 5dd049325922 · 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

At 6 ranks (off gfx1250) the custom all-gather, all-gatherv and reduce-scatter fall back to NCCL and the one-stage all-reduce no longer reads or writes out of bounds. The all-gather, all-gatherv and reduce-scatter have no 6-rank kernels: `custom_all_gatherv`, `should_custom_rs`, `should_custom_ag` and `GroupCoordinator.all_gather(use_custom=True)` now decline, so they run through NCCL, where before the all-gatherv crashed and the other two returned uninitialized memory; their C++ dispatch throws on such a size instead of printing. The one-stage all-reduce does run at 6 ranks, but its two leftover threads per block read through a peer pointer slot the group never fills; they now skip the memory accesses. `GroupCoordinator.all_gather` no longer reads a device communicator a group may not have (the world group), and the custom-only all-gather entries raise a clear error at 6 ranks.

Validation and unverified scope

MI355X, 8 GPUs: `python op_tests/multigpu_tests/test_custom_allgatherv.py -t 6` passed (0 bad bytes for `all_gatherv`, `reduce_scatter_tensor`, `all_gather(use_custom=True)`), `-t 8` passed with unchanged timings, and removing each of the four gates alone makes `-t 6` fail at that gate. `test_custom_allreduce.py -t 6 --regression` with the new one-stage shape `(79, 512)` passed, and failed with an illegal memory access with the one-stage fix reverted; the `-t 6` eager sweep and `-t 8` graph sweep passed. In ATOM, DeepSeek-V4-Pro at `-tp 1 -pcp 6` with the custom all-reduce on scored gsm8k 0.97 (100 q, aiter 35110065d plus these changes); before, decode graph capture faulted. At `5dd049325`, the two multi-GPU tests as the updated `aiter_test.sh` runs them passed: default size, then `-t 6 --regression` / `-t 6`. `python -m pytest tests/test_group_coordinator_all_gather.py` passed, and fails with main's `AttributeError` when the `all_gather` line is reverted.

Unverified: gfx1250 (the gates are always true there and the one-stage change only affects group sizes that do not divide 512) and MI300X / MI250X were not tested. The CI multi-GPU job has not run the new 6-rank commands yet. The prefetch guard in the one-stage kernel is defensive at 6 ranks (the dispatch keeps one iteration there). A first-call two-stage mismatch that appears only right after another process faulted on the same GPUs (see Test Result) predates this PR and is not covered.

PR-specific question

The CI change runs two more commands inside the existing multi-GPU job: after `python3 "$file"` for `test_custom_allreduce.py` and `test_custom_allgatherv.py`, the same file again with `-t 6 --regression` / `-t 6` when `torch.cuda.device_count()` is at least 6. It runs with that job's existing permissions and environment, adds no secrets, tokens or new inputs, and reads no PR text or labels; the only PR-controlled code it executes is these two test files, which the job already ran from the PR checkout. So it does not widen what fork PR code can reach.

Changed op tests

`op_tests/multigpu_tests/test_custom_allgatherv.py`: it is the only test of `custom_all_gatherv`, and it only ran at group sizes that have the kernel. It now also covers a group size without one (`-t 6`): every custom entry must decline and the NCCL fallbacks of `all_gatherv`, `reduce_scatter_tensor` and `all_gather(use_custom=True)` must match the reference byte for byte. No existing test runs these collectives at 6 ranks; before this PR it fails there (the all-gatherv throws, the others return garbage).

`op_tests/multigpu_tests/test_custom_allreduce.py`: at 6 ranks the tail regression adds `(79, 512)` bf16, the only shape in `--regression` under the 80 KiB one-stage cutoff, so `-t 6 --regression` reaches `cross_device_reduce_1stage<T, 6>`; its existing shapes all take the two-stage path. It fails with an illegal memory access without the one-stage fix. Other group sizes keep their shapes.

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.

@yitingw1

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

…GPUs

cross_device_reduce_1stage splits its 512 threads into ngpus groups of
512 / ngpus. At 6 ranks that leaves threads 510 and 511 with warp_id 6:
they read through dp.ptrs[6], a slot a 6-rank group never fills, and
store into tmp_smem past the six rank groups. DeepSeek-V4 at -pcp 6
faulted there in decode (rocm-debug-agent: cross_device_reduce_1stage<
bf16, 6, false>, MEMORY_VIOLATION).

- Threads with warp_id >= ngpus skip the loads and stores and only join
  the barriers; 2, 4 and 8 divide 512 and are unchanged.
- test_custom_allreduce.py adds a (79, 512) tail shape at 6 ranks, under
  the 80 KiB one-stage cutoff; it fails with an illegal memory access
  without the fix.
- Note on the two-stage dispatch why 6 ranks take the naive kernels.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@yitingw1 yitingw1 changed the title [HIP] fix(custom_ar): decline gather / scatter at group sizes with no kernel [HIP] fix(custom_ar): make 6-rank custom collectives correct Oct 30, 2026
yitingw1 added a commit to ROCm/ATOM that referenced this pull request Oct 30, 2026
ROCm/aiter#7149 makes custom_all_gatherv decline group sizes it has no
kernel for, so all_gatherv falls back to NCCL there. The grouped gather
now takes the one-collective path at every PCP size, 6 included.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

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

review summary
Verdict: Request changes. One small fix, then approve.

The approach is sound. At 6 ranks, gather/scatter now falls back to NCCL, and the one-stage all-reduce no longer reads out of bounds. Main has no merge conflict, there are no CI failures, and Multi-GPU tests were skipped because the PR has no multi-GPU label.

Must fix

  • [verified] aiter/dist/parallel_state.py:1183: regression in GroupCoordinator.all_gather.
    • self.device_communicator.ca_comm is read unconditionally, even when use_custom=False. device_communicator is None for the world group (init_world_group), and for standard groups when custom_group_config is set.
    • Repro: two ranks on gloo, init_world_group([0,1]).all_gather(x, dim=0). Head raises AttributeError: 'NoneType' object has no attribute 'ca_comm'. Main's version gets past this line.
    • Fix:
      dc = self.device_communicator
      ca_comm = dc.ca_comm if (use_custom and dc is not None) else None

Notes

  • [verified] One entry point is still ungated. GroupCoordinator.custom_all_gather / tensor_model_parallel_custom_all_gather call ca_comm.custom_all_gather without checking _has_gather_scatter_kernel(). At 6 ranks off gfx1250 they now raise instead of returning garbage. That is better than main, but please either gate them or document that they raise.
  • [verified] CI never runs the 6-rank paths. The tests default to -t 2 (all-gatherv) and -t 8 (all-reduce), so the new 6-rank branches never run in CI. Please run CI with the multi-GPU label and consider adding a -t 6 case.

Checked, no issues

  • 1-stage all-reduce fix: the leftover threads skip both load/store sites and still reach every barrier. Ranks 2, 4 and 8 are unchanged.
  • Other kernels sized by THREAD_NUM / ngpus: none of them is dispatched at 6 ranks, or they already throw. The new allreduce_residual from main (#6270) uses the _naive kernel at 6 ranks.
  • gfx1250: unaffected, because it uses its own *_gfx1250 ops.
  • printf → throw in the C++ dispatch: these are host-side, so the error reaches Python as a RuntimeError.

…runs

Review follow-ups on #7149:
- GroupCoordinator.all_gather read device_communicator.ca_comm on every
  call, so a group built without a device communicator (the world group)
  raised AttributeError even with use_custom=False. It reads it only when
  use_custom is set and a communicator exists.
- GroupCoordinator.custom_all_gather / tensor_model_parallel_custom_all_gather
  take the custom kernel with no fallback: they now raise a clear error
  before launching at a group size without one, and say so.
- CI runs test_custom_allreduce.py (-t 6 --regression) and
  test_custom_allgatherv.py (-t 6) at 6 ranks after their default sizes,
  where the runner has 6 GPUs.
- tests/test_group_coordinator_all_gather.py covers the path choice on CPU.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@yitingw1 yitingw1 added the ci:multi-gpu Trigger multi-GPU op tests on PR label Oct 30, 2026
@yitingw1

Copy link
Copy Markdown
Contributor Author

Thanks. Fixed in 5dd0493:

  • all_gather reads ca_comm only when use_custom is set and a device communicator exists; tests/test_group_coordinator_all_gather.py covers it on CPU (it fails with the AttributeError on the old line).
  • custom_all_gather / tensor_model_parallel_custom_all_gather stay custom-only (callers check should_custom_ag() first), but now raise a clear RuntimeError at a size without a kernel, before launching, and their docstrings say so.
  • aiter_test.sh now also runs test_custom_allreduce.py -t 6 --regression and test_custom_allgatherv.py -t 6 when the runner has 6+ GPUs; both passed locally on MI355X. Added ci:multi-gpu.

@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

@TennyWang1223
TennyWang1223 merged commit 47eaf46 into main Nov 2, 2026
98 of 102 checks passed
@TennyWang1223
TennyWang1223 deleted the yitingw1/allgatherv_world_size branch November 2, 2026 03:33
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
* [HIP] fix(custom_ar): decline gather / scatter at group sizes with no kernel

The custom all-reduce runs at 2, 4, 6 and 8 ranks, but the all-gather,
all-gatherv and reduce-scatter kernels exist for 2, 4 and 8 only. At 6
ranks custom_all_gatherv threw after copying into the pool, and the
reduce-scatter and all-gather printed and returned, leaving their outputs
uninitialized.

- _has_gather_scatter_kernel() (always true on gfx1250, which has its own
  kernels) gates custom_all_gatherv, should_custom_rs, should_custom_ag and
  GroupCoordinator.all_gather(use_custom=True), so they fall back to NCCL.
- The reduce-scatter and all-gather dispatches throw on a world size or
  split dim they have no kernel for instead of printing.
- test_custom_allgatherv.py at 6 ranks checks every path declines and that
  all_gatherv, reduce_scatter_tensor and all_gather come out right.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [HIP] fix(custom_ar): one-stage all-reduce reads past its ranks at 6 GPUs

cross_device_reduce_1stage splits its 512 threads into ngpus groups of
512 / ngpus. At 6 ranks that leaves threads 510 and 511 with warp_id 6:
they read through dp.ptrs[6], a slot a 6-rank group never fills, and
store into tmp_smem past the six rank groups. DeepSeek-V4 at -pcp 6
faulted there in decode (rocm-debug-agent: cross_device_reduce_1stage<
bf16, 6, false>, MEMORY_VIOLATION).

- Threads with warp_id >= ngpus skip the loads and stores and only join
  the barriers; 2, 4 and 8 divide 512 and are unchanged.
- test_custom_allreduce.py adds a (79, 512) tail shape at 6 ranks, under
  the 80 KiB one-stage cutoff; it fails with an illegal memory access
  without the fix.
- Note on the two-stage dispatch why 6 ranks take the naive kernels.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [HIP] fix(dist): all_gather without a device communicator; 6-rank CI runs

Review follow-ups on #7149:
- GroupCoordinator.all_gather read device_communicator.ca_comm on every
  call, so a group built without a device communicator (the world group)
  raised AttributeError even with use_custom=False. It reads it only when
  use_custom is set and a communicator exists.
- GroupCoordinator.custom_all_gather / tensor_model_parallel_custom_all_gather
  take the custom kernel with no fallback: they now raise a clear error
  before launching at a group size without one, and say so.
- CI runs test_custom_allreduce.py (-t 6 --regression) and
  test_custom_allgatherv.py (-t 6) at 6 ranks after their default sizes,
  where the runner has 6 GPUs.
- tests/test_group_coordinator_all_gather.py covers the path choice on CPU.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
valarLip pushed a commit to ROCm/ATOM that referenced this pull request Nov 14, 2026
* [PCP] Fewer prefill collectives per layer, no reindex readback

Each V4 attention layer under PCP prefill issued 3-5 separate all-gathers
(main compressor input, indexer compressor input, extend K -- two under fp8
KV -- and positions), each through torch.distributed. Now it issues two:

- `pcp_allgather_rerange_many` gathers several tensors in one grouped
  `all_gatherv` and restores token order per tensor. One-byte dtypes travel
  as uint8, since past aiter's custom all-gather limit the call falls back to
  PyNCCL, which has no fp8 dtype.
- The extend K is gathered together with the positions its SWA write
  addresses the ring by. Positions are gathered rather than read off the
  forward context: an MTP draft pass runs at the target's positions + 1.
- `_launch_compressors` projects both compressors' inputs and gathers them in
  one collective; `Compressor.forward(combined=)` takes the result.

V4-Pro (30 CSA + 31 HCA layers): 397 -> 245 collectives per prefill step.

`pcp_reindex_ragged` sized its output with a blocking `.item()`, four times
per prefill step (sixteen under PCP+TBO). The builder already computes the
four prefill indptrs in numpy; it now keeps them on the metadata
(`paged_prefill_indptr_cpu`) and each rank's local indptr is computed on the
host (`pcp_local_indptr`), in both the full-batch and the per-request-group
paths.

`pcp_round_robin_split` returns unit strides: `.contiguous()` leaves a
one-row shard at row stride pcp_size, which aiter's cached-positions RoPE
rejects.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] DSpark: project context KV on each rank's own rows

After a PCP prefill the aux hooks hold only this rank's round-robin rows.
`compute_draft_kv` all-gathered the three aux hidden states (~42 KiB a row)
and every rank then projected all rows into window KV, the same work on
every rank. The projection (main_proj + norm, then per stage wqkv_a + norm +
RoPE + fake-quant) works row by row, so project only the local rows at their
own positions, gather the projected KV rows (1 KiB a row a stage, one
grouped collective for all stages), and write them as before.

`DSparkLayer.write_context_kv` is split into `context_kv_rows` and
`write_context_kv_rows`. A draft opts in with `context_kv_by_rows`; only V4
DSpark does, and any other draft keeps gathering the aux states.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] Grouped gather: fall back off aiter's 2/4/8 ranks; check row counts

aiter's custom all-reduce, which `all_gatherv` tries first, runs at 6
ranks, but its all-gatherv kernel exists for 2, 4 and 8 only and throws
otherwise. The attention-side gathers went through torch.distributed before
the grouped gather, so PCP 6 worked; take one tensor at a time there again.

Also assert that the grouped inputs share a row count (a mismatch threw on
the custom path but passed on PyNCCL), and fix two review nits.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(config): key the compile cache on the KV cache dtype

The DSpark drafter branches on the KV cache dtype while tracing
(`dspark_fp8_planned`), but `Config.compute_hash` left it out -- the known
limitation #2566 deferred. A DSV4-Pro DSpark run with `--kv-cache-dtype
bf16` after an fp8 one in the same container hashed to the same directory,
loaded the fp8 drafter graph and died in warmup on every rank
(`IndexError: list index out of range` on the split graph's outputs).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] TBO: hold comm-stream gather outputs until the compute stream reads them

Under TBO a PCP gather runs on the comm stream, so its output is allocated
there, while the compute stream reads it. When the forward frees it, the
caching allocator hands the memory straight back to the comm stream, and the
comm stream waits only on its own ubatch's compute: the other ubatch's next
collective can overwrite it before this ubatch's kernels have read it.

On main this corrupts the gathered extend K. DSV4-Pro, pcp8 + `--enable-tbo`,
gsm8k (200 q): main 0.69 / 0.675 on two nodes. With only the extend-K gathers
on the main code path: 0.71 (K alone: 0.70, positions alone: 0.975); the same
plus `record_stream` on the gathered tensors: 0.965. The grouped gathers of
this branch have the same shape, and score 0.96 only by timing.

`tbo_mark_used_on_compute` records the compute stream on such tensors after
`tbo_switch_to_compute_sync`, for the attention-side gathers (extend K and
positions, the compressor inputs) and FusedMoE's PCP routed-rows gather and
reduce-scatter. The DP and mori TBO paths have the same shape and are left
alone here.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] TBO: run the PCP comm phases through tbo_on_comm

The previous commit marked the comm-stream outputs by hand at four call
sites, and nothing would notice one going missing: this branch scores 0.96
under TBO with or without the marks. `tbo_on_comm(fn, *args)` makes the
comm phase one call -- yield, `fn` on the comm stream, switch back, hold
every tensor it returns -- so a phase cannot skip the hold, and a test
fails if V4 attention or `FusedMoE._run_experts` writes a phase out by hand.

`tbo_mark_used_on_compute` now takes the compute stream from the TBO
context instead of the current stream, so it no longer depends on being
called after the switch back. `pcp_aux_rows` documents that it describes the
base layer-hook capture; EAGLE3 strips aux off the target's output instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] TBO: hold every comm-stream output; one wire format for grouped gathers

Review follow-ups on #2789:
- tbo_all_reduce and FusedMoE's DP gather / reduce-scatter run through
  tbo_on_comm, like the PCP comm phases, so their comm-stream outputs are
  held for the compute stream; the hold walks nested lists and tuples.
  Mori is unchanged: it returns views of its own per-ubatch buffers.
- Under a graph the V4 compressors read their PCP-gathered inputs on side
  streams; hold them for those streams.
- gather_rows moves to pcp_utils and carries one-byte dtypes as uint8 and
  the rest as is (aiter's all_gatherv copies bytes; only its PyNCCL
  fallback lacks fp8 / e8m0). MoE's DP, PCP and comm-fused gathers and the
  PCP grouped gather share it.
- The allocator-reuse positive control skips under expandable_segments.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(tbo): stub aiter's communication_op in the TP all-reduce test

tbo_all_reduce imports it ahead of the TBO branch, and the non-GPU CI's
aiter has no aiter.dist.communication_op.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] Grouped gather: drop the 6-rank special case, rely on aiter

ROCm/aiter#7149 makes custom_all_gatherv decline group sizes it has no
kernel for, so all_gatherv falls back to NCCL there. The grouped gather
now takes the one-collective path at every PCP size, 6 included.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(h2d): give the PCP reindex test the host prefill indptr

_apply_pcp_reindex now derives each rank's indptr from the host copy the
builder publishes (paged_prefill_indptr_cpu); the test builds its metadata
by hand, so it sets that copy beside kv_indptr_extend.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(h2d): bring the V4 indexer publication GPU test up to date

The file failed 20 of 22 cases on main with RUN_H2D_GPU_TESTS=1, all from
fixtures that fell behind the code:
- set_pcp patched pcp_round_robin_query_indices (removed in #2688); the
  builder reads get_pcp_rank.
- make_runner lacked forward_vars["batch_info"], config.max_num_seqs and
  the builder's csa_layers, max_model_len_idx, _local_heads and
  index_logits_workspace.
- The padded decode case modelled the bucket width through
  UBatchWrapper._decode_ub_running_bs; since #2692 the split comes from
  _prepare_ubatch_decode's split_bs, so the test passes the bucket.
- prepare_prefill was called with a total_tokens_num the fake batch lacks.

22/22 pass on this branch and on its merge base.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* DSV4 PCP: assert host and GPU paged-prefill indptrs agree in length

Both PCP reindex paths (rank and PCP+TBO group) compute local offsets from
the host copy and reindex the GPU copy; a length mismatch would silently
reindex against a different query set. Clarify that after either reindex
both copies describe the same rank- or group-local queries.

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

* DSV4 PCP: stage only this rank's paged-prefill rows on main's stage/finish split

Port the per-rank paged-prefill build onto main's stage_prefill /
finish_prefill structure (#3136):
- Under PCP, stage_prefill stages this rank's own rows (pcp_split) and
  finish_prefill reindexes them; pad query segments get length 0 and the
  per-step indptr/indices fill and reindex helpers are gone.
- Under PCP+TBO each group stages and finishes its own ub{i}_ inputs
  (_stage_pcp_group / _finish_pcp_group) with group-rebased cu_seqlens_q,
  block_tables and replay ranges.
- _pcp_split_rows takes scheduled and running token counts separately.
- Move shared comm helpers into atom/distributed/comm_utils.py.
- Tests: rank segments with running > scheduled, PP relay _aux_blocks in
  the DSpark drafter stubs.

gsm8k 5-shot 200q, V4-Pro -tp 1 -pcp 8: 0.965, +TBO prefill 0.970,
DSpark k=5 0.975 (acceptance 63.76%).

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

* Drop the duplicate kv_cache_dtype compile-hash factor left by the main merge

main's #3072 keys the compile cache on kv_cache_dtype as this branch's
222feeb did; the merge kept both, repeating the keyword in two test
fixtures (SyntaxError at collection) and the hash factor in Config.
Keep main's version.

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

* fix(spec_decode): check target_pcp_split before PCP world size in pcp_aux_rows

Non-PCP steps no longer query the PCP group, which is a MagicMock under the
aiter stub and broke test_deepseek_v41_mono_hi_served_step in CI.

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

* fix(v4 attn): make _apply_pcp_reindex take cu_q / block_tables explicitly

The 1110 port defaulted cu_q_per_seq_gpu and block_tables_gpu to the
whole batch's, so a PCP+TBO group caller that forgot them would build
indices from the wrong rows without an error. Make both keyword-only
and required; the whole-batch caller passes its own rows. Also note in
pcp_aux_rows that target_pcp_split implies PCP is enabled.

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

* test(comm-fused-moe): ids travel as int32, drop the no-op view

`gather_rows` passes int32 through unchanged since it moved to
`comm_utils`; the float-carrier comment and its `.view` were stale.

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

* dspark(v4.1): drop the unreachable PCP branch from write_context_kv

V4.1 refuses context parallel at startup, so the proposer never passes it
`pcp_num_tokens`. Restore main's signature, drop its split test, and keep
it out of the override scan.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
* [HIP] fix(custom_ar): decline gather / scatter at group sizes with no kernel

The custom all-reduce runs at 2, 4, 6 and 8 ranks, but the all-gather,
all-gatherv and reduce-scatter kernels exist for 2, 4 and 8 only. At 6
ranks custom_all_gatherv threw after copying into the pool, and the
reduce-scatter and all-gather printed and returned, leaving their outputs
uninitialized.

- _has_gather_scatter_kernel() (always true on gfx1250, which has its own
  kernels) gates custom_all_gatherv, should_custom_rs, should_custom_ag and
  GroupCoordinator.all_gather(use_custom=True), so they fall back to NCCL.
- The reduce-scatter and all-gather dispatches throw on a world size or
  split dim they have no kernel for instead of printing.
- test_custom_allgatherv.py at 6 ranks checks every path declines and that
  all_gatherv, reduce_scatter_tensor and all_gather come out right.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [HIP] fix(custom_ar): one-stage all-reduce reads past its ranks at 6 GPUs

cross_device_reduce_1stage splits its 512 threads into ngpus groups of
512 / ngpus. At 6 ranks that leaves threads 510 and 511 with warp_id 6:
they read through dp.ptrs[6], a slot a 6-rank group never fills, and
store into tmp_smem past the six rank groups. DeepSeek-V4 at -pcp 6
faulted there in decode (rocm-debug-agent: cross_device_reduce_1stage<
bf16, 6, false>, MEMORY_VIOLATION).

- Threads with warp_id >= ngpus skip the loads and stores and only join
  the barriers; 2, 4 and 8 divide 512 and are unchanged.
- test_custom_allreduce.py adds a (79, 512) tail shape at 6 ranks, under
  the 80 KiB one-stage cutoff; it fails with an illegal memory access
  without the fix.
- Note on the two-stage dispatch why 6 ranks take the naive kernels.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [HIP] fix(dist): all_gather without a device communicator; 6-rank CI runs

Review follow-ups on ROCm#7149:
- GroupCoordinator.all_gather read device_communicator.ca_comm on every
  call, so a group built without a device communicator (the world group)
  raised AttributeError even with use_custom=False. It reads it only when
  use_custom is set and a communicator exists.
- GroupCoordinator.custom_all_gather / tensor_model_parallel_custom_all_gather
  take the custom kernel with no fallback: they now raise a clear error
  before launching at a group size without one, and say so.
- CI runs test_custom_allreduce.py (-t 6 --regression) and
  test_custom_allgatherv.py (-t 6) at 6 ranks after their default sizes,
  where the runner has 6 GPUs.
- tests/test_group_coordinator_all_gather.py covers the path choice on CPU.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR HIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants