Skip to content

[HIP] fea: impl gfx1250 lamport allreduce - #7927

Merged
TennyWang1223 merged 1 commit into
mainfrom
gfx1250_lamport_ar
Nov 17, 2026
Merged

TennyWang1223 merged 1 commit into
mainfrom
gfx1250_lamport_ar

Conversation

@TennyWang1223

@TennyWang1223 TennyWang1223 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Route the gfx1250 plain all-reduce through Lamport kernels. On TP2/TP4, fp16/bf16 inputs up to world_size x the Lamport cap (32 MiB at both) now run one of two kernels:

  • a Lamport one-shot, up to 1.25 MiB at TP4 and 9 MiB at TP2;
  • a new Lamport two-shot above that: a pushed reduce-scatter, then a pushed all-gather.

Both entries (tensor_model_parallel_all_reduce and CudaCommunicator.all_reduce) reach it through CustomAllreduce.custom_all_reduce. The plain all-reduce cutoff from #7432 (4 MiB at TP2/TP4, RCCL above) no longer applies to the inputs the Lamport kernels take: they are faster than RCCL up to 32 MiB. The result has the same bits as the custom all-reduce: a rank-order fp32 sum, rounded once. The one exception is the NaN payload: a 0xffff half-word is the Lamport "not arrived" sentinel, so it is sent as 0x7fff (still a NaN), and the two-shot also does this to the sum it hands to its peers. A NaN stays a NaN on every path, and every rank writes the same bits. fp32, larger inputs, TP6/TP8 and other archs keep their current route.

Motivation

