Repository navigation
[HIP] fea: impl gfx1250 lamport ar+rms - #7499
Conversation
Signed-off-by: TennyWang1223 <[email protected]>
🏷️ 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 |
Resolve the conflict in csrc/include/custom_all_reduce_gfx1250.cuh: both sides added new CustomAllreduce members after allreduce_ll(). Keep both, the Lamport fused AR + RMSNorm entry points (init_lamport_ar_rms, fused_allreduce_rmsnorm_lamport) followed by the LL all-gather ones from #7265 (use_ll_ag, ll_ag_reads_in_place, allgather_ll), each closing its own brace. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
ci failed |
Resolve the conflict with the gfx9 lamport allreduce (#7452) in CustomAllreduce init: gfx1250 sets up the lamport AR + RMSNorm inbox, other archs the lamport allreduce. Add TODOs on both inits for when each arch gets the other lamport op. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
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]>
…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]>
Lamport all-reduce of x + y (
|
| M | This PR | #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 |
At the cap, TP4 8 MiB is 30.5 us (RCCL 33.2) and TP2 16 MiB is 29.1 us (custom AR 64.7).
Testing
op_tests/multigpu_tests/test_ar_add_lamport.py:
- Bit-exact against the rank-order fp32 reference at TP2/TP4, bf16 and fp16.
- Mixed sequence on the shared inbox, 0 bit difference: the add interleaved with AR + RMSNorm, partial last waves, injected
0xffff, fallback and broadcast calls
checked against the fake, and HIP graph replays with fresh inputs.
Conflicts with #7499 (gfx1250 Lamport AR + RMSNorm), both additive: the plain all-reduce cutoff table and the Lamport size table in custom_all_reduce.py, and the two-shot tables and the Lamport inbox member in CustomAllreduce. Both kept. 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]> (cherry picked from commit 06b7fd3)
…ute up to hidden 2048 where Lamport runs With the Gluon all-reduce on (TP4), fused_allreduce_rmsnorm took the Gluon power-of-2 AR + RMSNorm (all_reduce_rmsnorm_quant, #6974) for every power-of-2 hidden up to 8 MiB, ahead of the Gluon per-token kernel and the Lamport one-shot, which came later (#7499). At hidden 4096 / 8192 it took 1.02-1.63x / 1.45-4.85x the time of those routes (4x MI455X, TP4, CUDA graphs, 1 row to the 8 MiB cap); at 1024 / 2048 it stays the faster route. Where the Lamport one-shot can take the call, the power-of-2 route now stops at hidden 2048 (_GLUON_AR_MAX_HIDDEN_WITH_LAMPORT) and larger hidden sizes take the routes after it: the Gluon per-token kernel up to 128 rows, then Lamport. Their bf16 output bits differ from the power-of-2 kernel's in the last place (another reduction order). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Add a Lamport one-shot fused all-reduce + residual add + RMSNorm kernel for gfx1250.
fused_allreduce_rmsnormnow uses it on TP2 up to 16 MiB and on TP4 up to 8 MiB. Above that size, and for TP6/TP8, the routing is unchanged.Motivation
On gfx1250, inputs ≤ 4 MiB currently go through LL all-reduce followed by a separate
rmsnorm2d_fwd_with_add, which is two kernels. Inputs above 4 MiB go toar_rmsnorm_gfx1250, which pays for a barrier and a copy-in. The Lamport kernel does the whole thing in one kernel with no barrier and no copy-in: each rank pushes its data straight into the peers' inboxes, and the readers poll for a 0xffff sentinel. That makes it 1.3–2.1x faster than the current route in the decode / small-prefill range.Changes
custom_all_reduce_gfx1250.cuh): there are two layouts. In row mode one block handles one row. In cluster mode one workgroup cluster handles one row, and partial sums are combined through a cluster barrier. The inbox is triple-buffered and tracks rounds with a counter per wave.clusterDimofhipLaunchKernelEx. After capture, the kernel puts it back on the captured node withhipGraphKernelNodeSetAttribute. Without this, a graph runs the kernel with no cluster sync and the RMSNorm comes out wrong.lamport_ar_rms_buffer_size/init_lamport_ar_rms/fused_allreduce_rmsnorm_lamport, all inmodule_custom_all_reduce_gfx1250.CustomAllreduce._init_lamport_ar_rmssets up one IPC inbox per communicator. It uses cached memory and takes 96 MiB per rank on both TP2 and TP4.should_lamport_ar_rmsdecides from shape, dtype and size only, so every rank picks the same path.CudaCommunicator.fused_allreduce_rmsnorm, after the opt-in Gluon branch, soAITER_GLUON_FUSED_ARstill takes precedence.AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZEoverrides the size cap. Setting it to0turns the path off.Performance (if applicable)
4x gfx1250 (256 CU), ROCm 10.1, IPC transport, CUDA graph (10 calls × 20 replays, median per rank, slowest rank reported).
Before = old production route: ≤ 4 MiB → LL AR +
rmsnorm2d_fwd_with_add, > 4 MiB →ar_rmsnorm_gfx1250. After = this PR.TL;DR: TP2 1.26–2.14x, TP4 1.33–1.83x, bf16 and fp16 alike. Inputs above the cap (TP4 > 8 MiB) keep the old route.
bf16
fp16 (all measured points)
vs Gluon (opt-in
AITER_GLUON_FUSED_AR=1)Gluon only covers TP4, bf16, power-of-2 hidden and ≤ 8 MiB. It is still opt-in and, when enabled, still takes precedence over Lamport. E2E models run a single fixed hidden, so whether to turn it on can be decided per model.
Testing
Documentation
This is an internal routing change. The only new user-facing knob is the env var, and it is documented in the docstring of
_resolve_lamport_ar_rms_max_size.Dependencies
Breaking Changes
None. Note that on gfx1250 with TP2/TP4, each rank now allocates an extra 96 MiB IPC inbox at init. Set
AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE=0to opt out.PR Self-Review
Reviewed revision
719d23e
Behavior and intent
On gfx1250 TP2/TP4, fused AR + RMSNorm calls up to the size cap now go through a single Lamport kernel instead of LL AR + RMSNorm or the barrier fused kernel. The output is bit-identical to
ar_rmsnorm_gfx1250. Larger inputs, TP6/TP8, other archs, and the opt-in Gluon path behave as before.Validation and unverified scope
Command:
python op_tests/multigpu_tests/test_fused_ar_rms_lamport.py -d bf16 fp16(defaults: TP 2 and 4, M 1–1024, hidden 2048/4096/7168/8192)ar_rmsnorm_gfx1250for every case under the cap, in both bf16 and fp16.PR-specific question
Changed op tests
op_tests/multigpu_tests/test_fused_ar_rms_lamport.py(new): checks Lamport correctness (bit-exact against the barrier fused kernel, a mixed sequence on the shared inbox, and graph replay with fresh input) and times it against the production route,car_fused,car_ar+normandrccl+norm. The existing tests do not cover this kernel or its inbox round and sentinel protocol.