Skip to content

[HIP] gfx1250: INT4 / INT8-coded Lamport two-shot all-reduce (opt-in, lossy) - #8012

Draft
gbyu-amd wants to merge 1 commit into
mainfrom
gyu/gfx1250-q4-lamport-2s
Draft

gbyu-amd wants to merge 1 commit into
mainfrom
gyu/gfx1250-q4-lamport-2s

Conversation

@gbyu-amd

@gbyu-amd gbyu-amd commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An opt-in, lossy all-reduce for large bf16 messages on gfx1250: a coded Lamport two-shot. By default every 28 elements travel as one 16-byte line (28 int4 levels plus the group's bf16 scale), so the wire carries 0.29x the bytes of a lossless bf16 two-shot. AITER_CUSTOM_AR_Q4_2S_CODEC=8 picks INT8 instead: 14 elements a line (0.57x the bytes, error ~1/254 of the group max). tensor_model_parallel_all_reduce / CudaCommunicator.all_reduce take it for bf16 inputs of AITER_CUSTOM_AR_Q4_2S_MIN_SIZE < bytes <= AITER_CUSTOM_AR_Q4_2S_MAX_SIZE. The max also sizes the inbox; unset or 0 means off, so nothing changes by default. It works on the IPC transport (one node) and on the torch symm_mem transport, i.e. TP groups that span nodes.

Motivation

Prefill-size all-reduces (tens to hundreds of MB) are bandwidth-bound. The INT4 quick-reduce is the usual lossy answer, but on gfx1250 it does not help here, for two reasons:

  • Across nodes it is disabled. It exchanges IPC handles.
  • At TP8 it saves no bytes. PullQ4 pulls every rank's compressed message, so each rank moves (ws - 1) x 0.28 x N, about what a lossless two-shot moves (2 x (ws - 1) / ws x N).

A coded two-shot cuts the bytes per rank to 0.29x of the lossless two-shot at any world size. It also stays push-only, and the push-only Lamport form is what runs well on gfx1250. A flag + release-fence protocol is slow on gfx1250, because the system-scope release writes back L2 every tile.

Design (custom_all_reduce_gfx1250.cuh: lamport_q4_2s_gfx1250, LamportQ4Ar2s)

  • Codec. A group of 28 consecutive elements becomes one 16-byte line:

    • 28 int4 levels in [-7, 7], stored +7, so no nibble is 0xf;
    • the scale amax / 7 as bf16 (sign bit 0) in the top half of the last word.

    Values are rounded to nearest-even and clamped. Hence no word of a coded line can be 0xffffffff, which is the inbox sentinel: a line has landed once its four words differ from it, so 4-byte single-copy atomicity is enough. There are no flag words and no fences.

  • Two-shot. The message splits into ws chunks of groups, and rank c reduces chunk c.

    • Role 0 of a block codes group g of every other chunk and pushes it to that rank's RS slot [rank]. After all its groups, it polls the AG lines and writes the decoded values out.
    • Role 1 polls the RS lines of the own chunk, all (ws - 1) lines in flight at once, and sums them in fp32 with the own exact input. It rounds the sum to bf16, codes it once, and pushes that to every peer's AG slot. It also writes the decoded sum out, so every rank holds the same bits.
  • Graph-safe state.

    • The grid is fixed: the co-resident capacity (occupancy x CUs, queried once at init) runs on every call. A wave therefore owns the same groups in every call, and a per-wave round counter (rank-local, equal on all ranks) picks one of two banks.
    • A reader re-arms a line with the sentinel right after reading it. The next write to that line is at least two calls later, because a peer is at most one call ahead and a call's stores have landed by the time it ends. So calls of different sizes never leave a stale line, and no host-side state changes between replays.
  • Inbox. lamport_q4_2s_buffer_size(ws, max_bytes) bytes a rank: 2 banks x (RS + AG) x ws x ceil(max / 2 / 28 / ws) lines of 16 B (307 MB a rank at TP8 for 256 MiB). It is filled with the sentinel through system-scope stores at init, and a barrier follows so that every fill lands before any push.

Accuracy

The route is lossy by design, in the class of the INT4 quick-reduce. Each element passes two quantisations: its rank's partial in the reduce-scatter, and the reduced value in the all-gather. On N(0, 1) inputs, max |out - ref| / max |ref| is 0.09-0.14 for INT4 (TP2 to TP8) and 0.006-0.008 for INT8 (test_custom_allreduce_q4.py, which bounds it at 0.2 / 0.03). Inputs below the window keep the lossless route, so decode-size messages are unaffected when MIN is set above them.

Results

MI455X, bf16, CUDA graph of 10 calls, slowest rank's median, us per all-reduce. "fallback" is the same call with the route off (custom all-reduce up to its window, RCCL above):

TP, transport 8.2 MB 14 MB 28 MB 56 MB 112 MB 224 MB
TP2, one tray (IPC), INT4 15.9 (143) 17.3 (155) 26.3 (197) 45.1 (264) 81.3 (390) 153.4
TP2, one tray (IPC), INT8 20.0 (143) 24.9 (151) 38.5 (196) 67.2 (261) 125.1 (392) 242.7
TP4, one tray (IPC), INT4 25.2 (41.9) 28.5 (47.5) 35.2 (192) 54.7 (226) 97.1 (310) 187.9 (RCCL fails)
TP4, one tray (IPC), INT8 31.4 (41.9) 33.6 (47.6) 49.3 (188) 85.4 (227) 161.0 (309) 317.1 (RCCL fails)
TP8, two nodes (symm_mem), INT4 42.6 (49.8) 44.2 (55.2) 48.4 (93.7) 76.0 (190.6) 133.8 (272.7) 253.5 (493.0)

Test

op_tests/multigpu_tests/test_custom_allreduce_q4.py -t 2 4 [--codec 8] covers:

  • the routing decision;
  • the error bound against an fp32 sum of every rank's input, and equal bits on all ranks;
  • sizes whose last iteration is partial;
  • a mixed sequence of 144 calls. Seeded random sizes cross the window boundary, run eager and inside CUDA graphs replayed with fresh inputs, with eager calls of other sizes in between.

All passed on TP2 and TP4 with both codecs. At TP8 across two nodes (torch symm_mem transport), a mixed-size sequence through tensor_model_parallel_all_reduce with the route on (eager and CUDA-graph replays with fresh inputs, sizes crossing the window) had no failing call; the TP8 row above comes from the same two-node setup. The op tests above ran on main 2d13d1c. Rebased onto main 78a14ae, after #7861 (gfx1250 Lamport all-gather) changed the same files: the kernel and LamportQ4Ar2s now follow LamportArRms's new all-gather dispatch, module_custom_all_reduce_gfx1250 builds for gfx1250, and black / ruff are clean; the op tests on the new base are pending.

Related: #7937 (lossless Lamport two-shot inside the custom all-reduce window); this route covers the larger messages above it.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8012 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@gbyu-amd
gbyu-amd force-pushed the gyu/gfx1250-q4-lamport-2s branch from 0a5784f to c3b4113 Compare November 16, 2026 06:45
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
#8012 @ c3b4113, head 2026-11-16T06:45:00Z)

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

(cherry picked from commit 1bb791e)

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant