Skip to content

[Triton/Gluon] [Perf] gfx1250 all-reduce: fold a residual add into the reduce - #7488

Closed
karverma-amd wants to merge 2 commits into
ROCm:mainfrom
karverma-amd:karverma/gfx1250-allreduce-fused-residual-add
Closed

karverma-amd wants to merge 2 commits into
ROCm:mainfrom
karverma-amd:karverma/gfx1250-allreduce-fused-residual-add

Conversation

@karverma-amd

@karverma-amd karverma-amd commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

all_reduce(x, ..., x2=y) reduces x + y without a separate add kernel, on the gfx1250 Gluon all-reduce. Exposed as tensor_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: optional x2 operand. The sending and receiving programs both load that rank's x and x2, add in fp32 and round to bf16 before packing, so the result is the sum over ranks of each rank's x + x2, with the bits of all_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, with all_reduce_add_fake (shape and dtype of tensor + other, as the fallback returns), and GroupCoordinator.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: x2 defaults to None and the new entry points are additive.

Performance (if applicable)

Hardware Workload/configuration Before After Change
4x gfx1250, TP4 bf16 [8, 5120], 43 calls per HIP graph, slowest rank 6.59 us (add + all-reduce) 5.05 us -23%
4x gfx1250, TP4 bf16 [48, 5120] (DeepSeek-V4.1-Flash C8 decode) 7.60 us 6.03 us -21%
4x gfx1250, TP4 bf16 [96, 5120] 11.64 us 9.62 us -17%
4x gfx1250, TP4 bf16 [288, 5120] 21.42 us 19.21 us -10%

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Tested on gfx1250 only; the fused path is gfx1250 Gluon only, and other targets take the unchanged fallback.

Documentation

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

Dependencies

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

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 without x2 are unchanged.

Validation and unverified scope

  • 4x gfx1250: python3 -m pytest -q op_tests/multigpu_tests/triton_test/test_all_reduce.py -> 2 passed (existing test_all_reduce and new test_all_reduce_add).
  • Through ATOM (perf(dsv41): fold the shared-expert add into the MoE TP all-reduce via HIP Lamport kernel ATOM#3020, tests/model_ops/test_all_reduce_add_gpu.py): tensor_model_parallel_all_reduce_add vs tensor_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.
  • Timing: bf16 x 5120, rows 8/48/96/288, 43 calls captured in a HIP graph, slowest rank (table above).
  • black --check (26.10) and ruff check clean on changed files.
  • Unverified: MI250X / MI300X / MI355X (they take the fallback, not exercised here); dtypes other than bf16; world sizes other than 4.

PR-specific question

test_all_reduce_add fails before this PR because all_reduce(..., x2=), all_reduce_add and tensor_model_parallel_all_reduce_add do not exist. With a wrong implementation it fails on any bit difference from all_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: adds test_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.

…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.
@karverma-amd
karverma-amd requested a review from a team November 5, 2026 02:50
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

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

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

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

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

@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 32be6992db64 · mode shadow

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

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

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

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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 x2 operand, 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]>
@karverma-amd

Copy link
Copy Markdown
Contributor Author

On the Copilot review note about the fake: fixed in 32be699. all_reduce_add_ reused all_reduce_fake (empty_like(tensor)), but off the Gluon fused path it returns all_reduce(tensor + other), whose shape and dtype follow broadcasting and type promotion. It now has its own all_reduce_add_fake, which returns torch.broadcast_shapes(tensor.shape, other.shape) with torch.result_type(tensor, other). New tests/test_all_reduce_add_fake.py (CPU, stub communicator) checks the fake against the eager fallback for same-shape bf16, fp32 other, broadcast other and broadcast tensor. 4 passed; with the previous fake the mixed-dtype and broadcast-tensor cases fail. The fused Gluon path is unchanged: it is taken only for same shape and dtype. Black and ruff clean.

Boss2002n pushed a commit that referenced this pull request Nov 6, 2026
…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]>
@TennyWang1223 TennyWang1223 mentioned this pull request Nov 6, 2026
5 of 10 tasks
junhaha666 pushed a commit that referenced this pull request Nov 11, 2026
* 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]>
@Boss2002n

Copy link
Copy Markdown
Contributor

Pls resolve merge conflicts

junhaha666 pushed a commit to ROCm/ATOM that referenced this pull request Nov 13, 2026
…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]>
@karverma-amd

Copy link
Copy Markdown
Contributor Author

closing Main already covered PR 7489

lirui927 pushed a commit that referenced this pull request Nov 16, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants