Skip to content

[HIP] fea: impl gfx1250 lamport allgather - #7861

Merged
zufayu merged 1 commit into
mainfrom
gfx1250_lamport_ag
Nov 16, 2026
Merged

zufayu merged 1 commit into
mainfrom
gfx1250_lamport_ag

Conversation

@TennyWang1223

Copy link
Copy Markdown
Contributor

Summary

Add a Lamport one-shot all-gather for gfx1250 and route the custom all-gather to it. On TP2 up to 16 MiB per rank and on TP4 up to 8 MiB, custom_all_gather now runs lamport_ag_gfx1250 for gathers along dim 0 or the last dim. Both tensor_model_parallel_all_gather(use_custom=True) and CudaCommunicator.all_gather go through custom_all_gather. Above the cap, along other dims, and for rows that are not whole 16B packs, the routing is unchanged.

This PR also removes an address check from the Lamport all-reduce + add gate that could hang the group.

Motivation

On gfx1250 the custom all-gather currently runs ag_ll_gfx1250 up to 4 MiB and the barrier kernels above that. In the LL kernel each 16B line carries 12B of payload plus an epoch word, and every call ends with an epoch fan-out over all blocks. The Lamport protocol from #7499 needs neither. Each rank pushes its 16B packs straight into its peers' inboxes, and the peers poll against a sentinel. So a line carries 16B of payload, and there is no barrier and no copy-in. The gather that motivated this is TP4 [4, BS, 32] int32 along dim 0 with BS 8–128, a decode case from our test team. It drops from 7.8–8.4 us to 5.0–6.0 us.

Changes

  • Kernel (custom_all_reduce_gfx1250.cuh): lamport_ag_gfx1250 is a one-shot push all-gather on the Lamport inbox of [HIP] fea: impl gfx1250 lamport ar+rms #7499. It uses the same round counters and re-arm, so it interleaves freely with the Lamport AR + RMSNorm and AR + add. A codec, picked by dtype, decides how a reader tells an arrived word from the armed sentinel:
    • fp16/bf16: the 0xffff half-word sentinel of the other Lamport kernels. A 0xffff half-word (a NaN) comes out as 0x7fff (also a NaN). Everything else is bit for bit.
    • Any other dtype: bit for bit. All-ones words are flagged in an escape inbox appended to the data inbox, a quarter of its size.
  • Ops: all_gather_lamport in module_custom_all_reduce_gfx1250. Some inputs cannot be read in place: those not 16B aligned, and those overlapping the output other than as their own dim-0 slice. Such an input is first copied into the registered input pool, as the LL all-gather already does.
  • Python:
    • CustomAllreduce.custom_all_gather takes lamport_all_gather when should_lamport_ag holds. That requires dim 0 or the last dim, a contiguous input, rows of whole 16B packs, and a size up to the Lamport cap.
    • The decision uses shapes, dtypes and the cap only, so every rank picks the same path. It runs the same in eager, warmup and capture.
    • The check runs before the int → float view, so an int16 input takes the exact codec.
    • The Lamport gates no longer look at operand addresses. should_lamport_ar_add used to check data_ptr() % 16. When ranks held differently aligned operands, some took Lamport and others took the fallback, and the group hung.
    • An unaligned operand of the Lamport AR + add or AR + RMSNorm is now copied rank-locally (_lamport_aligned).
    • AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE now caps all three Lamport ops. The defaults are unchanged: TP2 16 MiB, TP4 8 MiB. Setting it to 0 turns all three off.
  • Tests:
    • op_tests/multigpu_tests/test_ag_lamport.py (new): correctness only.
    • op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_allgather.py (rewritten): performance plus a dispatch check.
    • test_ar_add_lamport.py and test_fused_ar_rms_lamport.py: new cases with unaligned operands on the odd ranks.

Performance (if applicable)

Setup: 4x gfx1250 (256 CU), ROCm 10.1, IPC transport, CUDA graph (43 calls × 20 replays, median per rank, slowest rank reported).

  • Before: the route without this PR. That is ag_ll_gfx1250 up to 4 MiB and the barrier kernels above it, reading the captured input in place.
  • After: tensor_model_parallel_all_gather(use_custom=True) with this PR.

TL;DR: Over the shapes × dtypes × dims under the cap, TP2 is 1.08–3.13x faster (median 1.44x) and TP4 is 1.22–3.63x faster (median 1.50x). No case is slower. The median speedup over RCCL is 3.4–4.0x. Inputs above the cap keep the old route.

Decode: [4, BS, 32] int32 along dim 0

Hardware Workload/configuration Before (us) After (us) Change
gfx1250 TP2, BS=8 (4 KiB) 6.17 4.75 1.30x
gfx1250 TP2, BS=16 (8 KiB) 6.96 4.78 1.46x
gfx1250 TP2, BS=32 (16 KiB) 7.22 5.01 1.44x
gfx1250 TP2, BS=64 (32 KiB) 7.63 5.34 1.43x
gfx1250 TP2, BS=128 (64 KiB) 7.72 5.24 1.47x
gfx1250 TP4, BS=8 (4 KiB) 7.76 5.03 1.54x
gfx1250 TP4, BS=16 (8 KiB) 7.96 5.13 1.55x
gfx1250 TP4, BS=32 (16 KiB) 8.05 5.48 1.47x
gfx1250 TP4, BS=64 (32 KiB) 8.28 5.66 1.46x
gfx1250 TP4, BS=128 (64 KiB) 8.43 5.98 1.41x

Rows of hidden 7168 along dim 0

Hardware Workload/configuration Before (us) After (us) Change
gfx1250 TP2, bf16, M=1 (14 KiB) 7.16 4.88 1.47x
gfx1250 TP2, bf16, M=8 (112 KiB) 7.87 5.42 1.45x
gfx1250 TP2, bf16, M=64 (0.88 MiB) 8.83 5.90 1.50x
gfx1250 TP2, bf16, M=128 (1.75 MiB) 9.96 7.68 1.30x
gfx1250 TP2, bf16, M=256 (3.5 MiB) 14.0 9.50 1.47x
gfx1250 TP2, bf16, M=512 (7 MiB) 28.8 15.7 1.83x
gfx1250 TP2, int32, M=1 (28 KiB) 7.57 5.28 1.43x
gfx1250 TP2, int32, M=8 (224 KiB) 8.13 5.68 1.43x
gfx1250 TP2, int32, M=64 (1.75 MiB) 10.0 7.92 1.26x
gfx1250 TP2, int32, M=128 (3.5 MiB) 14.3 11.6 1.23x
gfx1250 TP2, int32, M=256 (7 MiB) 29.0 17.9 1.62x
gfx1250 TP2, int32, M=512 (14 MiB) 34.9 30.8 1.13x
gfx1250 TP4, bf16, M=1 (14 KiB) 8.09 5.25 1.54x
gfx1250 TP4, bf16, M=8 (112 KiB) 8.68 5.84 1.49x
gfx1250 TP4, bf16, M=64 (0.88 MiB) 11.3 8.10 1.40x
gfx1250 TP4, bf16, M=128 (1.75 MiB) 16.8 12.5 1.34x
gfx1250 TP4, bf16, M=256 (3.5 MiB) 25.1 15.9 1.58x
gfx1250 TP4, bf16, M=512 (7 MiB) 48.7 29.2 1.67x
gfx1250 TP4, int32, M=1 (28 KiB) 8.20 5.69 1.44x
gfx1250 TP4, int32, M=8 (224 KiB) 9.02 6.32 1.43x
gfx1250 TP4, int32, M=64 (1.75 MiB) 16.9 13.5 1.25x
gfx1250 TP4, int32, M=128 (3.5 MiB) 25.4 19.9 1.28x
gfx1250 TP4, int32, M=256 (7 MiB) 48.6 36.9 1.32x
gfx1250 TP4, int32, M=512 (14 MiB) 71.9 71.9 above cap, unchanged

Model shapes, along the last dim

Hardware Workload/configuration Before (us) After (us) Change
gfx1250 TP2, DeepSeek-V4 LM-head shard, bf16 [65, 32320] (4 MiB) 33.8 10.8 3.13x
gfx1250 TP4, DeepSeek-V4 LM-head shard, bf16 [65, 32320] (4 MiB) 64.7 17.8 3.63x
gfx1250 TP2, MiniMax-M3 logits, bf16 [12, 50016] (1.1 MiB) 10.3 7.4 1.39x
gfx1250 TP4, MiniMax-M3 logits, bf16 [12, 50016] (1.1 MiB) 13.9 11.1 1.25x
gfx1250 TP2, Kimi-K3 DCP8 fp8 KV rows as fp16 [2048, 288] (1.1 MiB) 9.09 6.97 1.30x
gfx1250 TP4, Kimi-K3 DCP8 fp8 KV rows as fp16 [2048, 288] (1.1 MiB) 13.3 10.6 1.25x

At the cap

Hardware Workload/configuration Before (us) After (us) Change
gfx1250 TP2, bf16 [1024, 8192] dim 0 (16 MiB) 36.1 30.5 1.18x
gfx1250 TP2, bf16 [1024, 8192] last dim (16 MiB) 45.3 30.3 1.50x
gfx1250 TP2, int32 [512, 8192] dim 0 (16 MiB) 36.2 33.6 1.08x
gfx1250 TP2, int32 [512, 8192] last dim (16 MiB) 45.4 33.5 1.36x
gfx1250 TP4, bf16 [512, 8192] dim 0 (8 MiB) 50.1 31.4 1.60x
gfx1250 TP4, bf16 [512, 8192] last dim (8 MiB) 67.1 31.7 2.12x
gfx1250 TP4, int32 [256, 8192] dim 0 (8 MiB) 50.0 38.9 1.29x
gfx1250 TP4, int32 [256, 8192] last dim (8 MiB) 67.1 38.6 1.74x

One row past the cap keeps the barrier kernel, so its time is unchanged.

All cases under the cap, by TP, dim and codec

[4, BS, 32] with BS 8–128, plus [M, 7168] with M 1–512. Dtypes are int32, bf16, fp16, int16 and fp32. Each shape is gathered along dim 0 and along the last dim. The edge cases are also included: uint8, fp8, int64, a partial last wave, one pack, the model shapes above, and the cap itself.

TP dim codec cases min median max
2 0 fp16/bf16 (sentinel) 38 1.18x 1.46x 2.12x
2 0 other (escape) 53 1.08x 1.43x 1.94x
2 last fp16/bf16 (sentinel) 39 1.27x 1.43x 3.13x
2 last other (escape) 53 1.25x 1.44x 2.51x
4 0 fp16/bf16 (sentinel) 38 1.33x 1.54x 2.05x
4 0 other (escape) 47 1.22x 1.47x 1.88x
4 last fp16/bf16 (sentinel) 39 1.25x 1.55x 3.63x
4 last other (escape) 47 1.22x 1.50x 2.69x

An input one element off 16B alignment on the odd ranks is copied into the pool first. It still runs 1.02–1.10x faster than before.

The cap is shared with the Lamport AR + RMSNorm and is not raised here. We measured the all-gather with a raised cap:

  • TP4 8–16 MiB: bf16 gains 1.18–1.60x. int32 along dim 0 gains only 1.02–1.09x, and falls to 0.92x at 16 MiB.
  • TP2 above 16 MiB: along dim 0 it is slower than the barrier kernel from about 20 MiB.

Raising the cap would also cost another 120 MiB per rank. It would also need an all-gather-only cap, because the AR + RMSNorm is 0.95–1.2x at TP4 14–16 MiB.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X — not affected: gfx1250 only
  • Tested on MI300X — not affected: gfx1250 only

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

This is an internal routing change with no new knob. The behavior of the existing AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE is documented next to _LAMPORT_AR_RMS_MAX_BYTES. The fp16/bf16 codec note is in the docstring of lamport_all_gather.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Some notes on behavior:

  • On gfx1250 TP2/TP4 the Lamport inbox grows from 96 to 120 MiB per rank, for the escape flags.
  • On the Lamport path, a 0xffff half-word of an fp16/bf16 input comes out as 0x7fff. Both are NaN. Integer or packed data should be gathered in its own dtype, not viewed as fp16/bf16. The fp8 payloads that ATOM pairs into fp16 are value-safe, because a 0xffff there is two fp8 NaNs.
  • AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE=0 now also turns off the Lamport all-gather.

PR Self-Review

Reviewed revision

e442cfc

Behavior and intent

On gfx1250 TP2/TP4, a custom all-gather along dim 0 or the last dim, up to the Lamport cap, now goes through a single Lamport kernel instead of the LL or barrier all-gather. The output is bit for bit the gathered inputs, with one exception: a 0xffff half-word of an fp16/bf16 input becomes 0x7fff. Larger inputs, other dims, TP6/TP8, multi-node groups, other archs and the RCCL path behave as before.

The Lamport AR + add no longer decides from operand addresses. A group whose ranks hold differently aligned operands now runs instead of hanging.

Validation and unverified scope

All runs are on 4x gfx1250, TP2 and TP4.

  • python op_tests/multigpu_tests/test_ag_lamport.py: 202 cases plus a mixed sequence of 64 calls per TP. Every gather is bit for bit, through both production entries, eager and in graph replays with fresh inputs.
  • python op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_allgather.py: 382 cases.
    • Every case ran the kernel that the routing rules give, on every rank and for both entries. This was checked with torch.profiler.
    • Every case is bit for bit. The numbers above come from this run.
    • The Lamport kernel's times match the pre-integration sweep: new/old median 0.996, with 95% of cases within 0.97–1.02.
  • python op_tests/multigpu_tests/test_allgather.py -t 2 and -t 4: all 40 cases have err 0. This includes the cases where the odd ranks' input sits one element into its storage. Those cases hang if the gate looks at addresses.
  • python op_tests/multigpu_tests/test_ar_add_lamport.py and python op_tests/multigpu_tests/test_fused_ar_rms_lamport.py: bit for bit. Their mixed sequences (52 and 51 calls per TP) now include unaligned operands on the odd ranks.
  • black --check and ruff check (ruff 0.16.0, as pinned in CI) are clean on the changed Python files.
  • The tests ran with flydsl hidden from Python. The machine's flydsl 0.3.3 is older than main requires, and these ops do not use it.
  • Unverified:
    • End-to-end model runs.
    • TP6/TP8. The Lamport ops are off by default there, and gfx1250 machines go up to TP4.
    • Multi-node groups. The Lamport inbox exists only on the node-local IPC transport.

PR-specific question

Changed op tests

  • op_tests/multigpu_tests/test_ag_lamport.py (new): correctness of the Lamport all-gather on the production path.
    • Covers both entries, eager and graph, every codec, dim 0 and the last dim, and the cap together with one row past it.
    • Also covers odd-rank-unaligned inputs, inputs aliasing the output, and interleaving with the Lamport AR + add and AR + RMSNorm on the shared inbox.
    • test_allgather.py gathers random bf16 against a tolerance. It never hits sentinel collisions, the escape codec or the shared inbox.
  • op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_allgather.py (rewritten, not run by CI): timing and dispatch check for the gfx1250 all-gather routes.
    • Compares the production route, the Lamport kernel, the LL/barrier route (copy-in and registered) and RCCL.
    • Checks which kernel each case actually launched.
    • It replaces a TP2 bf16-only benchmark of the naive kernel.
  • op_tests/multigpu_tests/test_ar_add_lamport.py and op_tests/multigpu_tests/test_fused_ar_rms_lamport.py: add operands one element off alignment on the odd ranks only. This is the case where the AR + add gate used to hang.

🤖 Generated with Claude Code

Route custom_all_gather on gfx1250 (TP2 up to 16 MiB a rank, TP4 up to
8 MiB) to a Lamport one-shot all-gather on the inbox of the Lamport
AR + RMSNorm. Drop the address check from the Lamport AR + add gate,
which could hang a group whose ranks hold differently aligned operands;
an unaligned operand of a Lamport op is now copied rank-locally.

