Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
0a5784f to
c3b4113
Compare
#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.
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=8picks INT8 instead: 14 elements a line (0.57x the bytes, error ~1/254 of the group max).tensor_model_parallel_all_reduce/CudaCommunicator.all_reducetake it for bf16 inputs ofAITER_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:
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:
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.
Graph-safe state.
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):
Test
op_tests/multigpu_tests/test_custom_allreduce_q4.py -t 2 4 [--codec 8]covers: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_reducewith 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 andLamportQ4Ar2snow followLamportArRms's new all-gather dispatch,module_custom_all_reduce_gfx1250builds 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.