Repository navigation
[HIP] fix(custom_ar): sum ranks in a fixed order on every reduce path - #6954
Conversation
The two-stage all-reduce rotated its inputs so that the rank owning an output segment summed its own partial first and then the others in ring order. The owner of an element is fixed by the element's offset in the tensor, so the same row reduced at a different offset could take a different FP32 summation order and round to a neighbouring BF16 value. Read the inputs as rank 0..n-1 in cross_device_reduce_2stage and cross_device_reduce_2stage_naive, matching the one-stage kernel. In the LL and LL128 paths, where each receiver previously added its own value first, insert the local value at its rank position so every receiver sums in the same order. Partitioning, communication, temporary buffers, synchronisation and dtypes are unchanged. Every custom-AR path now produces the same bits for a given set of partials, regardless of row offset, receiving rank or the kernel chosen for the message size.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Signed-off-by: TennyWang1223 <[email protected]>
Signed-off-by: TennyWang1223 <[email protected]>
…#6954) * fix(custom_ar): sum ranks in a fixed order on every reduce path The two-stage all-reduce rotated its inputs so that the rank owning an output segment summed its own partial first and then the others in ring order. The owner of an element is fixed by the element's offset in the tensor, so the same row reduced at a different offset could take a different FP32 summation order and round to a neighbouring BF16 value. Read the inputs as rank 0..n-1 in cross_device_reduce_2stage and cross_device_reduce_2stage_naive, matching the one-stage kernel. In the LL and LL128 paths, where each receiver previously added its own value first, insert the local value at its rank position so every receiver sums in the same order. Partitioning, communication, temporary buffers, synchronisation and dtypes are unchanged. Every custom-AR path now produces the same bits for a given set of partials, regardless of row offset, receiving rank or the kernel chosen for the message size. * fix: fix other comm kernel Signed-off-by: TennyWang1223 <[email protected]> * fix: ut format Signed-off-by: TennyWang1223 <[email protected]> --------- Signed-off-by: TennyWang1223 <[email protected]> Co-authored-by: TennyWang1223 <[email protected]>
…e override Review: the verdict is computed on every TP rank on the premise that p, q and the coins are bitwise equal across ranks, which needs the all-reduce to sum ranks in one order. aiter's custom all-reduce did not from its LL/LL128 paths (2039d2b96c, 2026-09-13) until ROCm/aiter#6954, and main's exact-match path rests on the same premise, so a minimum aiter version in the docs would make it explicit. Separately, with the flag on, Kimi-K3's _sample_block takes the lossless block regardless of ATOM_DSPARK_FUSED_MARKOV_SAMPLE, so =0 no longer selects the fp32 reference path for greedy rows either; worth a line in its env entry. docs/model_ops_guide.md (RejectionSampler) now says that only the tokens are broadcast and each rank computes its own verdict. Differing logits can therefore desync next_token_locs, the KDA state commit and the KV release silently, for exact match as for the ratio verify. It names the minimum aiter as a build including ROCm/aiter#6954 and gives the affected range. The ATOM_SPEC_LOSSLESS_SAMPLING entry (envs.py and docs/environment_variables.md) carries the same requirement in short. The ATOM_DSPARK_FUSED_MARKOV_SAMPLE entry now says that once lossless sampling arms, Kimi-K3's draft takes the lossless sampled block for every row whatever this flag says, so comparing against the reference needs ATOM_SPEC_LOSSLESS_SAMPLING off too. Docs only. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…#6954) * fix(custom_ar): sum ranks in a fixed order on every reduce path The two-stage all-reduce rotated its inputs so that the rank owning an output segment summed its own partial first and then the others in ring order. The owner of an element is fixed by the element's offset in the tensor, so the same row reduced at a different offset could take a different FP32 summation order and round to a neighbouring BF16 value. Read the inputs as rank 0..n-1 in cross_device_reduce_2stage and cross_device_reduce_2stage_naive, matching the one-stage kernel. In the LL and LL128 paths, where each receiver previously added its own value first, insert the local value at its rank position so every receiver sums in the same order. Partitioning, communication, temporary buffers, synchronisation and dtypes are unchanged. Every custom-AR path now produces the same bits for a given set of partials, regardless of row offset, receiving rank or the kernel chosen for the message size. * fix: fix other comm kernel Signed-off-by: TennyWang1223 <[email protected]> * fix: ut format Signed-off-by: TennyWang1223 <[email protected]> --------- Signed-off-by: TennyWang1223 <[email protected]> Co-authored-by: TennyWang1223 <[email protected]>
Move the gfx950 1-/2-stage rule and the packs < world_size guard into select_ar_stage() and the LL/LL128 caps into select_ll_path(), so allreduce and allreduce_residual pick stages the same way (TP2 residual is no longer 1-stage only). Add ops.all_reduce_one_shot and make uses_1stage_ar() query the dispatch, LL included. ROCm#6954 made LL/LL128 slower near their caps; re-swept on the merged tree: TP8 plain LL aligned 40 -> 32 KB, TP8 fused LL aligned 64 -> 56 KB, TP4 fused unaligned LL 96 -> 112 KB with LL128 dropped.
ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ages (#7432) * [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages On gfx1250 the custom all-reduce had a flat one-shot LL kernel up to 4 MiB, which sends (n - 1) x the message per rank (x2 for LL lines), and above that a one-shot pull (ar_gfx1250_naive_unroll4) that is 4-8x slower than RCCL at TP8. Add ar_2s_ll_gfx1250, a reduce-scatter + all-gather over the same LL lines, scratch, banks and per-block epochs as ar_ll_gfx1250, so no buffer is added. Each rank sends 2 (n - 1) / n x the message (x2 for LL lines), for one more fabric round trip. It takes inputs from 1 MiB up to world_size x 2 MiB (one bank of the LL scratch) at 4+ ranks and reads them in place (no copy-in). The existing knobs keep their meaning: AITER_CUSTOM_AR_MAX_SIZE caps it and AITER_CUSTOM_AR_DISABLE_LL turns it off with the one-shot LL. Also launch both LL kernels with 512-thread blocks once 256-thread blocks would put more than one block on a CU (the CU count is read at run time): at TP8 the one-shot at 0.57 MB drops from 20.0 to 18.0 us, level with RCCL. MI455X, TP8 across two trays over UALink, bf16, CUDA graph, us per call: size RCCL* before after 0.57 MB 17.2 20.0 18.0 one-shot, 512-thread blocks 1.15 MB 29.7 28.8 23.3 two-shot 2.29 MB 39.2 47.9 25.6 3.67 MB 40.7 74.0 26.3 4.59 MB 42.2 157.8 34.5 8.39 MB 44.3 270.9 40.6 * RCCL 2.30.7 with RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728 Tests: test_custom_allreduce.py gains a gfx1250 LL two-shot mixed-size regression. It runs two-shot and one-shot sizes back to back and negates the inputs every other round, so a stale line cannot pass. The --regression suite passes at TP4 with --transport symm and auto. At TP8 across two trays, 200 calls per size, each with a fresh random input, match an fp32 all-reduce to bf16 rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): sum the gfx1250 LL two-shot in rank order ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] refactor(custom_ar): own scratch and a per-TP cap for the gfx1250 LL two-shot The two-shot reused the one-shot LL's state. It carved each LL bank into chunk-sized reduce-scatter and all-gather regions, shared the LL per-block epochs, and derived its size cap (world_size x 2 MiB) from kLLPackCapacity. A change to the LL scratch layout or capacity would therefore have changed the two-shot's correctness and routing without notice. - Own scratch: after the fused AR + RMSNorm shard in the meta buffer (ar2sScratchOffset). It is counted in meta_size(), so every transport zero-initializes it with the rest. It has two banks, each with a reduce-scatter and an all-gather region of ar2sMaxBytes / 8 lines. That is 8 x ar2sMaxBytes a rank: 64 MiB at TP4 and TP8, nothing at TP2 or TP6. - Own peer table and per-block epochs (d_2s_peers_, d_2s_block_flags_), built at construction like the LL tables, so nothing is allocated inside a graph capture. - A per-world-size cap from measurements (ar2sMaxBytes), which also sizes the scratch: - TP8, two MI455X trays: 8 MiB. The two-shot is ahead of RCCL at 8.39 MB (40.6 vs 44.3 us) and behind at 14.68 MB (59.1 vs 51.0 us). - TP4: 8 MiB, as before. RCCL within a tray is not measured yet. - TP6: off, as it is not measured. - ar_ll_gfx1250, ag_ll_gfx1250, kLLScratchCapBytes, kLLPackCapacity and the LL scratch layout are unchanged. Built for gfx1250, the one-shot and all-gather LL kernels keep identical resource usage. With AITER_CUSTOM_AR_MAX_SIZE unset (64 MiB), an all-reduce of 8-16 MiB at TP8 now takes the one-shot pull (ar_gfx1250_naive_unroll4), as on main, rather than the two-shot. Sending it to RCCL by default needs a per-TP gfx1250 AR cutoff in _resolve_custom_sizes, which is left for the review. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] test(custom_ar): vary the LL two-shot regression's inputs on bank reuse Rounds of the mixed-size regression alternated x and -x. A kernel reuses the same scratch bank every second call of that kernel. For a kernel called once a round (here the one-shot LL), the bank's previous contents therefore carried the sign now expected, and accepting a stale line would still have passed the exact comparison. Rounds now cycle through x, -x and 2x, which is exact both in fp32 and on bf16 integers. The previous use of any bank, one or two rounds back, never carries the expected bits. The test now runs only at TP4 and TP8, where the two-shot runs (ar2sMaxBytes); at TP6 it only ever exercised the one-shot and the pull. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 LL all-reduce lines carry 12 bytes; senders and pollers in separate waves Decode-size all-reduces at TP8 were slow in both LL kernels: - each 16-byte line carried 8 bytes and two flags, so a rank moved 2 x its payload on the wire; - a poll was issued after the same wave's remote stores, and on gfx1250 a load after a remote store waits for that store (about a fabric round trip) while a peer's line lands in about half of one; - the one-shot polled the peers one after another and re-read the peer table (scalar loads) between its stores. Both kernels now send 12-byte lines with one flag (a line is a single 16-byte store and load, so one flag guards it), read the peer bases once before any store, and poll every peer in one batch. The one-shot runs W senders and W pollers a block; the two-shot three wave groups (send the reduce-scatter; poll, reduce and send the all-gather; poll the all-gather). Both still sum in rank order in fp32 and round once, so results are bit-identical to before. The two-shot's per-source slots start on 4 KiB boundaries (a misaligned slot cost ~3 us a call). Blocks: the smallest W with one block a CU. The two-shot takes over from 768 KiB at TP8 (ar2sMinBytes; 1 MiB elsewhere). MI455X TP8 across two trays, bf16, 50 all-reduces in one CUDA graph, us an all-reduce (slowest rank), before -> after: [40, 3584] 0.29 MB 15.8 -> 11.4, [40, 7168] 0.57 MB 19.1 -> 13.4, [80, 7168] 1.15 MB 23.8 -> 18.1, [115, 3584] 0.82 MB 22.0 -> 16.9, [115, 7168] 1.65 MB 26.0 -> 18.1, [320, 7168] 4.59 MB 34.9 -> 26.5. Checked bit for bit against an fp32 rank-order sum at 28 shapes, with 600 mixed calls interleaving the all-gather, and over CUDA-graph replays. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): gfx1250 LL all-reduce keeps a flag per 8 bytes; one-shot safe in place Review of 6b28946 (#7432): - Lines carry 8 bytes again, [d0, flag, d1, flag], and a reader takes a line only once both flags carry the epoch, so a line has to land atomically per 8 bytes only. The 12-byte lines with one flag relied on a remote b128 store landing atomically as a whole, which no gfx1250 or UALink document guarantees. - The one-shot is safe with recvbuff == sendbuff again. Its sender also writes the line to its own scratch, first, and the poller takes the local value from that line. So no output is written before its input packet has been loaded and sent. - The two-shot runs send, reduce and gather in three wave groups while one block of 3 x 128 threads a CU covers a chunk, else in two, with gather in the send group, so a block covers more packets a CU. It takes over from the one-shot at 512 KiB at TP8 (1 MiB at TP4, as before). - Kept from 6b28946: sender and poller waves, batched polls, peer bases read once into registers. MI455X, bf16, CUDA graph, us an all-reduce (slowest rank), 5c522b3 -> this: TP8, two trays: 0.29 MB 14.6 -> 12.0, 0.57 MB 17.6 -> 13.5, 1.15 MB 22.6 -> 15.3, 1.65 MB 24.3 -> 15.6, 4.59 MB 34.2 -> 28.4, 8.39 MB 41.5 -> 39.2 TP4: 1.15 MB 14.6 -> 10.4, 2.29 MB 17.1 -> 14.2, 4.59 MB 27.5 -> 22.2 TP2: 1.65 MB 11.7 -> 9.5, 2.29 MB 13.8 -> 11.9 The regression test gets an in-place case (output aliasing the input) that covers the one-shot with 1, 2 and 4 packets a sender, and the two-shot. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 plain all-reduce defaults to RCCL past the measured crossover As agreed on #7432 (11-05). On gfx1250, with AITER_CUSTOM_AR_MAX_SIZE unset, plain all-reduce (CudaCommunicator.all_reduce) runs the custom kernels only up to about where RCCL becomes faster: 4 MiB at TP2 and TP4, 8 MiB at TP8. Larger inputs went to the two-shot (TP4, 4-8 MiB) or to the one-shot pull, which takes 405 us at 14.68 MB at TP8 against 55 us for RCCL. - New binding ll_ar_max_bytes(world_size): the largest input the LL kernels take, max(kLLArMaxBytes, ar2sMaxBytes). The default never exceeds it, so Python does not copy the C++ caps. - An explicit AITER_CUSTOM_AR_MAX_SIZE keeps its meaning. TP6 and gfx9 keep the AR cutoff. - should_custom_ar and the fused AR + RMSNorm paths are unchanged; their fallback to all_reduce picks up the default. - Tests: the default applies only with the env unset (test_custom_allreduce_size_env.py), and every rank resolves the same cutoff and takes the same path (test_custom_allreduce.py --regression). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ages (#7432) * [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages On gfx1250 the custom all-reduce had a flat one-shot LL kernel up to 4 MiB, which sends (n - 1) x the message per rank (x2 for LL lines), and above that a one-shot pull (ar_gfx1250_naive_unroll4) that is 4-8x slower than RCCL at TP8. Add ar_2s_ll_gfx1250, a reduce-scatter + all-gather over the same LL lines, scratch, banks and per-block epochs as ar_ll_gfx1250, so no buffer is added. Each rank sends 2 (n - 1) / n x the message (x2 for LL lines), for one more fabric round trip. It takes inputs from 1 MiB up to world_size x 2 MiB (one bank of the LL scratch) at 4+ ranks and reads them in place (no copy-in). The existing knobs keep their meaning: AITER_CUSTOM_AR_MAX_SIZE caps it and AITER_CUSTOM_AR_DISABLE_LL turns it off with the one-shot LL. Also launch both LL kernels with 512-thread blocks once 256-thread blocks would put more than one block on a CU (the CU count is read at run time): at TP8 the one-shot at 0.57 MB drops from 20.0 to 18.0 us, level with RCCL. MI455X, TP8 across two trays over UALink, bf16, CUDA graph, us per call: size RCCL* before after 0.57 MB 17.2 20.0 18.0 one-shot, 512-thread blocks 1.15 MB 29.7 28.8 23.3 two-shot 2.29 MB 39.2 47.9 25.6 3.67 MB 40.7 74.0 26.3 4.59 MB 42.2 157.8 34.5 8.39 MB 44.3 270.9 40.6 * RCCL 2.30.7 with RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728 Tests: test_custom_allreduce.py gains a gfx1250 LL two-shot mixed-size regression. It runs two-shot and one-shot sizes back to back and negates the inputs every other round, so a stale line cannot pass. The --regression suite passes at TP4 with --transport symm and auto. At TP8 across two trays, 200 calls per size, each with a fresh random input, match an fp32 all-reduce to bf16 rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): sum the gfx1250 LL two-shot in rank order ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] refactor(custom_ar): own scratch and a per-TP cap for the gfx1250 LL two-shot The two-shot reused the one-shot LL's state. It carved each LL bank into chunk-sized reduce-scatter and all-gather regions, shared the LL per-block epochs, and derived its size cap (world_size x 2 MiB) from kLLPackCapacity. A change to the LL scratch layout or capacity would therefore have changed the two-shot's correctness and routing without notice. - Own scratch: after the fused AR + RMSNorm shard in the meta buffer (ar2sScratchOffset). It is counted in meta_size(), so every transport zero-initializes it with the rest. It has two banks, each with a reduce-scatter and an all-gather region of ar2sMaxBytes / 8 lines. That is 8 x ar2sMaxBytes a rank: 64 MiB at TP4 and TP8, nothing at TP2 or TP6. - Own peer table and per-block epochs (d_2s_peers_, d_2s_block_flags_), built at construction like the LL tables, so nothing is allocated inside a graph capture. - A per-world-size cap from measurements (ar2sMaxBytes), which also sizes the scratch: - TP8, two MI455X trays: 8 MiB. The two-shot is ahead of RCCL at 8.39 MB (40.6 vs 44.3 us) and behind at 14.68 MB (59.1 vs 51.0 us). - TP4: 8 MiB, as before. RCCL within a tray is not measured yet. - TP6: off, as it is not measured. - ar_ll_gfx1250, ag_ll_gfx1250, kLLScratchCapBytes, kLLPackCapacity and the LL scratch layout are unchanged. Built for gfx1250, the one-shot and all-gather LL kernels keep identical resource usage. With AITER_CUSTOM_AR_MAX_SIZE unset (64 MiB), an all-reduce of 8-16 MiB at TP8 now takes the one-shot pull (ar_gfx1250_naive_unroll4), as on main, rather than the two-shot. Sending it to RCCL by default needs a per-TP gfx1250 AR cutoff in _resolve_custom_sizes, which is left for the review. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] test(custom_ar): vary the LL two-shot regression's inputs on bank reuse Rounds of the mixed-size regression alternated x and -x. A kernel reuses the same scratch bank every second call of that kernel. For a kernel called once a round (here the one-shot LL), the bank's previous contents therefore carried the sign now expected, and accepting a stale line would still have passed the exact comparison. Rounds now cycle through x, -x and 2x, which is exact both in fp32 and on bf16 integers. The previous use of any bank, one or two rounds back, never carries the expected bits. The test now runs only at TP4 and TP8, where the two-shot runs (ar2sMaxBytes); at TP6 it only ever exercised the one-shot and the pull. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 LL all-reduce lines carry 12 bytes; senders and pollers in separate waves Decode-size all-reduces at TP8 were slow in both LL kernels: - each 16-byte line carried 8 bytes and two flags, so a rank moved 2 x its payload on the wire; - a poll was issued after the same wave's remote stores, and on gfx1250 a load after a remote store waits for that store (about a fabric round trip) while a peer's line lands in about half of one; - the one-shot polled the peers one after another and re-read the peer table (scalar loads) between its stores. Both kernels now send 12-byte lines with one flag (a line is a single 16-byte store and load, so one flag guards it), read the peer bases once before any store, and poll every peer in one batch. The one-shot runs W senders and W pollers a block; the two-shot three wave groups (send the reduce-scatter; poll, reduce and send the all-gather; poll the all-gather). Both still sum in rank order in fp32 and round once, so results are bit-identical to before. The two-shot's per-source slots start on 4 KiB boundaries (a misaligned slot cost ~3 us a call). Blocks: the smallest W with one block a CU. The two-shot takes over from 768 KiB at TP8 (ar2sMinBytes; 1 MiB elsewhere). MI455X TP8 across two trays, bf16, 50 all-reduces in one CUDA graph, us an all-reduce (slowest rank), before -> after: [40, 3584] 0.29 MB 15.8 -> 11.4, [40, 7168] 0.57 MB 19.1 -> 13.4, [80, 7168] 1.15 MB 23.8 -> 18.1, [115, 3584] 0.82 MB 22.0 -> 16.9, [115, 7168] 1.65 MB 26.0 -> 18.1, [320, 7168] 4.59 MB 34.9 -> 26.5. Checked bit for bit against an fp32 rank-order sum at 28 shapes, with 600 mixed calls interleaving the all-gather, and over CUDA-graph replays. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): gfx1250 LL all-reduce keeps a flag per 8 bytes; one-shot safe in place Review of 6b28946 (#7432): - Lines carry 8 bytes again, [d0, flag, d1, flag], and a reader takes a line only once both flags carry the epoch, so a line has to land atomically per 8 bytes only. The 12-byte lines with one flag relied on a remote b128 store landing atomically as a whole, which no gfx1250 or UALink document guarantees. - The one-shot is safe with recvbuff == sendbuff again. Its sender also writes the line to its own scratch, first, and the poller takes the local value from that line. So no output is written before its input packet has been loaded and sent. - The two-shot runs send, reduce and gather in three wave groups while one block of 3 x 128 threads a CU covers a chunk, else in two, with gather in the send group, so a block covers more packets a CU. It takes over from the one-shot at 512 KiB at TP8 (1 MiB at TP4, as before). - Kept from 6b28946: sender and poller waves, batched polls, peer bases read once into registers. MI455X, bf16, CUDA graph, us an all-reduce (slowest rank), 5c522b3 -> this: TP8, two trays: 0.29 MB 14.6 -> 12.0, 0.57 MB 17.6 -> 13.5, 1.15 MB 22.6 -> 15.3, 1.65 MB 24.3 -> 15.6, 4.59 MB 34.2 -> 28.4, 8.39 MB 41.5 -> 39.2 TP4: 1.15 MB 14.6 -> 10.4, 2.29 MB 17.1 -> 14.2, 4.59 MB 27.5 -> 22.2 TP2: 1.65 MB 11.7 -> 9.5, 2.29 MB 13.8 -> 11.9 The regression test gets an in-place case (output aliasing the input) that covers the one-shot with 1, 2 and 4 packets a sender, and the two-shot. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 plain all-reduce defaults to RCCL past the measured crossover As agreed on #7432 (11-05). On gfx1250, with AITER_CUSTOM_AR_MAX_SIZE unset, plain all-reduce (CudaCommunicator.all_reduce) runs the custom kernels only up to about where RCCL becomes faster: 4 MiB at TP2 and TP4, 8 MiB at TP8. Larger inputs went to the two-shot (TP4, 4-8 MiB) or to the one-shot pull, which takes 405 us at 14.68 MB at TP8 against 55 us for RCCL. - New binding ll_ar_max_bytes(world_size): the largest input the LL kernels take, max(kLLArMaxBytes, ar2sMaxBytes). The default never exceeds it, so Python does not copy the C++ caps. - An explicit AITER_CUSTOM_AR_MAX_SIZE keeps its meaning. TP6 and gfx9 keep the AR cutoff. - should_custom_ar and the fused AR + RMSNorm paths are unchanged; their fallback to all_reduce picks up the default. - Tests: the default applies only with the env unset (test_custom_allreduce_size_env.py), and every rank resolves the same cutoff and takes the same path (test_custom_allreduce.py --regression). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ages (#7432) * [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages On gfx1250 the custom all-reduce had a flat one-shot LL kernel up to 4 MiB, which sends (n - 1) x the message per rank (x2 for LL lines), and above that a one-shot pull (ar_gfx1250_naive_unroll4) that is 4-8x slower than RCCL at TP8. Add ar_2s_ll_gfx1250, a reduce-scatter + all-gather over the same LL lines, scratch, banks and per-block epochs as ar_ll_gfx1250, so no buffer is added. Each rank sends 2 (n - 1) / n x the message (x2 for LL lines), for one more fabric round trip. It takes inputs from 1 MiB up to world_size x 2 MiB (one bank of the LL scratch) at 4+ ranks and reads them in place (no copy-in). The existing knobs keep their meaning: AITER_CUSTOM_AR_MAX_SIZE caps it and AITER_CUSTOM_AR_DISABLE_LL turns it off with the one-shot LL. Also launch both LL kernels with 512-thread blocks once 256-thread blocks would put more than one block on a CU (the CU count is read at run time): at TP8 the one-shot at 0.57 MB drops from 20.0 to 18.0 us, level with RCCL. MI455X, TP8 across two trays over UALink, bf16, CUDA graph, us per call: size RCCL* before after 0.57 MB 17.2 20.0 18.0 one-shot, 512-thread blocks 1.15 MB 29.7 28.8 23.3 two-shot 2.29 MB 39.2 47.9 25.6 3.67 MB 40.7 74.0 26.3 4.59 MB 42.2 157.8 34.5 8.39 MB 44.3 270.9 40.6 * RCCL 2.30.7 with RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728 Tests: test_custom_allreduce.py gains a gfx1250 LL two-shot mixed-size regression. It runs two-shot and one-shot sizes back to back and negates the inputs every other round, so a stale line cannot pass. The --regression suite passes at TP4 with --transport symm and auto. At TP8 across two trays, 200 calls per size, each with a fresh random input, match an fp32 all-reduce to bf16 rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): sum the gfx1250 LL two-shot in rank order ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] refactor(custom_ar): own scratch and a per-TP cap for the gfx1250 LL two-shot The two-shot reused the one-shot LL's state. It carved each LL bank into chunk-sized reduce-scatter and all-gather regions, shared the LL per-block epochs, and derived its size cap (world_size x 2 MiB) from kLLPackCapacity. A change to the LL scratch layout or capacity would therefore have changed the two-shot's correctness and routing without notice. - Own scratch: after the fused AR + RMSNorm shard in the meta buffer (ar2sScratchOffset). It is counted in meta_size(), so every transport zero-initializes it with the rest. It has two banks, each with a reduce-scatter and an all-gather region of ar2sMaxBytes / 8 lines. That is 8 x ar2sMaxBytes a rank: 64 MiB at TP4 and TP8, nothing at TP2 or TP6. - Own peer table and per-block epochs (d_2s_peers_, d_2s_block_flags_), built at construction like the LL tables, so nothing is allocated inside a graph capture. - A per-world-size cap from measurements (ar2sMaxBytes), which also sizes the scratch: - TP8, two MI455X trays: 8 MiB. The two-shot is ahead of RCCL at 8.39 MB (40.6 vs 44.3 us) and behind at 14.68 MB (59.1 vs 51.0 us). - TP4: 8 MiB, as before. RCCL within a tray is not measured yet. - TP6: off, as it is not measured. - ar_ll_gfx1250, ag_ll_gfx1250, kLLScratchCapBytes, kLLPackCapacity and the LL scratch layout are unchanged. Built for gfx1250, the one-shot and all-gather LL kernels keep identical resource usage. With AITER_CUSTOM_AR_MAX_SIZE unset (64 MiB), an all-reduce of 8-16 MiB at TP8 now takes the one-shot pull (ar_gfx1250_naive_unroll4), as on main, rather than the two-shot. Sending it to RCCL by default needs a per-TP gfx1250 AR cutoff in _resolve_custom_sizes, which is left for the review. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] test(custom_ar): vary the LL two-shot regression's inputs on bank reuse Rounds of the mixed-size regression alternated x and -x. A kernel reuses the same scratch bank every second call of that kernel. For a kernel called once a round (here the one-shot LL), the bank's previous contents therefore carried the sign now expected, and accepting a stale line would still have passed the exact comparison. Rounds now cycle through x, -x and 2x, which is exact both in fp32 and on bf16 integers. The previous use of any bank, one or two rounds back, never carries the expected bits. The test now runs only at TP4 and TP8, where the two-shot runs (ar2sMaxBytes); at TP6 it only ever exercised the one-shot and the pull. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 LL all-reduce lines carry 12 bytes; senders and pollers in separate waves Decode-size all-reduces at TP8 were slow in both LL kernels: - each 16-byte line carried 8 bytes and two flags, so a rank moved 2 x its payload on the wire; - a poll was issued after the same wave's remote stores, and on gfx1250 a load after a remote store waits for that store (about a fabric round trip) while a peer's line lands in about half of one; - the one-shot polled the peers one after another and re-read the peer table (scalar loads) between its stores. Both kernels now send 12-byte lines with one flag (a line is a single 16-byte store and load, so one flag guards it), read the peer bases once before any store, and poll every peer in one batch. The one-shot runs W senders and W pollers a block; the two-shot three wave groups (send the reduce-scatter; poll, reduce and send the all-gather; poll the all-gather). Both still sum in rank order in fp32 and round once, so results are bit-identical to before. The two-shot's per-source slots start on 4 KiB boundaries (a misaligned slot cost ~3 us a call). Blocks: the smallest W with one block a CU. The two-shot takes over from 768 KiB at TP8 (ar2sMinBytes; 1 MiB elsewhere). MI455X TP8 across two trays, bf16, 50 all-reduces in one CUDA graph, us an all-reduce (slowest rank), before -> after: [40, 3584] 0.29 MB 15.8 -> 11.4, [40, 7168] 0.57 MB 19.1 -> 13.4, [80, 7168] 1.15 MB 23.8 -> 18.1, [115, 3584] 0.82 MB 22.0 -> 16.9, [115, 7168] 1.65 MB 26.0 -> 18.1, [320, 7168] 4.59 MB 34.9 -> 26.5. Checked bit for bit against an fp32 rank-order sum at 28 shapes, with 600 mixed calls interleaving the all-gather, and over CUDA-graph replays. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): gfx1250 LL all-reduce keeps a flag per 8 bytes; one-shot safe in place Review of 6b28946 (#7432): - Lines carry 8 bytes again, [d0, flag, d1, flag], and a reader takes a line only once both flags carry the epoch, so a line has to land atomically per 8 bytes only. The 12-byte lines with one flag relied on a remote b128 store landing atomically as a whole, which no gfx1250 or UALink document guarantees. - The one-shot is safe with recvbuff == sendbuff again. Its sender also writes the line to its own scratch, first, and the poller takes the local value from that line. So no output is written before its input packet has been loaded and sent. - The two-shot runs send, reduce and gather in three wave groups while one block of 3 x 128 threads a CU covers a chunk, else in two, with gather in the send group, so a block covers more packets a CU. It takes over from the one-shot at 512 KiB at TP8 (1 MiB at TP4, as before). - Kept from 6b28946: sender and poller waves, batched polls, peer bases read once into registers. MI455X, bf16, CUDA graph, us an all-reduce (slowest rank), 5c522b3 -> this: TP8, two trays: 0.29 MB 14.6 -> 12.0, 0.57 MB 17.6 -> 13.5, 1.15 MB 22.6 -> 15.3, 1.65 MB 24.3 -> 15.6, 4.59 MB 34.2 -> 28.4, 8.39 MB 41.5 -> 39.2 TP4: 1.15 MB 14.6 -> 10.4, 2.29 MB 17.1 -> 14.2, 4.59 MB 27.5 -> 22.2 TP2: 1.65 MB 11.7 -> 9.5, 2.29 MB 13.8 -> 11.9 The regression test gets an in-place case (output aliasing the input) that covers the one-shot with 1, 2 and 4 packets a sender, and the two-shot. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 plain all-reduce defaults to RCCL past the measured crossover As agreed on #7432 (11-05). On gfx1250, with AITER_CUSTOM_AR_MAX_SIZE unset, plain all-reduce (CudaCommunicator.all_reduce) runs the custom kernels only up to about where RCCL becomes faster: 4 MiB at TP2 and TP4, 8 MiB at TP8. Larger inputs went to the two-shot (TP4, 4-8 MiB) or to the one-shot pull, which takes 405 us at 14.68 MB at TP8 against 55 us for RCCL. - New binding ll_ar_max_bytes(world_size): the largest input the LL kernels take, max(kLLArMaxBytes, ar2sMaxBytes). The default never exceeds it, so Python does not copy the C++ caps. - An explicit AITER_CUSTOM_AR_MAX_SIZE keeps its meaning. TP6 and gfx9 keep the AR cutoff. - should_custom_ar and the fused AR + RMSNorm paths are unchanged; their fallback to all_reduce picks up the default. - Tests: the default applies only with the env unset (test_custom_allreduce_size_env.py), and every rank resolves the same cutoff and takes the same path (test_custom_allreduce.py --regression). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 484095e)
) * Add support for fused AR add kernel * ruff fix * validate all_reduce_add inputs, fix 16-byte gfx950 dispatch, retune caps * Share gfx950 AR stage rule with all_reduce_residual; retune caps Move the gfx950 1-/2-stage rule and the packs < world_size guard into select_ar_stage() and the LL/LL128 caps into select_ll_path(), so allreduce and allreduce_residual pick stages the same way (TP2 residual is no longer 1-stage only). Add ops.all_reduce_one_shot and make uses_1stage_ar() query the dispatch, LL included. #6954 made LL/LL128 slower near their caps; re-swept on the merged tree: TP8 plain LL aligned 40 -> 32 KB, TP8 fused LL aligned 64 -> 56 KB, TP4 fused unaligned LL 96 -> 112 KB with LL128 dropped. * Give LL / LL128 their own scratch region in the meta buffer The LL and LL128 kernels staged into the meta buffer's post-Signal region, the same memory the 2-stage kernels use as tmp. The 2-stage kernels end without a barrier and the LL kernels write into peers' scratch without one, so an LL call right after a 2-stage call could overwrite a peer's reduce-scatter partial while other ranks still read it in stage 2. This failed CI in test_custom_allreduce_add.py's interleaved graph (TP8 bf16, fused 256 KB + 16 B naive 2-stage followed by fused 88 KB + 16 B LL). Plain all-reduce hits it too when lamport is off (AITER_CUSTOM_AR_DISABLE_LAMPORT=1); with lamport on, lamport takes every size plain LL / LL128 would serve after a 2-stage call. The meta buffer is now [Signal][LL / LL128 scratch][tmp]: get_tmp_buf and local_tmp_reduced_ptr skip kLLScratchBytes and meta_size() includes it, so the Python allocation (meta_size() + 2 * max_size) is unchanged. kLL128PocCapBytes drops from 4 MB to 1 MB (the dispatch sends at most 896 KB), which keeps the new region at 21 MiB. --------- Co-authored-by: TennyWang1223 <[email protected]>
Problem
cross_device_reduce_2stageandcross_device_reduce_2stage_naiverotate their input pointers so that the rank owning an output segment adds its own partial first and then the other ranks in ring order:Which rank owns an element depends on the element's offset in the tensor. So the same row reduced at a different offset (for example, a different batch composition) can be summed in a different FP32 order. When the sum lies close to a BF16 rounding midpoint, the result lands on a neighbouring BF16 value. The four partials are bit-identical in both cases, and the two outputs differ by exactly one ULP.
The LL (
ar_ll_gfx9) and LL128 (ar_ll128_unroll2) paths have the related receiver-side problem: each receiver adds its own value first, so different ranks can round the same element differently.Change
cross_device_reduce_2stage/_naive: read inputs asptrs[i] = input[i], i.e. rank 0 → n-1. This matchescross_device_reduce_1stage,2stage_write_modeand the fused AR+RMSNorm kernels, which already sum in that order. The temporary buffers and the all-gather stage keep their existing rotated layout, because they only move data.Every custom-AR reduce path now produces the same bits for a given set of partials, independent of:
Test plan
torchrun --nproc-per-node=4 -m pytest op_tests/multigpu_tests/test_custom_allreduce_rank_order.pyRemaining communication paths with the same issue (not fixed here)
These were found by sweeping
csrc/includeandaiter/distfor rank-rotated reductions. They are left for a follow-up.Sum order depends on element position
communicator_cuda.pyall_reduce→pynccl_comm.all_reduce.AITER_CUSTOM_AR_MAX_SIZE(default 64 MiB).reduce_scatter_split_first_dim,reduce_scatter_split_lastdim(_naive),reduce_scatter_split_middim(_naive)custom_all_reduce.cuh~L880–1060.ptrs[i] = input[(rank + i) % ngpus], so each output segment is summed starting from its owner rank.ptrs[i] = input[i].Different ranks can round the same element differently
sum2of the variance)custom_all_reduce.cuh~L2730–2750.tmps[(rank + r) % ngpus]starting from the local rank, so the normalisation denominator for the same token can differ by one rounding across ranks.r = 0..ngpus-1in order.allReduceQuantFp8custom_all_reduce.cuh~L1288.ptrs.custom_all_reduce_gfx1250.cuh(rank + i) % ngpusat ~L427, 515, 547, 583, 624, 702, 744, 781, 829, 867).To verify
reduce_scatterv/reduce_scatterthrough RCCLThe custom-AR kernels already summing in fixed rank order were checked and need no change:
cross_device_reduce_1stage(_naive),cross_device_reduce_2stage_write_mode,reduce_scatter_cross_device_store, and the one-shot fused AR+RMSNorm family.