On main, the gfx1250 plain all-reduce at TP2/TP4 runs the LL one-shot ar_ll_gfx1250, at TP4 the LL two-shot ar_2s_ll_gfx1250 from 1 MiB (#7432), and RCCL above 4 MiB (_GFX1250_PLAIN_AR_MAX_SIZE). The Lamport protocol from #7499 needs no barrier, no registered input and no copy-in. #7499 and #7861 already use it for the AR + RMSNorm, AR + add and all-gather, and it now covers the plain all-reduce too. On 4x gfx1250 it is faster than the LL kernels and RCCL at every size from 1 KiB to 32 MiB (tables below).

A one-shot alone stops at the cap (8 MiB at TP4), because every rank pushes the whole message into each peer's slot. The two-shot pushes only 1/world_size of the message per peer in each of its two steps. So it fits world_size x the cap in the same shared inbox, and it is also faster than the one-shot from about 1.3 MiB at TP4.

Changes

  • Kernels (custom_all_reduce_gfx1250.cuh):
    • lamport_ar_1shot_gfx1250: the Lamport AR + add kernel with a bool ADD template parameter. ADD=false is the plain all-reduce. The AR + add (ADD=true) is unchanged.
    • lamport_ar_2shot_gfx1250 (new): thread t owns pack t of each rank's chunk.
      • Reduce-scatter: it pushes pack t of chunk g to rank g through the shared inbox, taking one round of the per-wave round counters as every Lamport op does. So it interleaves freely with the other Lamport ops.
      • Sum and all-gather: it sums its own chunk in fp32 in rank order, then pushes the sum into a private all-gather inbox on every peer.
      • Re-arm: the private inbox has one buffer, re-armed as soon as it is read. A peer can only write a pack again after it holds this rank's reduce-scatter data of a later call, which this rank sends after the kernel boundary.
  • Inbox: the private all-gather inbox (world_size x cap, armed with 0xff) is appended after the escape inbox of [HIP] fea: impl gfx1250 lamport allgather #7861. The shared data inbox, the escape inbox, their offsets and the cap are unchanged. The other Lamport ops keep their size ranges.
  • Ops: allreduce_lamport_gfx1250(fa, inp, out, two_shot). It checks the size against the cap for the one-shot, and against world_size x the cap for the two-shot.
  • Python (custom_all_reduce.py):
    • custom_all_reduce first asks select_lamport_ar. That requires fp16/bf16, a contiguous input, and at most world_size x the Lamport cap. It picks the one-shot up to _LAMPORT_AR_1SHOT_MAX_BYTES (TP2 9 MiB, TP4 1.25 MiB, the measured crossovers), and the two-shot above that.
    • should_custom_plain_ar (the gate of CudaCommunicator.all_reduce) also passes an input that select_lamport_ar takes, above the plain all-reduce cutoff. Everything else keeps the cutoff, so fp32 and inputs above 32 MiB still go to RCCL above 4 MiB.
    • Both run after should_custom_ar, so AITER_CUSTOM_AR_MAX_SIZE / AITER_CUSTOM_AR_MIN_SIZE still bound them.
    • The decision uses shapes, dtypes and the cap only, so every rank picks the same kernel. It runs the same in eager, warmup and capture. An unaligned input is copied rank-locally (_lamport_aligned), as for the other Lamport ops.
    • should_lamport_ar(inp, two_shot) and lamport_all_reduce(inp, two_shot): the gate and the direct entry.
  • Tests:
    • op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py (new): performance, correctness and a routing check.
    • op_tests/multigpu_tests/test_custom_allreduce.py: the gfx1250 LL mixed-size regression now sets the Lamport cap to 0, so that its bf16 sizes keep exercising the LL kernel.
    • op_tests/multigpu_tests/test_custom_allreduce_size_env.py: a CPU test of the plain all-reduce gate with the Lamport cap.

Performance (if applicable)

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

  • Before: main, i.e. the LL one-shot / LL two-shot up to 4 MiB and RCCL above.
  • After: tensor_model_parallel_all_reduce with this PR.

TL;DR: Over the cases this PR routes (sizes 1 KiB–32 MiB plus [M, 7168] with M 1–2048), TP2 is 1.43–6.73x faster than main (median 1.78x) and TP4 1.02–3.30x (median 1.55x). Against the fastest of the LL one-shot, the LL two-shot, the barrier kernel and RCCL (default and with #7432's RCCL_DDA_LL_* settings) at each size, TP2 is 1.30–2.37x faster (median 1.75x) and TP4 1.02–3.30x (median 1.48x). No case is slower. The smallest gains are at TP4 5–8 MiB (1.02–1.08x, see the note under the tables).

Rows of hidden 7168, bf16 (the shapes of #7432)

Hardware Workload/configuration Before (us) After (us) Change
gfx1250 TP2, M=1 (14 KiB), LL → one-shot 7.6 5.0 1.52x
gfx1250 TP2, M=80 (1.09 MiB), LL → one-shot 11.9 6.8 1.75x
gfx1250 TP2, M=256 (3.5 MiB), LL → one-shot 17.0 9.2 1.85x
gfx1250 TP2, M=585 (8 MiB), RCCL → one-shot 25.1 16.0 1.57x
gfx1250 TP2, M=1024 (14 MiB), RCCL → two-shot 144 24.6 5.85x
gfx1250 TP4, M=1 (14 KiB), LL → one-shot 7.9 5.2 1.52x
gfx1250 TP4, M=80 (1.09 MiB), LL two-shot → one-shot 15.2 9.8 1.55x
gfx1250 TP4, M=256 (3.5 MiB), LL two-shot → two-shot 22.2 12.5 1.78x
gfx1250 TP4, M=320 (4.38 MiB), RCCL → two-shot 22.9 21.9 1.05x
gfx1250 TP4, M=585 (8 MiB), RCCL → two-shot 27.4 25.4 1.08x
gfx1250 TP4, M=1024 (14 MiB), RCCL → two-shot 42.5 35.0 1.21x
gfx1250 TP4, M=2048 (28 MiB), RCCL → two-shot 158 56.9 2.78x

By size, bf16, against each kernel

us per all-reduce. LL is what the custom all-reduce runs without Lamport (ar_ll_gfx1250, at TP4 ar_2s_ll_gfx1250 from 1 MiB; the barrier kernel where noted). "RCCL tuned" sets RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728, as in #7432. Bold is main's route.

TP Size LL RCCL RCCL tuned This PR vs main
2 1 KiB 6.95 5.69 5.68 4.36 (one-shot) 1.59x
2 64 KiB 7.85 7.33 7.25 5.14 (one-shot) 1.53x
2 1 MiB 9.30 8.55 8.52 5.97 (one-shot) 1.56x
2 4 MiB 19.2 17.0 17.1 9.68 (one-shot) 1.98x
2 8 MiB 36.8 (barrier) 25.3 25.7 16.1 (one-shot) 1.57x
2 16 MiB 58.3 (barrier) 146 141 25.1 (two-shot) 5.82x
2 32 MiB 106 (barrier) 187 179 48.2 (two-shot) 3.88x
4 1 KiB 7.03 5.34 5.45 4.65 (one-shot) 1.51x
4 64 KiB 8.30 8.14 8.18 5.58 (one-shot) 1.49x
4 1 MiB 15.1 (two-shot) 12.2 12.0 8.16 (one-shot) 1.85x
4 2 MiB 18.1 (two-shot) 20.4 17.8 11.2 (two-shot) 1.62x
4 4 MiB 24.4 (two-shot) 22.5 22.4 13.3 (two-shot) 1.83x
4 5 MiB 26.0 (two-shot) 23.7 23.7 23.2 (two-shot) 1.02x
4 8 MiB 33.9 (two-shot) 28.0 28.2 26.0 (two-shot) 1.08x
4 16 MiB 151 (barrier) 46.1 46.0 37.2 (two-shot) 1.24x
4 32 MiB 273 (barrier) 161 158 60.6 (two-shot) 2.66x
4 33 MiB RCCL RCCL, unchanged

At TP4 the Lamport two-shot slows down between 3.5 and 4.4 MiB (12.5 → 21.9 us) and is only 2–8% ahead of RCCL at 5–8 MiB. Its register use (49 VGPRs, no LDS) does not limit occupancy; the cause is not known yet and is left to a follow-up. In 4.4–6 MiB the one-shot is 1–6% faster than the two-shot; the two-shot is kept there so that the split stays a single size, and it is still ahead of RCCL and the LL two-shot.

The one-shot / two-shot crossover

Hardware Workload/configuration One-shot (us) Two-shot (us)
gfx1250 TP4, 1 MiB 8.13 10.3
gfx1250 TP4, 1.25 MiB 10.5 10.6
gfx1250 TP4, 1.5 MiB 11.2 10.7
gfx1250 TP4, 2 MiB 12.5 11.0
gfx1250 TP2, 8 MiB 16.1 18.2
gfx1250 TP2, 10 MiB 21.9 21.0

bf16 and fp16 cross at the same sizes. Above the cap only the two-shot fits, so it runs there.

Why the private all-gather inbox is world_size x the cap

With a private inbox of only 1x the cap, the two-shot could reach only the cap. The private inbox costs 32 MiB per rank. What the extra range buys at TP4 (bf16, us):

Size RCCL RCCL tuned Two-shot
10 MiB 38.6 38.6 28.2
16 MiB 46.1 46.0 37.2
20 MiB 146 147 44.2
32 MiB 161 158 60.6

RCCL 2.30 slows down sharply between 16 and 20 MiB at TP4, and between 8 and 10 MiB at TP2, with or without the tuned settings.

Growing the cap itself instead would grow the shared inbox (3.75 x world_size x the cap per rank: 120 MiB at TP4, 240 MiB with the cap doubled), and with it the range of every Lamport op.

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 one-shot / two-shot split and the inbox layout are documented next to _LAMPORT_AR_1SHOT_MAX_BYTES and _LAMPORT_AR_RMS_MAX_BYTES, and in the kernel comments.

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 120 to 152 MiB per rank, for the two-shot's private all-gather inbox.
  • AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE now also bounds the Lamport all-reduce: the one-shot up to it, the two-shot up to world_size x it. Setting it to 0 turns the Lamport all-reduce off too, and the plain all-reduce cutoff then applies to every input again.
  • A captured fp16/bf16 all-reduce in the Lamport range no longer registers its input as a graph buffer, because the Lamport kernels read no peer input.

PR Self-Review

Reviewed revision

f11d1be

Behavior and intent

On gfx1250 TP2/TP4, a plain fp16/bf16 all-reduce of a contiguous input up to 32 MiB now runs a single Lamport kernel, the one-shot or the two-shot, instead of the LL kernels (up to 4 MiB) or RCCL (above). The output bits are unchanged against the custom all-reduce: both sum in fp32 in rank order and round once. The only exception is the NaN payload, since a 0xffff half-word is canonicalized to 0x7fff (still a NaN) so it never reads as the Lamport sentinel. fp32, non-contiguous inputs, inputs above 32 MiB, TP6/TP8, multi-node groups, other archs and the RCCL path behave as before. The other Lamport ops keep their kernels and size ranges.

Validation and unverified scope

All runs are on 4x gfx1250, TP2 and TP4, on this branch rebased onto main (after #7432 and #7861).

  • python op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py -t 4 2 -d bf16 fp16 fp32 --size 1k 64k 1m 1280k 1408k 2m 4m 5m 8m 9m 9728k 16m 32m 33m 64m 65m, and the same file with its default [M, 7168] sweep:
    • All 118 cases ran the kernel that the routing rules give, on every rank, checked with torch.profiler: fp16/bf16 up to 32 MiB on the Lamport kernels; fp32 on the LL one-shot / LL two-shot up to 4 MiB and RCCL above; everything above 32 MiB on RCCL.
    • Every Lamport result is bit for bit against the rank-order fp32 sum.
    • The mixed sequence ran 99 calls per TP, all bit for bit. It interleaves both Lamport all-reduces with the Lamport AR + add, AR + RMSNorm and all-gather on the one inbox. It covers chunks that are short or empty, two-shots from just above the cap up to world_size x the cap, a NaN input (NaN compared as NaN, not by payload), and a graph replayed with fresh inputs.
  • python op_tests/multigpu_tests/test_custom_allreduce.py --regression, at -t 4 with --transport auto and --transport symm, and at -t 2: all pass (tail, LL128, gfx1250 LL mixed sizes, LL two-shot mixed sizes, LL in place, plain all-reduce cutoff).
  • python op_tests/multigpu_tests/test_custom_allreduce.py --op all_reduce, run with -t 4 -m graph, -t 4 -m eager, -t 2 -m graph and -t 4 -d fp16: all pass.
    • At TP4 bf16 its err column is up to 4.9e-4, from its reference, which accumulates in bf16; the values are the same as before the rebase. TP2 and fp16 show 0.
    • Without --op all_reduce the file also runs all_gather_lastdim_add ([HIP] Add all_gather_lastdim_add to the custom all-reduce #6960), which is not wired on gfx1250 and raises there, on main as well.
  • python op_tests/multigpu_tests/test_ar_add_lamport.py, test_fused_ar_rms_lamport.py, test_ag_lamport.py and gfx1250_poc/test_gfx1250_allgather.py: all bit for bit, and the all-gather routes are unchanged.
  • python op_tests/multigpu_tests/test_custom_ar_fused_interleave.py --tp 4 and test_custom_allreduce_rank_order.py: pass.
  • pytest op_tests/multigpu_tests/test_custom_allreduce_size_env.py: 16 passed, including the new test_gfx1250_plain_ar_gate_lamport, which fails on the gate without this change.
  • black --check and ruff check are clean on the changed Python files.
  • The tests ran with flydsl hidden from Python. The machine's flydsl 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.
  • Known and out of scope: the TP4 two-shot slowdown between 3.5 and 4.4 MiB (see Performance).

PR-specific question

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

Boundaries. A plain all-reduce takes a Lamport kernel only when CustomAllreduce.select_lamport_ar picks one, that is when should_lamport_ar(inp, two_shot=True) holds. All of the following must be true:

  • Architecture and transport: gfx1250 on the node-local IPC transport.
    • _lamport_max_bytes is non-zero only after _init_lamport_ar_rms has set up the Lamport inbox.
    • Only _init_ipc calls it, and only on gfx1250.
    • By default it sets a cap only for TP2 (16 MiB) and TP4 (8 MiB). TP6/TP8 get one only when AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE sets a size.
    • gfx9, the symm_mem and VMM transports, and multi-node groups never get an inbox. There select_lamport_ar returns None, and should_custom_plain_ar is the [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages #7432 cutoff unchanged.
  • Dtype: fp16 or bf16. The inbox sentinel 0xffff is defined for 2-byte types only. fp32 keeps the LL kernels up to the plain cutoff and RCCL above it.
  • Shape:
    • The input is contiguous and a whole number of 16B packs.
    • 0 < bytes ≤ world_size x the cap (32 MiB at TP2/TP4).
    • It is inside the AITER_CUSTOM_AR_MAX_SIZE / AITER_CUSTOM_AR_MIN_SIZE window, because should_custom_ar runs first.
    • The one-shot takes up to _LAMPORT_AR_1SHOT_MAX_BYTES (TP4 1.25 MiB, TP2 9 MiB), the two-shot the rest.
  • Entry: custom_all_reduce, which both tensor_model_parallel_all_reduce and CudaCommunicator.all_reduce reach. should_custom_plain_ar lets these inputs past the 4 MiB plain cutoff; every other input keeps it.

Invariants.

  • Every rank takes the same kernel. should_lamport_ar and select_lamport_ar read the dtype, contiguity, byte count and cap only, never the address, and the cap and the one-shot split are the same on every rank. This matters because the kernels wait for every peer, so a split group would hang. An unaligned input is copied rank-locally (_lamport_aligned) instead of being rerouted.
  • Anything that reaches the kernel fits the inbox.
    • allreduce_lamport rejects a non-contiguous input, an output that does not match it, any dtype but fp16/bf16, and a communicator without an inbox.
    • ar_packs rejects an input that is not whole 16B packs, and one larger than the slot (one-shot) or world_size x the slot (two-shot), the sizes the shared inbox and the private all-gather inbox are built for.
    • Both kernels static_assert a 2-byte dtype.
  • Group size: the kernels take at most 8 ranks (DISPATCH_NGPUS_1250), and the inbox exists only within one node.

Changed op tests

  • op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py (new): the production all-reduce route on gfx1250.
    • It times the route against both Lamport kernels, the custom all-reduce without Lamport (and which LL kernel that runs) and RCCL, and checks every result bit for bit.
    • It checks that every rank runs the kernel the routing rules give, including the plain all-reduce cutoff and the LL two-shot.
    • It runs a mixed sequence of every Lamport op on the shared inbox, eager and in graph replays.
    • No existing test covers the Lamport all-reduce, its routing, or its interleaving with the other Lamport ops.
  • op_tests/multigpu_tests/test_custom_allreduce.py: the gfx1250 LL mixed-size regression now sets AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE=0. Without it, its bf16 sizes would take the Lamport one-shot, and the test would no longer cover the LL kernel it guards. The LL two-shot and in-place regressions from [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages #7432 run fp32 or call all_reduce directly, so the Lamport kernels do not take them.
  • op_tests/multigpu_tests/test_custom_allreduce_size_env.py: the stub communicator gets the Lamport cap (0, the inbox off, unless a test sets it), which the plain all-reduce gate now reads. test_gfx1250_plain_ar_gate_lamport (new) checks that fp16/bf16 inputs up to world_size x the cap pass the gate above the plain cutoff, and that fp32, strided inputs, inputs above that, a cap of 0 and AITER_CUSTOM_AR_MAX_SIZE still keep it. It runs on CPU, so CI covers the gate.

🤖 Generated with Claude Code

Base automatically changed from gfx1250_lamport_ag to main November 16, 2026 05:41
@zufayu
zufayu requested a review from a team November 16, 2026 05:41
@aiter-bot

aiter-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision f11d1bee5a24 · 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

On gfx1250 TP2/TP4, a plain fp16/bf16 all-reduce of a contiguous input up to 32 MiB now runs a single Lamport kernel, the one-shot or the two-shot, instead of the LL kernels (up to 4 MiB) or RCCL (above). The output bits are unchanged against the custom all-reduce: both sum in fp32 in rank order and round once. The only exception is the NaN payload, since a 0xffff half-word is canonicalized to 0x7fff (still a NaN) so it never reads as the Lamport sentinel. fp32, non-contiguous inputs, inputs above 32 MiB, TP6/TP8, multi-node groups, other archs and the RCCL path behave as before. The other Lamport ops keep their kernels and size ranges.

Validation and unverified scope

All runs are on 4x gfx1250, TP2 and TP4, on this branch rebased onto main (after #7432 and #7861).

- `python op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py -t 4 2 -d bf16 fp16 fp32 --size 1k 64k 1m 1280k 1408k 2m 4m 5m 8m 9m 9728k 16m 32m 33m 64m 65m`, and the same file with its default `[M, 7168]` sweep:
  - All 118 cases ran the kernel that the routing rules give, on every rank, checked with `torch.profiler`: fp16/bf16 up to 32 MiB on the Lamport kernels; fp32 on the LL one-shot / LL two-shot up to 4 MiB and RCCL above; everything above 32 MiB on RCCL.
  - Every Lamport result is bit for bit against the rank-order fp32 sum.
  - The mixed sequence ran 99 calls per TP, all bit for bit. It interleaves both Lamport all-reduces with the Lamport AR + add, AR + RMSNorm and all-gather on the one inbox. It covers chunks that are short or empty, two-shots from just above the cap up to world_size x the cap, a NaN input (NaN compared as NaN, not by payload), and a graph replayed with fresh inputs.
- `python op_tests/multigpu_tests/test_custom_allreduce.py --regression`, at `-t 4` with `--transport auto` and `--transport symm`, and at `-t 2`: all pass (tail, LL128, gfx1250 LL mixed sizes, LL two-shot mixed sizes, LL in place, plain all-reduce cutoff).
- `python op_tests/multigpu_tests/test_custom_allreduce.py --op all_reduce`, run with `-t 4 -m graph`, `-t 4 -m eager`, `-t 2 -m graph` and `-t 4 -d fp16`: all pass.
  - At TP4 bf16 its `err` column is up to 4.9e-4, from its reference, which accumulates in bf16; the values are the same as before the rebase. TP2 and fp16 show 0.
  - Without `--op all_reduce` the file also runs `all_gather_lastdim_add` (#6960), which is not wired on gfx1250 and raises there, on main as well.
- `python op_tests/multigpu_tests/test_ar_add_lamport.py`, `test_fused_ar_rms_lamport.py`, `test_ag_lamport.py` and `gfx1250_poc/test_gfx1250_allgather.py`: all bit for bit, and the all-gather routes are unchanged.
- `python op_tests/multigpu_tests/test_custom_ar_fused_interleave.py --tp 4` and `test_custom_allreduce_rank_order.py`: pass.
- `pytest op_tests/multigpu_tests/test_custom_allreduce_size_env.py`: 16 passed, including the new `test_gfx1250_plain_ar_gate_lamport`, which fails on the gate without this change.
- `black --check` and `ruff check` are clean on the changed Python files.
- The tests ran with flydsl hidden from Python. The machine's flydsl 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.
- Known and out of scope: the TP4 two-shot slowdown between 3.5 and 4.4 MiB (see Performance).

PR-specific question

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

**Boundaries.** A plain all-reduce takes a Lamport kernel only when `CustomAllreduce.select_lamport_ar` picks one, that is when `should_lamport_ar(inp, two_shot=True)` holds. All of the following must be true:

- **Architecture and transport**: gfx1250 on the node-local IPC transport.
  - `_lamport_max_bytes` is non-zero only after `_init_lamport_ar_rms` has set up the Lamport inbox.
  - Only `_init_ipc` calls it, and only on gfx1250.
  - By default it sets a cap only for TP2 (16 MiB) and TP4 (8 MiB). TP6/TP8 get one only when `AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE` sets a size.
  - gfx9, the symm_mem and VMM transports, and multi-node groups never get an inbox. There `select_lamport_ar` returns None, and `should_custom_plain_ar` is the #7432 cutoff unchanged.
- **Dtype**: fp16 or bf16. The inbox sentinel 0xffff is defined for 2-byte types only. fp32 keeps the LL kernels up to the plain cutoff and RCCL above it.
- **Shape**:
  - The input is contiguous and a whole number of 16B packs.
  - 0 < bytes ≤ world_size x the cap (32 MiB at TP2/TP4).
  - It is inside the `AITER_CUSTOM_AR_MAX_SIZE` / `AITER_CUSTOM_AR_MIN_SIZE` window, because `should_custom_ar` runs first.
  - The one-shot takes up to `_LAMPORT_AR_1SHOT_MAX_BYTES` (TP4 1.25 MiB, TP2 9 MiB), the two-shot the rest.
- **Entry**: `custom_all_reduce`, which both `tensor_model_parallel_all_reduce` and `CudaCommunicator.all_reduce` reach. `should_custom_plain_ar` lets these inputs past the 4 MiB plain cutoff; every other input keeps it.

**Invariants.**

- **Every rank takes the same kernel.** `should_lamport_ar` and `select_lamport_ar` read the dtype, contiguity, byte count and cap only, never the address, and the cap and the one-shot split are the same on every rank. This matters because the kernels wait for every peer, so a split group would hang. An unaligned input is copied rank-locally (`_lamport_aligned`) instead of being rerouted.
- **Anything that reaches the kernel fits the inbox.**
  - `allreduce_lamport` rejects a non-contiguous input, an output that does not match it, any dtype but fp16/bf16, and a communicator without an inbox.
  - `ar_packs` rejects an input that is not whole 16B packs, and one larger than the slot (one-shot) or world_size x the slot (two-shot), the sizes the shared inbox and the private all-gather inbox are built for.
  - Both kernels `static_assert` a 2-byte dtype.
- **Group size**: the kernels take at most 8 ranks (`DISPATCH_NGPUS_1250`), and the inbox exists only within one node.

Changed op tests

- `op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py` (new): the production all-reduce route on gfx1250.
  - It times the route against both Lamport kernels, the custom all-reduce without Lamport (and which LL kernel that runs) and RCCL, and checks every result bit for bit.
  - It checks that every rank runs the kernel the routing rules give, including the plain all-reduce cutoff and the LL two-shot.
  - It runs a mixed sequence of every Lamport op on the shared inbox, eager and in graph replays.
  - No existing test covers the Lamport all-reduce, its routing, or its interleaving with the other Lamport ops.
- `op_tests/multigpu_tests/test_custom_allreduce.py`: the gfx1250 LL mixed-size regression now sets `AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE=0`. Without it, its bf16 sizes would take the Lamport one-shot, and the test would no longer cover the LL kernel it guards. The LL two-shot and in-place regressions from #7432 run fp32 or call `all_reduce` directly, so the Lamport kernels do not take them.
- `op_tests/multigpu_tests/test_custom_allreduce_size_env.py`: the stub communicator gets the Lamport cap (0, the inbox off, unless a test sets it), which the plain all-reduce gate now reads. `test_gfx1250_plain_ar_gate_lamport` (new) checks that fp16/bf16 inputs up to world_size x the cap pass the gate above the plain cutoff, and that fp32, strided inputs, inputs above that, a cap of 0 and `AITER_CUSTOM_AR_MAX_SIZE` still keep it. It runs on CPU, so CI covers the gate.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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
  • PASS — Aiter Test Gate: passed

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

Route the gfx1250 plain all-reduce through Lamport kernels on the shared
Lamport inbox: a one-shot up to 1.25 MiB at TP4 and 9 MiB at TP2, and a
new two-shot (pushed reduce-scatter + all-gather) above it, up to
world_size x the Lamport cap (32 MiB at TP2/TP4). fp16/bf16 only; same
bits as the custom all-reduce (rank-order fp32 sum).

The plain all-reduce cutoff of CudaCommunicator.all_reduce (#7432, 4 MiB
at TP2/TP4, RCCL above) no longer applies to the inputs the Lamport
kernels take: they stay ahead of RCCL up to world_size x the cap. Other
inputs keep the cutoff.

The two-shot's all-gather gets a private inbox of world_size x cap after
the escape inbox (per-rank Lamport buffer 120 -> 152 MiB at TP2/TP4); the
shared inbox, the cap and the other Lamport ops are unchanged.

Signed-off-by: TennyWang1223 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aiter-bot

Copy link
Copy Markdown

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

@zufayu

zufayu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Review ownership / next action:

  • Primary independent communication review: @junhaha666.
  • Please validate the Lamport protocol, memory ordering, re-arm/interleaving behavior, and inbox footprint, and provide a reproducible gfx1250 multi-GPU run because the relevant multi-GPU tests are skipped by the current CI.
  • After the protocol review and hardware evidence are available, I can co-review the per-rank memory cost and default routing policy.

I will wait for the communication primary review rather than approve ahead of it.

@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 #7927 — [HIP] fea: impl gfx1250 lamport allreduce

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0) and no gfx1250 GPU on this review box (8x gfx942); the target op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py exists but cannot run here (the CPU-only gate test test_custom_allreduce_size_env.py was run by hand against the head files: 16 passed; the gfx1250 kernel tests were not run)
Perf (advisory): NOT RUN — the perf stage has no entry point for the target (no --scenario bench / perftest harness) and this gfx942 box cannot run the gfx1250-only timing harness; the PR's tables (TP2 1.43–6.73x, TP4 1.02–3.30x vs main) are author-run on one 4x gfx1250 box
Size: 1047 lines / 9 files — over the review bar
Design (advisory): SPLIT — (1) the ADD template-param refactor of lamport_ar_1shot_gfx1250 with the AR+add path re-verified, (2) the lamport_ar_2shot_gfx1250 kernel with its private all-gather inbox plus the C++ entry, pybind and op plumbing, (3) the Python routing (select_lamport_ar, should_lamport_ar, the should_custom_plain_ar / custom_all_reduce gates) with its three test files
Human: recommend valarLip review whether PR #7927 rerouting every gfx1250 TP2/TP4 fp16/bf16 plain all-reduce up to 32 MiB off the LL kernels and RCCL onto the one-shot/two-shot lamport_ar_2shot_gfx1250 split (and growing the per-rank Lamport inbox 120 -> 152 MiB for it) is the right default for all TP model families

⚠️ [verified] Every perf number in this PR — the TP2 1.43–6.73x / TP4 1.02–3.30x vs-main tables and the 1.25 MiB / 9 MiB one-shot/two-shot crossover that sets _LAMPORT_AR_1SHOT_MAX_BYTES — is author-run on one 4x gfx1250 box and nobody re-ran it: the perf stage has no entry point for op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_lamport_allreduce.py and this review box is 8x gfx942, so a new default route for every gfx1250 TP2/TP4 fp16/bf16 all-reduce rests on unreplicated numbers. Reviewer should ask for one independent re-run of that harness (it already times base vs head back to back via its car candidate with the Lamport cap forced to 0) before merging the new default route.

📝 The PR carries an AI-attribution footer and two structural checks fired (the NaN-bits asymmetry above and the "same bits" claim it contradicts), so this is elevated-AI-code risk despite an unusually thorough self-review: the re-arm-safety argument for the private all-gather inbox is author-authored and only its consequences are tested. Reviewer should ask for thorough manual verification of the two-shot dispatch logic and the routing gates (select_lamport_ar, should_custom_plain_ar) before merge.

1 finding(s) posted inline, on the lines they are about:

  • csrc/include/custom_all_reduce_gfx1250.cuh:1690-1698 — lamport_ar_2shot_gfx1250 canonicalizes its output (0xffff → 0x7fff,…

@TennyWang1223
TennyWang1223 merged commit 2d9ab91 into main Nov 17, 2026
@TennyWang1223
TennyWang1223 deleted the gfx1250_lamport_ar branch November 17, 2026 09:13
lirui927 pushed a commit that referenced this pull request Nov 20, 2026
…lit norm where it wins

fused_allreduce_rmsnorm now runs the Lamport two-shot all-reduce
(#7927) followed by the split add + RMSNorm instead of a fused
kernel:
- above the Lamport one-shot AR + RMSNorm cap (8 MiB) up to the two-shot's
  4 x cap (32 MiB), where the fused kernel syncs through the barrier;
- for hidden 6144, also in (2, 4] MiB and (6, 8] MiB, where the fused
  one-shot steps up past 256 and past 512 rows.

TP4, hidden 6144 bf16, CUDA graph replay on 4 x MI455X, us per call
(slowest rank's median), before -> after:
  rows  192 (2.2 MiB)  15.7 -> 13.2     rows  683 (8 MiB)   38.8 -> 29.3
  rows  256 (3 MiB)    16.5 -> 13.9     rows 1365 (16 MiB)  59.1 -> 42.7
  rows  341 (4 MiB)    22.2 -> 15.1     rows 2048 (24 MiB)  77.3 -> 56.5
  rows  544 (6.4 MiB)  33.4 -> 27.5     rows 2730 (32 MiB)  96.1 -> 72.9
Unchanged outside these ranges (24 / 128 / 512 / 2731 rows).

residual_out keeps its bits; out differs in the last bf16 bit of about 1
value in 1e5 (the norm is the split kernel's). The decision uses shapes,
dtypes and the cap only. AITER_LAMPORT_SPLIT_AR_NORM=0 restores the old
routing. Only TP4 and (under the cap) hidden 6144 were measured, so only
those are routed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
#8012 @ c3b4113, head 2026-11-16T06:45:00Z)

Applied as the PR diff onto the rebased 1116 tree; PR state: draft. Conflicts resolved by keeping both sides (both PRs add different opt-in routes next to each other): communicator_cuda.py (#8015 Lamport one-shot check, then this PR's INT4 two-shot check), custom_all_reduce.py (constants, both symm_mem inits, both init methods), custom_all_reduce_gfx1250.h / pybind (main's #7927 allreduce_lamport and fused AR+RMS+quant declarations kept next to this PR's q4 declarations).

(cherry picked from commit 1bb791e)

Rebase onto main 12-03: #8015 (one-shot + symm_mem inbox) is not carried: main's #7937 final builds the Lamport inbox on every transport and routes plain all-reduce itself (should_lamport_ar(inp, two_shot)). So _LAMPORT_AR_MAX_SIZE / _init_lamport_symm / should_lamport_ar / lamport_all_reduce and the communicator's one-shot branch from #8015 are left out; the symm_mem init calls main's _init_lamport_ar_rms, then this PR's _init_lamport_q4_2s(symm=True). pybind keeps main's allreduce_lamport(split=False) next to the q4 bindings.
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.

4 participants