Signed-off-by: TennyWang1223 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@TennyWang1223
TennyWang1223 requested a review from a team November 12, 2026 07:23
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 7861 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@github-actions github-actions Bot added the HIP label Nov 12, 2026
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision e442cfc2ec1d · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — PR-specific question has no substantive answer

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

@zufayu

zufayu commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 3 review(s); expect to start in about 1.6 h. The box reviews one PR at a time.

@zufayu
zufayu requested a review from junhaha666 November 12, 2026 07:41

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ROCm/aiter PR #7861 — [HIP] fea: impl gfx1250 lamport allgather

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0) and this box is 8x gfx942 while the change is gfx1250-only, so the target op_tests/multigpu_tests/test_ag_lamport.py (which returns early on non-gfx1250) could not be run here; environment gap, not a PR defect
Perf (advisory): NOT RUN — the validation target exposes no benchmark entry point and no gfx1250 GPU exists on this box, so the PR's own harness (op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_allgather.py, which times prod against the old route back to back) was not re-run by this review; the 1.08–3.63x tables are the author's runs
Size: 1526 lines / 10 files — over the review bar
Design (advisory): SPLIT — (1) the AR+add/AR+RMS unaligned-operand hang fix (_lamport_aligned, the should_lamport_ar_add address-gate removal, its two test files), (2) the Lamport all-gather itself (lamport_ag_gfx1250 + the two codecs + the escape inbox, the C++/pybind/ops stub, should_lamport_ag routing, test_ag_lamport.py), (3) the gfx1250_poc benchmark rewrite; (1) is a standalone hang fix and ghstack makes the stack cheap
Human: recommend XiaobingZhang review whether the gfx1250 Lamport all-gather of PR #7861 should share the AR+RMSNorm inbox, round counters and AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE cap with the AR+add and AR+RMSNorm ops, and whether the 0xffff → 0x7fff rewrite for fp16/bf16 gathers is acceptable to every consumer of custom_all_gather

⚠️ [verified] Every test this PR ships is a hand-run gfx1250 script that returns early on any other arch (op_tests/multigpu_tests/test_ag_lamport.py main()'s get_gfx_runtime() not in SUPPORTED_GFX gate), no CI lane runs gfx1250 HIP tests (default CI is MI35X, the multi-GPU runner is gfx942), and this review's box is 8x gfx942 — so neither the 202+382+40-case correctness runs nor the 1.08–3.63x tables were verified by anything but the author, and a later regression in should_lamport_ag or lamport_ag_gfx1250 would land with no automated check. Reviewer should ask for the test logs and benchmark output to be attached to the PR (or a gfx1250 CI lane) before this production routing lands.

📝 [verified] On the new path a 0xffff half-word of an fp16/bf16 input comes out 0x7fff (lamportCanonicalize in csrc/include/custom_all_reduce_gfx1250.cuh) — NaN→NaN for real float data, but a consumer gathering bit-packed data already viewed as fp16/bf16 gets silently rewritten bits; the PR analyzes ATOM's fp8-paired-into-fp16 case as value-safe and routes int16 through the bit-for-bit codec. Reviewer should ask whether every other gfx1250 consumer of tensor_model_parallel_all_gather(use_custom=True) gathers real float data rather than packed bits.

@zufayu
zufayu merged commit 88ebffa into main Nov 16, 2026
@zufayu
zufayu deleted the gfx1250_lamport_ag branch November 16, 2026 05:41
lirui927 pushed a commit that referenced this pull request Nov 16, 2026
Route custom_all_gather on gfx1250 (TP2 up to 16 MiB a rank, TP4 up to
8 MiB) to a Lamport one-shot all-gather on the inbox of the Lamport
AR + RMSNorm. Drop the address check from the Lamport AR + add gate,
which could hang a group whose ranks hold differently aligned operands;
an unaligned operand of a Lamport op is now copied rank-locally.

Signed-off-by: TennyWang1223 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 88ebffa)
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.

3 participants