Repository navigation
[Triton/Gluon] [Perf] gfx1250 all-reduce: fold a residual add into the reduce - #7488
karverma-amd wants to merge 2 commits into
Conversation
…e reduce
`all_reduce(x, ..., x2=y)` reduces x + y without the separate add: the
sending and receiving programs both load x and x2, add them in fp32 and round
to bf16 before packing, so the result has the bits of `all_reduce(x + y)` and
every rank still gets the same bits. The plain path is unchanged.
Wired through `CudaCommunicator.all_reduce_add`, the `all_reduce_add_` custom
op, `GroupCoordinator.all_reduce_add` and
`tensor_model_parallel_all_reduce_add`; anything outside the Gluon path falls
back to the add followed by the regular all-reduce.
DeepSeek-V4.1-Flash TP4 decode adds the shared expert into the routed MoE
output right before the TP all-reduce on every MoE layer. Bf16 x 5120, 43
calls per HIP graph, slowest rank:
rows add + all-reduce fused
8 6.59 us 5.05 us
48 7.60 us 6.03 us
96 11.64 us 9.62 us
288 21.42 us 19.21 us
test_all_reduce.py: test_all_reduce_add checks bit-exactness against the
materialized sum over decode and partial-chunk sizes, plain and fused calls
interleaved on the same counters, and 20 HIP graph replays.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🔵 Needs a closer look
The fake reports incorrect dtype and shape for mixed-dtype, broadcasted inputs, giving torch.compile metadata that differs from the fallback output.
No open issues 🎉
What changed in this PR
This PR adds a fused residual-add path to AITER’s gfx1250 Gluon all-reduce, avoiding a separate add kernel for tensor-parallel workloads.
Changes:
- Adds an optional
x2operand, with each local sum rounded to bf16 before reduction. - Exposes
tensor_model_parallel_all_reduce_add, with add-then-reduce fallback outside the supported Gluon path. - Adds multi-GPU correctness checks for partial chunks, interleaved calls, and HIP-graph replay.
| File | Description |
|---|---|
op_tests/multigpu_tests/triton_test/test_all_reduce.py |
Adds fused-add correctness and graph-replay tests. |
aiter/ops/triton/comms/all_reduce.py |
Validates and forwards the optional residual operand. |
aiter/ops/triton/_gluon_kernels/gfx1250/comms/all_reduce.py |
Fuses residual addition into sender and receiver loads. |
aiter/dist/parallel_state.py |
Adds the custom op and group-level dispatch. |
aiter/dist/device_communicators/communicator_cuda.py |
Selects fused execution or add-then-reduce fallback. |
aiter/dist/communication_op.py |
Exposes the tensor-parallel all-reduce-add API. |
Review effort: Balanced
all_reduce_add_ reused all_reduce_fake, which returns empty_like(tensor). Off the Gluon fused path the op returns all_reduce(tensor + other), whose shape and dtype follow broadcasting and type promotion, so torch.compile saw the wrong metadata for a broadcast or mixed-dtype other. all_reduce_add_fake returns broadcast_shapes / result_type of the two. tests/test_all_reduce_add_fake.py (CPU): the fake against the eager fallback for same, mixed-dtype and broadcast operands. Co-authored-by: Cursor <[email protected]>
|
On the Copilot review note about the fake: fixed in 32be699. |
…reduce_add) DeepSeek-V4.1 TP decode adds the shared-expert output into the routed MoE output right before the TP all-reduce of every MoE layer. The sum over ranks of each rank's x + y now runs as one Lamport one-shot kernel on gfx1250: each rank adds its pair in fp32 and rounds to the dtype before sending, so the result has the bits of all-reducing the materialized sum, the same on every rank. The kernel shares the AR + RMSNorm inbox, round counters and size cap (TP2 16 MiB, TP4 8 MiB), so it takes no extra memory. Its kernel arguments are scalars and pointers only, the inboxes one by one: the module preloads kernel arguments into SGPRs up to the first aggregate, and a LamportPeers argument left the rest to serial s_loads before the first remote store, about 1 us of a decode-size call. Entry points follow #7488, which ROCm/ATOM#3020 calls: tensor_model_parallel_all_reduce_add -> GroupCoordinator.all_reduce_add -> the all_reduce_add_ custom op (its fake follows the add-then-reduce fallback) -> CudaCommunicator.all_reduce_add, which takes the Lamport kernel where it fits and all_reduce(x + y) otherwise. 4x gfx1250, TP4, bf16 [M, 5120], 43 calls per HIP graph, slowest rank, us: M this #7488 Gluon fused add + RCCL 1 5.18 5.35 10.7 8 5.61 6.08 10.3 48 6.58 7.48 12.2 96 7.81 9.68 14.3 288 14.4 17.3 25.0 409 17.8 22.3 27.0 test_ar_add_lamport.py: bit-exact against the rank-order fp32 reference at TP2/TP4, bf16 and fp16, and a mixed sequence on the shared inbox (the add between AR + RMSNorm calls, partial last waves, injected 0xffff, fallback and broadcast calls against the fake, HIP graph replays with fresh inputs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
* fea: impl gfx1250 lamport ar+rms Signed-off-by: TennyWang1223 <[email protected]> * Remove the DBG_LAMPORT_BS measurement hook It forced the lamport AR + RMSNorm cluster block size from the env and was only meant for tuning; cluster_threads now always uses its heuristic. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Guard the lamport cluster path for non-gfx1250 archs and older ROCm The module is prebuilt for every CI arch (gfx942/gfx950 on ROCm 7.2.4), where the cluster barrier, the cluster memory scope and the cluster launch attribute do not exist. Compile the cluster kernel out on the device side unless the target is gfx1250 with cluster support, and on the host side detect hipLaunchAttributeValue::clusterDim so every call takes the block-a-row path when the HIP headers lack cluster launch. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Add a gfx1250 Lamport all-reduce of x + y (tensor_model_parallel_all_reduce_add) DeepSeek-V4.1 TP decode adds the shared-expert output into the routed MoE output right before the TP all-reduce of every MoE layer. The sum over ranks of each rank's x + y now runs as one Lamport one-shot kernel on gfx1250: each rank adds its pair in fp32 and rounds to the dtype before sending, so the result has the bits of all-reducing the materialized sum, the same on every rank. The kernel shares the AR + RMSNorm inbox, round counters and size cap (TP2 16 MiB, TP4 8 MiB), so it takes no extra memory. Its kernel arguments are scalars and pointers only, the inboxes one by one: the module preloads kernel arguments into SGPRs up to the first aggregate, and a LamportPeers argument left the rest to serial s_loads before the first remote store, about 1 us of a decode-size call. Entry points follow #7488, which ROCm/ATOM#3020 calls: tensor_model_parallel_all_reduce_add -> GroupCoordinator.all_reduce_add -> the all_reduce_add_ custom op (its fake follows the add-then-reduce fallback) -> CudaCommunicator.all_reduce_add, which takes the Lamport kernel where it fits and all_reduce(x + y) otherwise. 4x gfx1250, TP4, bf16 [M, 5120], 43 calls per HIP graph, slowest rank, us: M this #7488 Gluon fused add + RCCL 1 5.18 5.35 10.7 8 5.61 6.08 10.3 48 6.58 7.48 12.2 96 7.81 9.68 14.3 288 14.4 17.3 25.0 409 17.8 22.3 27.0 test_ar_add_lamport.py: bit-exact against the rank-order fp32 reference at TP2/TP4, bf16 and fp16, and a mixed sequence on the shared inbox (the add between AR + RMSNorm calls, partial last waves, injected 0xffff, fallback and broadcast calls against the fake, HIP graph replays with fresh inputs). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Signed-off-by: TennyWang1223 <[email protected]> Co-authored-by: TennyWang1223 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Pls resolve merge conflicts |
…a HIP Lamport kernel (#3020) * perf(dsv41): fold the shared-expert add into the MoE TP all-reduce `MoE.combine_outputs` added the shared expert into the routed output and then all-reduced the sum. At TP > 1 it now calls `tensor_model_parallel_all_reduce_add(routed, shared)`, which aiter's gfx1250 Gluon all-reduce serves in one kernel with the same bits (the add happens as the reduce loads its input). Where aiter has no fused op, on the TBO path, or outside the Gluon path, it is the add followed by the plain all-reduce, as before. DeepSeek-V4.1-Flash TP4 C8 decode (48 rows x 5120 bf16): 7.60 -> 6.03 us per MoE layer, ~70 us per 9.55 ms step over 43 layers. Needs the aiter all-reduce add (karverma-amd/aiter karverma/gfx1250-allreduce-fused-residual-add); without it this falls back to the add followed by the plain all-reduce. * test(dsv41): fused all-reduce add vs add + all-reduce, bit for bit Review on #3020: name the aiter op (ROCm/aiter#7488) and its semantics in the wrapper, and check the numerics. The fused op is the sum over ranks of each rank's x + y, the same bits as all-reducing the materialized sum. tests/model_ops/test_all_reduce_add_gpu.py (4 gfx1250 GPUs, skips elsewhere): tensor_model_parallel_all_reduce_add(routed, shared) against tensor_model_parallel_all_reduce(routed + shared) at 5120 bf16, rows 1-409 (fused Gluon kernel, asserted to run) and 410/4096 (fallback), equal on every rank, eager and over HIP graph replays. * perf(dsv41): serve the fused MoE all-reduce add with the HIP Lamport kernel The shared-expert add still goes through tensor_model_parallel_all_reduce_add. aiter#7499 serves that op with the gfx1250 HIP one-shot kernel. The test now requires lamport_ar_add for every row count the kernel accepts, including a HIP-graph capture, and checks the bits against add plus all-reduce. Co-authored-by: Cursor <[email protected]> * test(dsv41): pin the Lamport all-reduce cap to the TP4 8 MiB default The row search used to stop at whatever should_lamport_ar_add accepted, so a wrong cap still passed. The unset TP4 limit is 819 rows, and the probe now stops at 4096. Co-authored-by: Cursor <[email protected]> * Call aiter's all-reduce add directly. ATOM no longer probes for tensor_model_parallel_all_reduce_add. The TBO path still adds and all-reduces here; aiter#7499 owns kernel eligibility and the other fallback. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Verma, Karan <[email protected]> Co-authored-by: karverma-amd <[email protected]> Co-authored-by: Cursor <[email protected]>
|
closing Main already covered PR 7489 |
* fea: impl gfx1250 lamport ar+rms Signed-off-by: TennyWang1223 <[email protected]> * Remove the DBG_LAMPORT_BS measurement hook It forced the lamport AR + RMSNorm cluster block size from the env and was only meant for tuning; cluster_threads now always uses its heuristic. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Guard the lamport cluster path for non-gfx1250 archs and older ROCm The module is prebuilt for every CI arch (gfx942/gfx950 on ROCm 7.2.4), where the cluster barrier, the cluster memory scope and the cluster launch attribute do not exist. Compile the cluster kernel out on the device side unless the target is gfx1250 with cluster support, and on the host side detect hipLaunchAttributeValue::clusterDim so every call takes the block-a-row path when the HIP headers lack cluster launch. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Add a gfx1250 Lamport all-reduce of x + y (tensor_model_parallel_all_reduce_add) DeepSeek-V4.1 TP decode adds the shared-expert output into the routed MoE output right before the TP all-reduce of every MoE layer. The sum over ranks of each rank's x + y now runs as one Lamport one-shot kernel on gfx1250: each rank adds its pair in fp32 and rounds to the dtype before sending, so the result has the bits of all-reducing the materialized sum, the same on every rank. The kernel shares the AR + RMSNorm inbox, round counters and size cap (TP2 16 MiB, TP4 8 MiB), so it takes no extra memory. Its kernel arguments are scalars and pointers only, the inboxes one by one: the module preloads kernel arguments into SGPRs up to the first aggregate, and a LamportPeers argument left the rest to serial s_loads before the first remote store, about 1 us of a decode-size call. Entry points follow #7488, which ROCm/ATOM#3020 calls: tensor_model_parallel_all_reduce_add -> GroupCoordinator.all_reduce_add -> the all_reduce_add_ custom op (its fake follows the add-then-reduce fallback) -> CudaCommunicator.all_reduce_add, which takes the Lamport kernel where it fits and all_reduce(x + y) otherwise. 4x gfx1250, TP4, bf16 [M, 5120], 43 calls per HIP graph, slowest rank, us: M this #7488 Gluon fused add + RCCL 1 5.18 5.35 10.7 8 5.61 6.08 10.3 48 6.58 7.48 12.2 96 7.81 9.68 14.3 288 14.4 17.3 25.0 409 17.8 22.3 27.0 test_ar_add_lamport.py: bit-exact against the rank-order fp32 reference at TP2/TP4, bf16 and fp16, and a mixed sequence on the shared inbox (the add between AR + RMSNorm calls, partial last waves, injected 0xffff, fallback and broadcast calls against the fake, HIP graph replays with fresh inputs). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Signed-off-by: TennyWang1223 <[email protected]> Co-authored-by: TennyWang1223 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 06b7fd3)
Summary
all_reduce(x, ..., x2=y)reducesx + ywithout a separate add kernel, on the gfx1250 Gluon all-reduce. Exposed astensor_model_parallel_all_reduce_add; anything outside the Gluon path falls back to the add followed by the regular all-reduce. The plain path is unchanged.Related: consumed by ROCm/ATOM#3020 (DeepSeek-V4.1 MoE shared-expert add), which falls back when this op is absent.
Motivation
DeepSeek-V4.1-Flash TP4 decode adds the shared-expert output into the routed MoE output right before the TP all-reduce on every MoE layer (43 per step). Today that is a separate elementwise kernel plus one extra read and write of the activation per layer.
Changes
aiter/ops/triton/_gluon_kernels/gfx1250/comms/all_reduce.py: optionalx2operand. The sending and receiving programs both load that rank'sxandx2, add in fp32 and round to bf16 before packing, so the result is the sum over ranks of each rank'sx + x2, with the bits ofall_reduce(x + y), the same on every rank.aiter/ops/triton/comms/all_reduce.py:x2=on the wrapper.aiter/dist/device_communicators/communicator_cuda.py:CudaCommunicator.all_reduce_add(Gluon path, else add +all_reduce).aiter/dist/parallel_state.py:all_reduce_add_custom op, withall_reduce_add_fake(shape and dtype oftensor + other, as the fallback returns), andGroupCoordinator.all_reduce_add.aiter/dist/communication_op.py:tensor_model_parallel_all_reduce_add.op_tests/multigpu_tests/triton_test/test_all_reduce.py:test_all_reduce_add.tests/test_all_reduce_add_fake.py(CPU): the fake against the eager fallback for same, mixed-dtype and broadcast operands.No existing call changes behaviour:
x2defaults toNoneand the new entry points are additive.Performance (if applicable)
Testing
Tested on gfx1250 only; the fused path is gfx1250 Gluon only, and other targets take the unchanged fallback.
Documentation
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
a063f75
Behavior and intent
Adds an optional residual operand to the gfx1250 Gluon all-reduce so
all_reduce(x + y)runs as one kernel with the same bits as the materialized sum. The existing behaviour is insufficient because callers that add right before a TP all-reduce (DeepSeek-V4.1 MoE: shared expert + routed) pay a separate add kernel and an extra pass over the activation. Calls withoutx2are unchanged.Validation and unverified scope
python3 -m pytest -q op_tests/multigpu_tests/triton_test/test_all_reduce.py-> 2 passed (existingtest_all_reduceand newtest_all_reduce_add).tests/model_ops/test_all_reduce_add_gpu.py):tensor_model_parallel_all_reduce_addvstensor_model_parallel_all_reduce(x + y)at 5120 bf16, rows 1-409 (fused) and past the 4 MiB cap (fallback), eager and HIP-graph replays: 0 differing elements on every rank.black --check(26.10) andruff checkclean on changed files.PR-specific question
test_all_reduce_addfails before this PR becauseall_reduce(..., x2=),all_reduce_addandtensor_model_parallel_all_reduce_adddo not exist. With a wrong implementation it fails on any bit difference fromall_reduce(x + y)or between ranks, on a partial last chunk, when plain and fused calls share the signal counters, or on HIP-graph replay. The existing canonical test (test_all_reduce) covers only the plain reduce and has no second operand, so it cannot catch any of these.Changed op tests
op_tests/multigpu_tests/triton_test/test_all_reduce.py: addstest_all_reduce_add, which checks the fused reduce bit-exact against the materialized sum on every rank, over decode sizes and partial-chunk sizes, with plain and fused calls interleaved on the same counters, and across 20 HIP-graph replays. Not redundant: no existing test passes a residual operand.