Repository navigation
[FlyDSL] QuickAllReduce INT4: faster poll and codec, kernel-arg peers, gfx950 engine plans - #7093
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
48ed980 to
eefe455
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The codec test checks only a quarter of fp16 bit patterns, allowing untouched zeroed outputs to pass, and lacks architecture guards for both standalone and pytest execution.
2 open issues
What changed in this PR
This PR aims to reduce FlyDSL QuickAllReduceInt4 latency while preserving bitwise results, combining shared protocol and codec optimizations with gfx950-specific engine plans.
Changes:
- Reworks flag polling, codec arithmetic, peer-pointer arguments, and epoch storage for plain and fused paths.
- Adds configurable workgroup geometry and payload-based engine selection for plain all-reduce; fused RMSNorm retains default geometry.
- Adds a single-GPU test intended to exhaustively compare optimized and original codec operations.
| File | Description |
|---|---|
op_tests/test_flydsl_quick_allreduce_int4_codec.py |
Adds scale and INT4 rounding equivalence checks. |
aiter/ops/flydsl/quick_allreduce_int4.py |
Adds engine plans, payload-based dispatch, and revised peer/epoch handling. |
aiter/ops/flydsl/kernels/quick_allreduce_int4.py |
Optimizes polling and quantization and supports configurable tile and thread geometry. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The codec test exercises only 16,384 of 65,536 fp16 patterns, leaving untested outputs to pass as zeros, and lacks the required GPU architecture gate before kernel launches.
4 open issues
This launch covers only 16,384 fp16 patterns: 8 blocks × 256 threads × 8 values per thread. It… · New The entry point launches the codec kernels even on GPUs outside QuickAllReduceInt4's gfx942/gfx950… · New Gate codec kernels to supported gfx942 and gfx950 architectures Launch enough blocks to cover the full 16-bit input domain
Review effort: Balanced
TennyWang1223
left a comment
There was a problem hiding this comment.
Review: #7093 — QuickAllReduce INT4 faster poll/codec + gfx950 engine plans
Verdict: Not ready to approve. The kernel logic looks correct, but the PR is based on an old main and doesn't apply to the current one. It needs a re-port, not just a conflict fix.
Blocking
- Stale base, real conflicts [verified]
- Since this PR's base (
48295fab6), main has merged two changes that overlap it: git merge-treereports a modify/delete conflict on the kernel file and a content conflict in the host wrapper.- The new test imports
aiter.ops.flydsl.kernels.quick_allreduce_int4, which no longer exists on main → ImportError. DEFAULT_ENGINE_PLANSoverlaps main'sblock/tile_atomsknobs andallreduce_policy.
- Since this PR's base (
- Codec equivalence proof no longer holds [verified]
_encode_scaleassumes E4M3 with a fixed-0.125step, and the exhaustive test covers only E4M3 bytes.- Main computes
d = _e4m3_to_f32(e) * codec.dec_stepover E5M2 bytes and clamps the encode scale to ±FP16_MAX (comm/quick_allreduce_codec.py:521-528). - The
w + 1032magic and the0xFmask are INT4-only. INT6 needs different constants. - The 3612/3612 bit-exact checks and all benchmarks compare against the old base.
Should fix
- Memory ordering after removing
buffer_inv- [verified] Payload reads now rely on NT loads to miss the CU cache. Main's own docs (
comm/allreduce_shared.py:470-474) say NT "does not stop the load being answered from the reader's own L1/L2", and main usessc0|sc1for uncached-inbox reads. - [inferred] If a stale packet were read, the result would be silently wrong output, not a hang.
- [verified] The change is not arch-gated, but gfx942 was only compile-tested.
- Please justify NT or switch to
sc0|sc1, and run multi-GPU tests on MI300X.
- [verified] Payload reads now rely on NT loads to miss the CU cache. Main's own docs (
- CI coverage gap [verified]
Multi-GPU Tests (8 GPU)was skipped. The only new code CI exercised was the single-GPU codec test, run against the old base.
Notes
- Unsynchronized colors init [inferred]
colors = torch.ones(...)is async on the current stream (it was a synchronoushipMemcpybefore), and__init__never synchronizes.- A first launch on another non-blocking stream could read uninitialized epochs and hang.
- Add a stream sync at the end of
__init__.
engine_plannot checked across ranks [verified]- Ranks with different plans will hang, either in the constructor's collectives or at runtime.
- Consider an
all_gathercheck in the constructor.
|
@aiter-bot review |
|
aiter-bot — queued behind 7 review(s); expect to start in about 3.5 h. The box reviews one PR at a time. |
@zufayu — please take a look. Re-comment |
5bcb579 to
3593ead
Compare
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 |
…ice-memory colours Port of ROCm#7093 onto the post-ROCm#5555 quick all-reduce (mesh/ring kernels in kernels/comm). Output is bit-identical to before. * Codec: the quantizer rounds with the fp16 magic number w + (1024 + bias), masked to the code width, instead of roundeven + cvt_i16 + bias, for INT4, INT5 and INT6. In [1024, 2048) the fp16 ulp is 1 and 1024 + bias is even, so the add rounds half to even exactly like roundeven. op_tests/test_flydsl_quick_allreduce_quant.py checks every fp16 input of every codec against torch (and times the old form). * Mesh and ring take the inbox bases as kernel arguments (peer0..peer7), so the prologue no longer starts with an uncached peer-table load. * The per-block colours of mesh/ring engines live in ordinary device memory (allocated and synchronized at engine construction), since only the owning GPU reads or writes them. The one-shot is unchanged. Not ported from ROCm#7093: * the flag poll and inbox-load cache policy: already covered upstream by transport._load_flag (system-scope atomic poll, no buffer_inv) and the sc0 sc1 recv policy; * the v_rcp_f32 encode scale: bit-identical, but 3-6% slower on some fused all-reduce + RMSNorm shapes on gfx950 and no faster on the plain kernel; * the gfx950 512-thread / 16 KiB-tile engine plans: upstream tunes the geometry through its own block knob and ladders. Co-Authored-By: Claude <[email protected]>
The decode-size half of ROCm#7093's engine plans, expressed with the existing geometry knob instead of a new kernel geometry: below 2 MiB a 64-thread block (4 KiB tile) spreads a payload over 4x the workgroups of block 256, each with a quarter of the tile. From 2 MiB on the existing rungs stay. Measured on MI355X (ROCm 10.2, hidden 4096, graph of 10 calls, mean of two runs) against upstream: TP2 -6..-16%, TP4 -8..-12%, TP8 -6..-10% from 8 KiB to 1 MiB; no shape slower by more than 1% (255 shapes, TP2/4/8). A sweep of block x super_tile x grid_cap found nothing better from 4 MiB on. A different block changes which rank owns which chunk, so outputs below 2 MiB are statistically equivalent to, not bit-identical with, the block 256 rung; the verify's SQNR checks pass. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The block-width changes alter which rank’s contribution remains unquantized for sub-2 MiB gfx950 xGMI reductions, violating the bitwise-equality contract.
5 open issues
Block width changes which rank contribution remains unquantized · New The entry point launches the codec kernels even on GPUs outside QuickAllReduceInt4's gfx942/gfx950… This launch covers only 16,384 fp16 patterns: 8 blocks × 256 threads × 8 values per thread. It… Gate codec kernels to supported gfx942 and gfx950 architectures Launch enough blocks to cover the full 16-bit input domain
Review effort: Balanced
Hi @TennyWang1223, thanks for the review. I've rebased the branch, so many things are updated or disappeared. Please take a look one more time |
…ice-memory colours Port of ROCm#7093 onto the post-ROCm#5555 quick all-reduce (mesh/ring kernels in kernels/comm). Output is bit-identical to before. * Codec: the quantizer rounds with the fp16 magic number w + (1024 + bias), masked to the code width, instead of roundeven + cvt_i16 + bias, for INT4, INT5 and INT6. In [1024, 2048) the fp16 ulp is 1 and 1024 + bias is even, so the add rounds half to even exactly like roundeven. op_tests/test_flydsl_quick_allreduce_quant.py checks every fp16 input of every codec against torch (and times the old form). * Mesh and ring take the inbox bases as kernel arguments (peer0..peer7), so the prologue no longer starts with an uncached peer-table load. * The per-block colours of mesh/ring engines live in ordinary device memory (allocated and synchronized at engine construction), since only the owning GPU reads or writes them. The one-shot is unchanged. Not ported from ROCm#7093: * the flag poll and inbox-load cache policy: already covered upstream by transport._load_flag (system-scope atomic poll, no buffer_inv) and the sc0 sc1 recv policy; * the v_rcp_f32 encode scale: bit-identical, but 3-6% slower on some fused all-reduce + RMSNorm shapes on gfx950 and no faster on the plain kernel; * the gfx950 512-thread / 16 KiB-tile engine plans: upstream tunes the geometry through its own block knob and ladders. Co-Authored-By: Claude <[email protected]>
The decode-size half of ROCm#7093's engine plans, expressed with the existing geometry knob instead of a new kernel geometry: below 2 MiB a 64-thread block (4 KiB tile) spreads a payload over 4x the workgroups of block 256, each with a quarter of the tile. From 2 MiB on the existing rungs stay. Measured on MI355X (ROCm 10.2, hidden 4096, graph of 10 calls, mean of two runs) against upstream: TP2 -6..-16%, TP4 -8..-12%, TP8 -6..-10% from 8 KiB to 1 MiB; no shape slower by more than 1% (255 shapes, TP2/4/8). A sweep of block x super_tile x grid_cap found nothing better from 4 MiB on. A different block changes which rank owns which chunk, so outputs below 2 MiB are statistically equivalent to, not bit-identical with, the block 256 rung; the verify's SQNR checks pass. Co-Authored-By: Claude <[email protected]>
3593ead to
02d5c1b
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Shared mesh/ring peer-addressing and epoch-storage changes need human review because gfx942 hardware validation is outstanding and GPU ordering and cross-launch epoch visibility could not be verified here.
No open issues 🎉
5 resolved since last review
Block width changes which rank contribution remains unquantized The entry point launches the codec kernels even on GPUs outside QuickAllReduceInt4's gfx942/gfx950… This launch covers only 16,384 fp16 patterns: 8 blocks × 256 threads × 8 values per thread. It… Gate codec kernels to supported gfx942 and gfx950 architectures Launch enough blocks to cover the full 16-bit input domain
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Shared epoch-caching and peer-address changes require human review because they affect gfx942, while reported hardware validation covers only gfx950 on a different stack, leaving gfx942 multi-GPU correctness and graph replay on the pinned stack unverified.
No open issues 🎉
Review effort: Balanced
|
@TennyWang1223 thank you for launching CI! It has successfully finished |
#7093 passes the mesh inboxes as eight kernel arguments instead of a device pointer table, so the relay's two bounce pointers, which were appended to that table, no longer reached the kernel. _StEngine.peer_args now puts extra_ptrs in the slots after the TP ranks, and the relay blocks read their bounces from peer_args[world_size] and [world_size + 1]. Co-authored-by: Cursor <[email protected]> Signed-off-by: Mikko Tukiainen <[email protected]>
…because main's kernel-arg peers (#7093) removed peer_vec and the auto-merged helpers/help_bal/help_pair code would fail to trace (ruff F821). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…list, because main's kernel-arg peers (#7093) shifted the mesh launcher's arguments by seven and the hard-coded slot 12 overwrote a peer pointer (illegal address at M=4096; with the fix the fused arm is back at err 0.1539, 603 us). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…to the PR branch, because CI checks the PR merged with main and main's kernel-arg peers change (#7093) removed peer_vec, which made Ruff fail with F821 in quick_allreduce_mesh.py. Re-formatted with black and re-marked with ruff 0.16.0 on the merged tree (both clean repo-wide). GPU check on the merged tree, TP8 eager mini-e2e M=4096 nvb 8: INT4 fused 606.6 us err 0.1539, exact fused 633.9 us err 0.0156 (before: 602 / 627-631 us, same errors). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves the conflicts with #7093 (kernel-arg peers, device-memory colours, magic-number codec rounding, gfx950/xGMI block-64 mesh rung) and #8574 (fused-only "pull" schedule): * mesh/ring take main's peer0..peer7 kernel arguments and device_colors; the Lamport mesh code uses main's self_inbox. * The hier kernel moves to peer0..peer7 too, to match the host's shared launch arguments. * "hier" and "pull" coexist in ALGORITHMS, _TWO_SHOT_CODECS and FamilyPolicy; both test blocks are kept. * The gfx950/xGMI MESH_ST_LADDER keeps this branch's Lamport rungs in place of #7093's block-64 flag rungs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>


Purpose
Lower the latency of the FlyDSL quick all-reduce (
FlyQuickAllReduce/QuickAllReduceInt4, mesh schedule) on gfx950, mostly at decode sizes. The kernel changes keep the output bitwise equal tomain. The changes come in two commits.1. Kernel: rounding, peers, colours (mesh and ring, all codecs, all archs; also speeds up
FlyQuickAllReduceRMSNorm):Magic-number rounding. The quantizer rounds with the fp16 magic number
w + (1024 + bias), masked to the code width, instead ofroundeven+cvt_i16+ bias:0x000F000F0x001F001F0x003F003FAfter the clamp,
w + 1024 + biaslies in [1024, 2048). There the fp16 ulp is 1, and1024 + biasis even, so the add rounds half to even exactly likeroundeven. It leavesroundeven(w) + biasin the low mantissa bits. The result is bit-identical over the whole input domain (see the new op test below), with nov_rndne_f16/v_cvt_i16_f16left in the kernel.Peers as kernel arguments. The mesh and ring kernels take the inbox bases as kernel arguments (
peer0..peer7) instead of loading the device-side peer table. The bases reach the wave in SGPRs, so the prologue no longer starts with the uncached table load that every inbox address depends on. The mesh's own inbox is a trace-time pick (peers[self_rank]).Colours in device memory. The per-block colours (epochs) of mesh and ring engines live in an ordinary device tensor instead of the uncached metadata block. Only the owning rank's kernel reads or writes them. Within a launch, block
bidreads its slot once at the start and writes it once at the end. Across launches, the kernel-boundary release/acquire orders them. The tensor is allocated eagerly at engine construction, never lazily, so a first call inside graph capture cannot capture the fill. A device synchronize follows the allocation, so a launch on any stream sees the initialized epochs. The one-shot keeps its uncached block.2. Policy: block-64 mesh rung below 2 MiB on gfx950 xGMI. In
MESH_ST_LADDER, each of TP2/TP4/TP8 gets ablock=64(4 KiB tile) ST=1 rung below 2 MiB. Below 2 MiB, block 64 spreads a payload over 4× the workgroups of block 256, each with a quarter of the tile. From 2 MiB on, the existing rungs are unchanged:The rung comes from a sweep of
block ∈ {64, 128, 256, 512} × super_tile ∈ {1, 8} × grid_cap ∈ {256, 512, 1024}at TP2/4/8:The rung changes which rank owns which chunk, so outputs below 2 MiB are statistically equivalent to block 256, not bit-identical (SQNR checks below). The fused ladders are untouched. Production dispatch sends payloads to the mesh from 512 KiB (TP2) or 384 KiB (TP4/8) (
quantized_floor), so there the rung serves 384 KiB–2 MiB.QuickAllReduceInt4(min_bytes=0) uses it for every payload below 2 MiB.Not changed: the flag poll (
transport._load_flag, system-scopesc0 sc1, no fence in the spin) and the inbox load policy (sc0 sc1on the uncached inbox) stay as they are onmain.Test Result
MI355X (gfx950, 256 CUs, 8 GPUs, xGMI), ROCm 10.2, torch 2.15, FlyDSL 0.5.0, bf16.
mainisce334d015.Method:
torch.profiler, each replay behind an NCCL barrier.mainand the PR run in separate processes, alternating order, with the GPUs checked idle before every step.Plain all-reduce (
QuickAllReduceInt4, mesh INT4), µs per call, main → PR (both commits)Fused
FlyQuickAllReduceRMSNorm(mesh), hidden 4096, µs per call, main → PREach cell is
allreduce_rmsnorm/allreduce_rmsnorm_mxfp4.Correctness
main(commit 1): every output, on every rank, compared by checksum on all 623 benchmark shapes (plain,allreduce_rmsnormandallreduce_rmsnorm_mxfp4outputs including the fp4 values and e8m0 scales).How to run the tests
Results on MI355X:
op_tests/test_flydsl_quick_allreduce_quant.py(24 rows: int4/int5/int6 × all-fp16/randn × 64 Ki/16 Mi elements × 2 encode factors)err = 0for both candidates in every rowop_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.pyop_tests/multigpu_tests/test_flydsl_quick_allreduce.pyop_tests/multigpu_tests/test_flydsl_quick_allreduce.py --extended -a meshPR Self-Review
Reviewed revision
02d5c1b
Behavior and intent
Commit 1 (kernel) changes no outputs, only how the quick all-reduce computes them. Three costs on
mainare avoidable:roundeven+cvt_i16(64v_rndne_f16+ 64v_cvt_i16_f16per mesh kernel).The commit replaces the rounding with an exact fp16 magic-number add, passes the peer bases as kernel arguments, and moves the colours to ordinary device memory. Output is bitwise equal to
main.Commit 2 (policy) changes which geometry the gfx950/xGMI mesh uses below 2 MiB.
mainruns block 256 there, which gives a decode-size payload few workgroups; block 64 is 3–12% faster (sweep in the description above).This does change rounding below 2 MiB.
blockdecides which rank's share skips one quantization, so individual elements can round differently. SQNR is unchanged (+-0.03 dB on the verify shapes), ranks still agree bit for bit, and results are deterministic.mainalready has the same property where its ladders switch block: gfx942/xGMI and gfx950/PCIe 256 -> 512, and fused block =hidden / 8.Validation and unverified scope
Validated on 8× MI355X (gfx950, xGMI), ROCm 10.2, torch 2.15, FlyDSL 0.5.0, against
maince334d015:python3 op_tests/test_flydsl_quick_allreduce_quant.pyerr = 0. Fails with an off-by-one magic constant (99.99% of codes differ).python3 -m pytest -q op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.pypython3 op_tests/multigpu_tests/test_flydsl_quick_allreduce.pypython3 op_tests/multigpu_tests/test_flydsl_quick_allreduce.py --extended -a meshsqnr_db,min_tile_sqnr_db,lanes_differing) is identical tomainfor commit 1. That is 162 cells in the default run and 419 in--extended -a mesh, including INT5/INT6.mainby checksum of every output on every rank, on 623 shapes. Those cover the plain,allreduce_rmsnormandallreduce_rmsnorm_mxfp4paths, hidden 1024–8192, tokens 1–65536 and TP2/4/8. With commit 2, all shapes >= 2 MiB stay bit-exact.torch.profiler, mean of two runs, GPUs checked idle before every step.v_rndne_f16/v_cvt_i16_f16(was 64/64); no peer-table load in the prologue; VGPRs 143 -> 139; no scratch.Not verified:
ci:multi-gpu+ci:mi300xlabels or a manual run.mainwas shown only through identical verify accuracy cells, not by output checksums.--extended(both algorithms) fails on gfx950/xGMI withNoPolicyError: no ring ladder for gfx950/xgmi/TP8. It fails identically onmain(no gfx950/xGMI ring ladder), so it is pre-existing.PR-specific question
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?
op_tests/test_flydsl_quick_allreduce_quant.pyis new. Commit 1 is meant to preserve behavior, so onmainthe test passes; itsflydsl_roundevencandidate ismain's rounding. It fails on any rounding that is not exactly round-half-to-even of the clamped product. That covers an off-by-one magic constant (99.99% of codes differ), ties rounded away from zero, a wrong code mask for INT5/INT6, NaN/inf handling that differs frommaxnumf+ clamp, and words the kernel never writes (−1 sentinel).The existing codec suite (
op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py) cannot catch these:|err| <= |ext| * (1/8 + 1.05/bias), which already allows half a code of rounding error. A tie resolved the wrong way has exactly that error and passes.None of them compares individual codes against an exact reference over every fp16 input.
Changed op tests
op_tests/test_flydsl_quick_allreduce_quant.py(new)._quant_atom_fp16, INT4/INT5/INT6), code by code, against a torch reference (torch.roundhalf-to-even). Inputs are every fp16 bit pattern (all_fp16, 32 blocks for 65,536 values) and a normal fill, at two encode factors, withrtol = atol = 0.roundevenform it replaced.main().op_tests/file changed.Submission Checklist
op_tests/test_flydsl_quick_allreduce_quant.py).mainon gfx950, TP2/TP4/TP8, plain and fused (incl. MXFP4) paths. Commit 2 changes only the rung below 2 MiB; SQNR checks pass.--extended -a meshrun on MI355X and pass.