Skip to content

[FlyDSL] Fuse add-RMSNorm and MXFP4 quant into INT4 QuickReduce - #6369

Merged
vgokhale merged 5 commits into
ROCm:mainfrom
mjkvaak-amd:flydsl/qr-int4-rmsnorm
Oct 19, 2026
Merged

vgokhale merged 5 commits into
ROCm:mainfrom
mjkvaak-amd:flydsl/qr-int4-rmsnorm

Conversation

@mjkvaak-amd

@mjkvaak-amd mjkvaak-amd commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

In tensor-parallel decoder layers, all-reduce is typically followed by a residual add and an RMSNorm. On MXFP4 checkpoints, the normed activation is then quantized to MXFP4 for the next GEMM. AITER already fuses the add + RMSNorm (and, at decode, the MXFP4 quant) into the HIP custom all-reduce. The FlyDSL INT4 QuickReduce added in #4970 doesn't yet have these epilogues, though. Serving stacks that use it for prefill-sized all-reduces have to pick one:

  • keep the AR + RMSNorm fusion and fall back to HIP QuickReduce, or
  • use FlyDSL QuickReduce and run the add + RMSNorm and the MXFP4 quant as separate launches.

This PR adds both epilogues to the FlyDSL kernel. vLLM uses them in vllm-project/vllm#61021 (AR + RMSNorm) and vllm-project/vllm#61020 (AR + RMSNorm + MXFP4).

Technical Details

QuickAllReduceInt4 gets two entry points:

  • allreduce_rmsnorm(inp, residual, weight, eps, out, residual_out, *, gemma_norm=False)
    • Computes residual_out = allreduce(inp) + residual and out = rmsnorm(residual_out) * w, where w is weight, or 1 + weight with gemma_norm.
    • residual_out may alias residual.
    • Hidden sizes 2048, 4096, 8192 and 16384; supports_rmsnorm(hidden, nbytes) tells callers whether a shape is covered.
  • allreduce_rmsnorm_mxfp4(..., mxfp4_out, mxfp4_scale, *, gemma_norm=False), gfx950 only (supports_mxfp4)
    • Also writes the packed FP4 activation and its e8m0 scales.
    • The scales use the shuffled layout gemm_a4w4 and the preshuffled GEMMs read; mxfp4_scale_shape(rows, hidden) gives the padded buffer shape.
    • The output is bit for bit what per_1x32_f4_quant_hip(out, shuffle=True) returns.

The epilogue runs in the all-gather phase of the two-shot kernel, after each tile of the reduced sum is complete:

  • Pass 1 accumulates the per-row sum of squares in fp32 across waves through LDS.
  • Pass 2 re-reads the tile, then writes residual_out and out.
  • MXFP4 epilogue (in pass 2):
    • takes each 32-element group's amax over the 4 lanes that hold it, with two shuffle_xor;
    • derives the e8m0 scale with the same RoundUp rule as AITER's quant;
    • packs the FP4 values with cvt_scalef32_pk_fp4_bf16;
    • stores the shuffled scale bytes. The lane-dependent part of the scale offset sits in a VGPR; the row and atom parts go in soffset.

The fused launches are compiled and cached per hidden size, epsilon, gemma_norm and mxfp4, plus a latency variant for small payloads. The plain allreduce kernel is unchanged.

Test Plan

op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py (new) initializes each rank once and runs every case in that process. It covers 11 shapes (1–16384 tokens, hidden 2048–16384, plain and Gemma norm, in place and out of place) and checks:

  • fp32 reference: SQNR against an fp32 NCCL all-reduce followed by fp32 add + RMSNorm. The INT4 codec is lossy, so this is a tolerance check.
  • unfused FlyDSL path: agreement with QuickAllReduceInt4.allreduce followed by an fp32 add + RMSNorm, at bf16-level tolerance (rtol = atol = 2e-2, at most 1% of elements outside). The only difference is the bf16 rounding of the reduced sum, which the fused kernel skips.
  • ranks: out and residual_out are bitwise equal across ranks.
  • MXFP4, gfx950: allreduce_rmsnorm_mxfp4 returns the same out and residual_out bit for bit, and its FP4 bytes and live scale bytes equal per_1x32_f4_quant_hip(out, shuffle=True).

The bench sweep times the fused paths against FlyDSL allreduce + rmsnorm2d_fwd_with_add (+ per_1x32_f4_quant_hip).

python3 op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py --tp 8
python3 op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py --tp 4
python3 op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py --tp 2

Hardware: 8× MI355X (gfx950); 8× MI300X (gfx942) for the plain fused path (last section of Test Result).

Test Result

Correctness: all 11 cases pass at TP 2, 4 and 8. Against the unfused FlyDSL path, no element of out or residual_out falls outside the bf16 tolerance in any case. out and residual_out are equal across ranks, and the MXFP4 output is bitwise equal to per_1x32_f4_quant_hip. SQNR against the fp32 reference is ~36.1 dB at TP2, ~33.3 dB at TP4 and ~30.5 dB at TP8.

Kernel time, TP8 (µs; unfused = FlyDSL all-reduce + rmsnorm2d_fwd_with_add, + per_1x32_f4_quant_hip for MXFP4):

tokens × hidden AR+RMSNorm fused unfused speedup AR+RMSNorm+MXFP4 fused unfused speedup
2048 × 8192 113.0 121.4 1.08× 116.4 129.4 1.11×
8192 × 8192 308.9 327.7 1.06× 326.6 354.5 1.09×
16384 × 8192 575.5 614.2 1.07× 601.3 679.2 1.13×
16384 × 4096 300.7 327.5 1.09× 317.4 355.0 1.12×

Kernel time, TP4:

tokens × hidden AR+RMSNorm fused unfused speedup AR+RMSNorm+MXFP4 fused unfused speedup
256 × 8192 41.9 42.4 1.01× 44.3 52.5 1.18×
1024 × 8192 81.6 91.8 1.12× 84.8 94.9 1.12×
2048 × 8192 138.9 149.6 1.08× 142.2 155.4 1.09×
8192 × 8192 459.8 488.5 1.06× 476.0 515.3 1.08×
16384 × 8192 881.2 945.6 1.07× 914.2 1007.6 1.10×

Serving: amd/Qwen3.8-2.4T-A95B-Quark-MXFP4, TP8 on MI355X, vLLM with FlyDSL INT4 QuickReduce. Each arm started from empty vLLM, AITER and Triton caches and ran a 12-point random-dataset sweep: ISL 8k/60k/128k, OSL 600–1024, concurrency 4–256. Compared with FlyDSL QuickReduce without any fusion:

output throughput (geomean) mean TTFT (geomean) mean TPOT (geomean) GPQA
no fusion — — — 0.919
allreduce_rmsnorm +4.4% −7.2% −4.1% 0.924
allreduce_rmsnorm_mxfp4 +5.3% −8.7% −4.7% 0.909

Every one of the 12 points improves with either entry point. The GPQA spread is within run-to-run noise for its 198 questions.

gfx942 (8× MI300X, FlyDSL 0.3.4.1): all 11 cases pass at TP 2, 4 and 8. No element of out or residual_out falls outside the bf16 tolerance against the unfused FlyDSL path, the ranks are bitwise equal, and SQNR against the fp32 reference is 36.1 / 33.3 / 30.5 dB at TP2 / 4 / 8. Run on main 159c1ef97 plus this commit, in the vLLM ROCm nightly with its aiter/ops/flydsl replaced by this tree; no later main commit touches aiter/ops/flydsl.

Kernel time, gfx942 (µs, fused / unfused, speedup; lower is better):

tokens × hidden TP2 TP4 TP8
256 × 8192 57.5 / 57.5 (1.00×) 47.9 / 49.3 (1.03×)
2048 × 8192 266.6 / 281.4 (1.06×) 173.2 / 178.7 (1.03×) 133.1 / 137.5 (1.03×)
8192 × 8192 956.6 / 1027.4 (1.07×) 599.1 / 646.6 (1.08×) 453.8 / 485.7 (1.07×)
16384 × 8192 1870.7 / 1980.0 (1.06×) 1147.3 / 1215.5 (1.06×) 859.6 / 915.8 (1.07×)
16384 × 4096 957.5 / 1033.8 (1.08×) 601.6 / 651.8 (1.08×) 470.4 / 491.9 (1.05×)

At TP8, 2048 × 8192 gains 1.03× against 1.08× on gfx950, and 256 × 8192 at TP2 is flat; waves_per_eu and NORM_GROUP were tuned on gfx950 only. allreduce_rmsnorm_mxfp4 raises on gfx942 and its test case is skipped there.

Submission Checklist

@mjkvaak-amd
mjkvaak-amd requested review from a team and samremes October 10, 2026 08:38
@github-actions

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: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 6369 --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.

@zufayu

zufayu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 1 review(s); expect to start in about 50 min. The box reviews one PR at a time.

@aiter-bot

Copy link
Copy Markdown

[ROCm/aiter] PR #6369 — [FlyDSL] Fuse add-RMSNorm and MXFP4 quant into INT4 QuickReduce

Fuses the residual add, RMSNorm and (on gfx950) the MXFP4 quantization into the all-gather phase of the FlyDSL INT4 two-shot all-reduce kernel, adding allreduce_rmsnorm / allreduce_rmsnorm_mxfp4 entry points to QuickAllReduceInt4.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — triage required the PR's one test target (op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py) but the run could not happen: auto-validation is disabled (REVIEW_AUTO_VALIDATE=0) and this review environment has no /dev/kfd GPU access (torch sees no GPUs), so the multi-GPU target could not execute — an environment gap, not a PR defect
Perf (advisory): NOT RUN — the target ships a bench harness (--bench with run_perftest) but the same environment gap (no GPU access from this box, REVIEW_AUTO_VALIDATE=0) blocked any base-vs-head timing; the PR's speedups are measured against its own unfused baseline, not base-vs-head of this tree

⚠️ [verified] The patch no longer applies to merge target 6ec72c5 — main's #6377 (e0ba675, Oct 12) refactored aiter/ops/flydsl/kernels/quick_allreduce_int4.py onto typed pointer APIs, dropping the from flydsl._mlir import ir import this PR's hunk context still carries and rewriting buffer_ops internals, so every CI result on the PR describes a tree that has moved and the fused epilogue has never been compiled against the refactored buffer_ops. Author must rebase onto current main and re-run the test suite before merge.
⚠️ [verified] The PR's only test, op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py, is a main() script pytest collects nothing from (the sibling test_flydsl_quick_allreduce_int4.py also defines a collectable test_quick_allreduce_int4), and the multigpu directory runs only under the opt-in ci:multi-gpu label — so a merge without that label ships a new numerical kernel with zero automated coverage. Author must run the ci:multi-gpu label job (or add a pytest-collectable case) before merge.
⚠️ [verified] aiter/ops/flydsl/quick_allreduce_int4.py leaves the arch gate at gfx942+gfx950, so allreduce_rmsnorm stays reachable on gfx942 (MI300X), but every reported result is 8× MI355X (gfx950) — the rocdl.waves_per_eu occupancy pinning and the NORM_GROUP tuning were measured on gfx950 only, so gfx942 behavior is unconfirmed. Author must run the test on gfx942 or gate the fused path to gfx950 until then.

@zufayu

zufayu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Where that review came from — I ran the bot on your PR to show what it does. It is not an automatic hook; nothing reviews your PR unless somebody asks.

Any reviewer on the aiter allowlist can ask for one, on any PR including their own. The trigger is a comment containing the words below — shown quoted here, because quoted lines deliberately do not trigger it:

@aiter-bot review

  • Reviews the PR at its current head. Comment again after pushing fixes for a fresh pass; a repeat on the same commit is deduped.
  • One review runs at a time on one box, roughly 20 minutes. If work is ahead of you the bot replies with your place in the queue, and if the runner is down it says so rather than leaving you waiting for a review that will never start.
  • The card is advisory. It never blocks a merge, 🔴 included — it is there to be argued with.

Feedback on the review itself is welcome; it is how the rules get better.

Add an add-RMSNorm epilogue to the FlyDSL INT4 QuickReduce kernel, so the
all-reduce, residual add and RMSNorm that sit between tensor-parallel layers
run as one launch: allreduce_rmsnorm() writes the normed output and the
updated residual. Gemma-style (1 + weight) norms are supported.

On gfx950 the same epilogue can also quantize the normed output to MXFP4:
allreduce_rmsnorm_mxfp4() additionally writes the packed FP4 activation and
its e8m0 scales in the shuffled layout gemm_a4w4 reads, bitwise equal to
per_1x32_f4_quant_hip(out, shuffle=True). That removes the separate quant
launch in front of the next MXFP4 GEMM.

op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py checks
both entry points against the unfused sequence and benchmarks them.

Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd
mjkvaak-amd force-pushed the flydsl/qr-int4-rmsnorm branch from fa4a01a to 82f1f54 Compare October 13, 2026 18:52
@mjkvaak-amd

mjkvaak-amd commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Replying to the aiter-bot review:

  1. Rebase: done in 82f1f5407, onto main 57e2c6b42 with no conflicts. The fused kernels compile against [FlyDSL] Update skills and clean up codes about typed memory and pointer APIs in communication kernels #6377's buffer_ops: I ran the new test on gfx942 against main 159c1ef97 plus this commit, and no later main commit touches aiter/ops/flydsl.
  2. Test coverage: aiter_test.sh runs every file in op_tests/multigpu_tests as python3 <file> under ci:multi-gpu, so this test runs there as a script and needs no pytest case (test_flydsl_quick_allreduce_int4.py sets __test__ = False as well). I also added ci:multi-gpu.
  3. gfx942: all 11 cases pass at TP 2, 4 and 8 on 8× MI300X, and the fused path is 1.00–1.08× faster than unfused. The arch gate stays. allreduce_rmsnorm_mxfp4 raises on gfx942 and its test is skipped there. Tables are now added in the PR body.

@mjkvaak-amd mjkvaak-amd added the ci:multi-gpu Trigger multi-GPU op tests on PR label Oct 13, 2026
@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

[ROCm/aiter] PR #6369 — [FlyDSL] Fuse add-RMSNorm and MXFP4 quant into INT4 QuickReduce

Fuses the residual add, RMSNorm and (on gfx950) the MXFP4 quantization into the all-gather phase of the FlyDSL INT4 two-shot all-reduce, adding allreduce_rmsnorm and allreduce_rmsnorm_mxfp4 entry points to QuickAllReduceInt4.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — triage required the PR's one test target (op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py) but the run could not happen: auto-validation is disabled (REVIEW_AUTO_VALIDATE=0) and this review account has no GPU access (/dev/kfd is root:render and no torch environment is present) — an environment gap, not a PR defect
Perf (advisory): NOT RUN — the target ships a bench harness (--bench via run_perftest) but the same environment gap (REVIEW_AUTO_VALIDATE=0, no GPU access) blocked any base-vs-head timing; the PR's fused-vs-unfused tables are measured against its own baseline, not base-vs-head of this tree

⚠️ [verified] aiter/ops/flydsl/quick_allreduce_int4.py:362 — compile() still eager-JITs only the plain ST binaries (it iterates self._by_st and launches eng.launch, never eng.norm_launch), so every fused variant pays its full FlyDSL compile inside the first real allreduce_rmsnorm / allreduce_rmsnorm_mxfp4 call, once per (hidden, eps, gemma_norm, latency, mxfp4) key — and the latency key flips with payload size (num_tiles ≤ 2×CU, line 559), so a serving process hits at least two compiles per hidden size, twice that with MXFP4: a multi-second stall on the first fused all-reduce that compile() cannot pre-warm because its (inp, out, stream) signature does not know the norm parameters. Author must extend compile() (or add a warm-up entry point) to eager-JIT the fused variants, or document that consumers warm them by calling the op with dummy tensors at startup.
📝 [verified] op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py:363 — the bench aggregation does max(r[i]["mxfp4_us"] or 0.0 ...), so on gfx942 (supports_mxfp4 False) both mxfp4 columns collapse to 0.0 and the printed mxfp4_speedup is 0.0/0.0 = nan: cosmetic, no assertion reads it, but the bench table this file prints on gfx942 is unreadable in exactly the columns the PR's gfx950 numbers quote. Author must guard the mxfp4 columns on fly.supports_mxfp4.
📝 [verified] The PR body discloses one TP2 run that hung the GPU while another job shared it, with 15 non-reproducing runs and no identified cause; the ci:multi-gpu label this PR now carries runs op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py on the 8-GPU runner under a 60-minute timeout, so if the hang is contention- or timing-dependent it surfaces as a hung CI job rather than a red test. Reviewer should ask for a green ci:multi-gpu run on this head before merge.

…olumns

compile() only JITs the plain ST engines, so every fused RMSNorm build
compiled inside the first allreduce_rmsnorm call. Add compile_rmsnorm(hidden,
eps, gemma_norm, mxfp4) that launches each selectable build (ST=1 low-latency,
ST=1 pinned, ST=8 pinned) once on a dummy one-row payload. The test warms up
first and asserts no case compiles a build the warm-up missed.

The bench table only builds the mxfp4 columns on gfx950, so gfx942 no longer
prints 0.0 columns and a nan mxfp4_speedup.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author

[ROCm/aiter] PR #6369 — [FlyDSL] Fuse add-RMSNorm and MXFP4 quant into INT4 QuickReduce

Fuses the residual add, RMSNorm and (on gfx950) the MXFP4 quantization into the all-gather phase of the FlyDSL INT4 two-shot all-reduce, adding allreduce_rmsnorm and allreduce_rmsnorm_mxfp4 entry points to QuickAllReduceInt4.

Review (advisory): ⚠️ NEEDS WORK Validation (deterministic): NOT RUN — triage required the PR's one test target (op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py) but the run could not happen: auto-validation is disabled (REVIEW_AUTO_VALIDATE=0) and this review account has no GPU access (/dev/kfd is root:render and no torch environment is present) — an environment gap, not a PR defect Perf (advisory): NOT RUN — the target ships a bench harness (--bench via run_perftest) but the same environment gap (REVIEW_AUTO_VALIDATE=0, no GPU access) blocked any base-vs-head timing; the PR's fused-vs-unfused tables are measured against its own baseline, not base-vs-head of this tree

⚠️ [verified] aiter/ops/flydsl/quick_allreduce_int4.py:362 — compile() still eager-JITs only the plain ST binaries (it iterates self._by_st and launches eng.launch, never eng.norm_launch), so every fused variant pays its full FlyDSL compile inside the first real allreduce_rmsnorm / allreduce_rmsnorm_mxfp4 call, once per (hidden, eps, gemma_norm, latency, mxfp4) key — and the latency key flips with payload size (num_tiles ≤ 2×CU, line 559), so a serving process hits at least two compiles per hidden size, twice that with MXFP4: a multi-second stall on the first fused all-reduce that compile() cannot pre-warm because its (inp, out, stream) signature does not know the norm parameters. Author must extend compile() (or add a warm-up entry point) to eager-JIT the fused variants, or document that consumers warm them by calling the op with dummy tensors at startup. 📝 [verified] op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py:363 — the bench aggregation does max(r[i]["mxfp4_us"] or 0.0 ...), so on gfx942 (supports_mxfp4 False) both mxfp4 columns collapse to 0.0 and the printed mxfp4_speedup is 0.0/0.0 = nan: cosmetic, no assertion reads it, but the bench table this file prints on gfx942 is unreadable in exactly the columns the PR's gfx950 numbers quote. Author must guard the mxfp4 columns on fly.supports_mxfp4. 📝 [verified] The PR body discloses one TP2 run that hung the GPU while another job shared it, with 15 non-reproducing runs and no identified cause; the ci:multi-gpu label this PR now carries runs op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py on the 8-GPU runner under a 60-minute timeout, so if the hang is contention- or timing-dependent it surfaces as a hung CI job rather than a red test. Reviewer should ask for a green ci:multi-gpu run on this head before merge.

  1. Fused-variant warm-up. Added QuickAllReduceInt4.compile_rmsnorm(hidden, eps, *, gemma_norm=False, mxfp4=False, stream=None). On gfx942 (TP2, hidden 8192, cold FlyDSL cache) the first fused calls cost 1672 ms (low-latency build) and 1239 ms (ST=8 build) without it. With it, compile_rmsnorm takes 4.06 s up front and the first calls take 0.3 / 0.1 / 2.0 ms (the 2.0 ms is the real 16384-row run). The test now calls it before the cases and fails if any case adds a fused build to the cache that the warm-up missed (checked: with the warm-up removed, both ranks raise).
  2. Bench table: the mxfp4 columns are only built on gfx950, so gfx942 no longer prints 0.0 columns or a nan mxfp4_speedup.

@zufayu
zufayu requested review from TennyWang1223 and removed request for samremes October 15, 2026 05:45
@zufayu zufayu self-assigned this Oct 15, 2026
@zufayu

zufayu commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

The CI failure is caused by a missing or incompatible MORI CCO installation on the MI350X runner, not by PR #6446; its custom all-reduce tests pass, while the gate only propagates the unrelated comm-fused MoE failure.

@TennyWang1223 TennyWang1223 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.

LGTM, I think this PR can be merged after CI pass

@vgokhale
vgokhale merged commit 3c10d34 into ROCm:main Oct 19, 2026
vpietila-amd added a commit that referenced this pull request Oct 22, 2026
…ed-comm-kernels

Resolve the renames (quick_allreduce_int4 -> mesh/ring/quick_allreduce,
allreduce_shared -> transport) in favor of the epilogue-based design, and
carry #6369's features over to it: Gemma (1 + w) gain as a runtime operand,
and a fused MXFP4 quantization variant of the RMSNorm epilogue (mesh and
ring) exposed as FlyQuickAllReduceRMSNorm.allreduce_rmsnorm_mxfp4. The #6369
test is adapted to the new API. #6369's norm_latency build is not ported.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
vpietila-amd added a commit that referenced this pull request Oct 22, 2026
The mesh RMSNorm epilogue gains a latency option with a prefetch hook that
loads the residual ahead of the exchanges. A ladder rung may select it
(optional latency field, default false), and the host builds it as separate
engines with two resident workgroups per CU. It is correct but slower than the
default build on gfx950 TP8 hidden 2048, so no shipped rung uses it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
vpietila-amd added a commit that referenced this pull request Oct 22, 2026
#6369's low-latency build targeted gfx950 over xGMI; over PCIe it measured
slower than the default build, so the ladder loader rejects a latency rung on
any other link. No shipped rung uses it. Also add --bench-only and a grid cap
override to the fused QuickReduce test, for measuring it on an xGMI box.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
TennyWang1223 pushed a commit that referenced this pull request Nov 17, 2026
* Land INT4 quad-fanout QR in aiter FlyDSL ops with a TP8 correctness test.

* Use layout views for LDS pack and ST inbox without regressing ST=8 wall.

Drop unused wave-join and single-wave fanout compiles; default and test the fp16 codec.

* Stop QR INT4 tests and host from mutating COMPILE_ONLY.

Compile-only and cache warming belong in developer scripts, not pytest or QRInt4QuadFanout.compile.

Co-authored-by: Cursor <[email protected]>

* Model local HBM payload as FlyDSL views; keep remote NT stores explicit.

inttoptr + make_buffer_tensor (nbytes OOB) and BufferCopy128b tiled copies replace the tile/atom/tid arithmetic for local dwordx4 loads and stores. IPC/XGMI fanout stays global_store_dwordx4 nt.

* New QR kernel/host/test files should use aiter MIT + AMD 2026 only; they were not FlyDSL-main originals.

* Drop the quad_fanout variant suffix from the only INT4 QuickReduce pipeline so the public API is QRInt4.

* Default QRInt4 to ST=8 and keep only ST∈{1,8} so the host matches the measured keeper; drop unused codec/force_super/bf16 ALU and qr_int4_mem, compiling via flyc.compile.

Co-authored-by: Cursor <[email protected]>

* Skip color 0 after wrap so it never matches the unset sentinel (HIP QR does the same), and time QRInt4 with run_perftest.

* Compile QRInt4 WORLD∈{2,4,8} via HIP-style kRankAtoms so TP4/TP2 work; WORLD=8 stays kRankAtoms=1.

Co-authored-by: Cursor <[email protected]>

* IPC helper is a FlyDSL copy so keep Apache-2.0 copyright 2025; match aiter vendored dual header.

Co-authored-by: Cursor <[email protected]>

* Replace QR INT4 packed-math inline asm with native FlyDSL f16x2 ops.

gfx942 already lowers vector<2xf16> to v_pk_max/min/mul/add/fma, so the
llvm.inline_asm helpers and f32 absmax round-trip are unnecessary.

* Spell out QR INT4 RS/AG and lower the flag wait as a Python while.

The two-shot NT fanout and last-sector handshake are unchanged; gfx942 SQNR vs fp32 all-reduce still passes at TP 2/4/8.

Co-authored-by: Cursor <[email protected]>

* Reduce torch surface in qrint4 kernel

* Join ST sub-tiles before LDS reuse and tighten QRInt4 host checks.

TP2 ST=8 was packing the next tile into LDS while wave 0 still loaded the previous one. Also match aiter FlyDSL dtype/device checks and stop sorting IPC group ranks.

Co-authored-by: Cursor <[email protected]>

* Assert QRInt4 SQNR on every rank.

Each rank already scored vs its local fp32 NCCL all-reduce. The parent
kept rank 0 only, so a broken all-gather on a non-zero rank could pass.

Co-authored-by: Cursor <[email protected]>

* Apply suggestions from ruff

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Match black wrapping and apply small Copilot host/test guards.

Fail SQNR on NaN or a zero-power reference with error. Drop the NCCL
fallback for Gloo object gather. Reject a rank or world_size that does
not match the process group.

Co-authored-by: Cursor <[email protected]>

* Enable gfx950 FlyDSL QRInt4 with configurable grid cap.

Extend arch support to gfx950, parameterize inbox/launch grid_cap (default
1216 to match HIP QR), and tighten the canonical test bench with --grid-cap
and optional JSON export.

Co-authored-by: Cursor <[email protected]>

* Run black on qr_int4_kernel.py after merging main.

* Reject NCCL and multi-node groups in QRInt4 with explicit errors.

IPC inbox setup needs CPU broadcast_object_list and node-local HIP IPC
handles. Fail fast before allocating buffers, matching QuickAllReduce.

* Shorten QRInt4 process-group rejection messages.

Co-authored-by: Cursor <[email protected]>

* Fix QR INT4 launch safety and validation

Clamp persistent grids to conservative residency limits, harden resource cleanup, and validate lossy collective results across ranks.

Co-authored-by: Cursor <[email protected]>

* Address QR INT4 review feedback

Co-authored-by: samremes <[email protected]>

* Apply Black formatting after merging origin/main.

Fix CI Black failures in qr_int4_kernel.py and test_flydsl_qr_int4.py.

Co-authored-by: Cursor <[email protected]>

* Fix QR INT4 E4M3 boundary encoding

* Reject >32bit offset

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

* Add automatic QRInt4 cleanup

* Avoid QRInt4 AOT import cycle

* Harden QRInt4 validation and test collection

* Fix QR INT4 E4M3 reserved-zero underflow after exponent clamp.

Reserve byte 0x00 for true +0 only after packing so clamped positive scales cannot collapse, and add TP2 fill cases for underflow, overflow, and zero.

Co-authored-by: Cursor <[email protected]>

* Drop duplicate QRInt4 lazy-import key after merging main.

Co-authored-by: Cursor <[email protected]>

* Spawn QRInt4 test ranks instead of re-entering the file with --rank.

Match HIP QR: Pool + spawn, return row dicts, keep argparse on main() only. Drop PYTHONPATH/arch env overrides and out.zero_(); time spawn workers with cuda.Event.

Co-authored-by: Cursor <[email protected]>

* Make QRInt4 test comments self-contained.

State what each threshold, fill, and CLI flag does today, and record why the
spawn ranks must time with cuda events instead of the profiler timer.

Co-authored-by: Cursor <[email protected]>

* Resolve the QRInt4 device index before set_device.

torch.cuda.set_device rejects torch.device("cuda") without an index, so the
current-device fallback in _cuda_index was unreachable. Resolve the index
first, select that integer, and keep self.device as the resolved cuda:N.

Co-authored-by: Cursor <[email protected]>

* Rename FlyDSL QR INT4 to QuickAllReduceInt4 and drop leftover globals/asm.

Move host and IPC out of kernels/, export QuickAllReduceInt4 only, and keep
module constants that actually couple host tile math, LDS, and codec layout.
Use fx.min, llvm.StoreOp(nontemporal=True) for NT fanout, llvm.amdgcn.s.setreg
for FP16_OVFL, and inline readfirstlane at the inbox descriptor.

Leave buffer_inv sc1 as inline asm: the flag poll is a non-atomic sc1
buffer_load (L2 bypass, not L1), so the miss path still needs an L1
invalidate, and llvm.amdgcn.buffer.wbinvl1.sc cannot select on gfx942/gfx950.

* Format QuickAllReduceInt4 host and tests with ruff and black.

* Move FlyDSL QR INT4 tests to multigpu_tests and fix HIP alloc rounding.

Collect the suite with the 8-GPU job instead of single-GPU op_tests.
Round uncached HIP mallocs to 4 KiB so small grid_cap inboxes still
export, and feed MODE setreg through as_ir_value instead of fx.arith.

* [FlyDSL] Extract quick-allreduce transport and codec into shared modules

The ring and one-shot schedules that follow need the same tile geometry,
inbox cache policy, peer store/load primitives and wire codec that the
mesh kernel had inlined. Split them out so all three agree byte for byte
rather than carrying three copies of the same magic numbers:

  quick_allreduce_shared  geometry, _INBOX_POLICY, peer store/load, LDS
  quick_allreduce_codec   INT4/INT6/FP16 wire formats and the E4M3 scale

The mesh kernel becomes codec- and inbox-policy-generic as a result, and
is renamed to match its new module. Two behavioural changes ride along.

Fix the buffer cache-modifier encoding. These are LLVM CPol bits, which
the backend renames for CDNA: bit 0 (GLC) prints as `sc0`, bit 1 (SLC) as
`nt`, bit 4 (SCC) as `sc1`; bit 2 exists in the encoding but CDNA has no
use for it and it emits nothing. The previous values were 4 for "NT" and
2 for "sc1", so the payload load carried no cache hint at all and the
flag spin load got `nt` instead of bypassing L2 -- a spin that can be
answered from a stale line. They are now 2 and `sc0 | sc1`.

Make the flag spin load bypass L1 as well. `sc1` alone only bypasses L2;
`sc0 sc1` is what LLVM emits for a system-scope load and is what lets the
retry loop run without a fence in its body.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Add inbox memory modes, codec selection and an ST ladder to the host

The uncached IPC inbox the host has always allocated is right on xGMI and
catastrophic on PCIe: peer writes into uncached memory serialize per
destination, so throughput collapses as the fanout widens (MI350P, INT4
mesh: 55 GB/s to one peer, 4.45 to two, 1.44 to three, against 33.5
fine-grained). Give the host an `inbox_memory` knob over the kernel's
existing cache-policy table, defaulting to "auto", which reads the real
per-peer link type out of KFD rather than guessing from the arch string
-- MI350X and MI350P both report gfx950 and want opposite answers.

With a cacheable inbox a publish costs an L2 writeback, so the super-tile
that was a fixed constructor argument becomes a payload-size ladder:
`_pick_st` selects a rung, `_grid_x` hands each block a whole super-tile
so the batching is real, and `_MIN_BATCH_BLOCKS` stops it trading the
whole machine away at small sizes (MI350P, 32x7168, TP4: 61.95 us
unbounded against 23.98 with the grid left alone).

Also adds `rs_codec`/`ag_codec` with an AITER_ALL_REDUCE_CODEC override,
`min_bytes` gating with `is_beneficial`, `variant()` for reporting which
binary a size actually runs, and `has_xgmi_peer_links` for the dispatcher.

The IPC heap grows a device check on every allocation. Several
byte-identical copies of libamdhip64 are typically mapped into one
process and they do not share device state, so the first one resolved by
soname can allocate on the wrong GPU -- every peer write then crosses to
the wrong device. Pick the mapped copy that reports torch's bound device,
and assert the allocation landed where it was meant to.

The page rounding hipIpcGetMemHandle needs moves from alloc_uncached to
alloc, which is where the inbox is now allocated from.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Add the ring schedule for quick-allreduce

The mesh writes to every one of the N-1 peers on both laps. On a PCIe
host a GPU has one shared x16 uplink, so those interleaved destinations
contend for it; the ring instead makes every step a single contiguous run
into exactly one peer's inbox. Same wire volume -- 2(N-1)/N of the
payload, which is bandwidth optimal (Patarasuk & Yuan, JPDC 69(2), 2009)
-- traded for per-destination locality, over 2(N-1) hops instead of two.

The ring pays for that in accuracy: its reduce-scatter lap requantizes
the running partial N-1 times where the mesh requantizes once, and the
partial's extremum grows with the contributions folded in. Hence the
per-lap codec knobs -- the reduce-scatter lap widens to INT6 at TP8 to
hold the 18 dB SQNR floor, while the all-gather lap forwards received
bytes untouched and stays INT4.

Registered as algorithm="ring" alongside the mesh, with its own
super-tile set (1, 8, 16, 32) and payload-size ladder. It is not the
default and is structurally worse at decode sizes and on xGMI; the
dispatcher that follows picks between them.

clamp_grid_cap now falls back to the smallest measurement for a world
size when a super-tile is not in the residency table, instead of raising:
the table was measured on the mesh and does not cover ST=16 or ST=32.
Under-launching a persistent kernel is always safe, so the fallback errs
small; an unknown arch or world size still raises.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Add the exact one-shot all-reduce and the schedule policy table

Both quantized schedules are two-shot, so their latency floor is two
serialized fabric traversals plus a grid-wide handshake between the laps.
At decode sizes that floor dominates and the quantization buys nothing --
the collective is not the bottleneck there, and INT4 charges ~36 dB of
SQNR for microseconds.

OneShotAllReduce is the decode-regime answer: one round, no grid-wide
barrier, bf16 in, fp32 accumulate, bf16 out, no codec. Each rank pushes
its whole tile into every peer's inbox, publishes a colour flag, waits
for N flags, then reduces N copies out of its own inbox. That trades wire
volume for round trips -- (N-1)*S pushed against a two-shot's 2(N-1)/N*S
-- so where it stops paying is a function of N, which is what max_bytes
gates on. It needs no LDS: thread t's 16 B lands at the same offset in
every destination, so it pushes straight from registers.

It reuses the IPC inbox, peer table and cache-policy table from the
quantized schedules verbatim, which is what the shared transport module
was extracted for.

allreduce_policy holds the size boundaries between the three families,
per (link, world_size), fitted from measurement. It is a pure table plus
env overrides -- no kernels, no torch -- so the dispatcher and the hosts
can both read it without an import cycle. Accuracy defaults to "exact",
which makes the quantized families unreachable until a caller opts in
with AITER_FLY_AR_ACCURACY=fast.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Dispatch the FlyDSL all-reduce family from CudaCommunicator

FlyDSLAllReduce owns one engine per reachable schedule and routes a
payload to the family allreduce_policy picks for its size, link type and
world size. CudaCommunicator consults it ahead of quick-reduce and custom
all-reduce.

It leads the chain because, at the default AITER_FLY_AR_ACCURACY=exact,
the only reachable family is the exact one-shot -- fp32 accumulate, one
bf16 rounding, comparable with cross_device_reduce rather than quantized
-- and it declines every payload above that ceiling, so the caller falls
through unchanged. AITER_FLY_AR_ACCURACY=fast unlocks the quantized
mesh/ring for larger payloads.

The whole path is opt-in: with AITER_FLY_AR unset the dispatcher
disables itself in its constructor and the chain is exactly as before.
Every unsupported condition -- no flydsl, wrong arch, NCCL group,
multi-node group, unsupported world size -- is an early return that
leaves `disabled` set, and should_fly_all_reduce is a pure predicate that
answers False rather than raising.

A communicator built with reuse_from borrows the engine rather than
owning it, so destroy() only closes the IPC inboxes on the group that
built them.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Add codec, policy and one-shot all-reduce tests

test_flydsl_allreduce_policy is CPU-only: it checks that the family
boundaries partition by size, that the ladders are ascending and reach
every super-tile they name, and that the env overrides apply where the
tables say they do.

test_flydsl_quick_allreduce_codec runs on a single GPU with no IPC, so it
covers the wire formats in isolation from the transport: INT4/INT6/FP16
round-trips, the E4M3 scale at both ends of its range, and the codec
resolution rules.

Two of its cases move with the E4M3 fixes rather than against them. They
were written against an encoder that saturated the exponent field alone,
so 512 encoded as 256 and an outlier decoded *smaller* than the ceiling
it passed; and against one where a positive extremum small enough to
encode as 0x00 collided with the reserved-zero byte and took its whole
group to zero at 1e-3. Both now assert the fixed behaviour -- monotonic
saturation past the ceiling, and a sub-floor extremum that rounds
coarsely instead of vanishing -- plus that exact zero still encodes as
exact zero.

test_flydsl_one_shot_allreduce spawns real ranks and checks the one-shot
is bit-identical to a torch all-reduce, not merely close, at TP2/4/8. It
lives in multigpu_tests because it needs more than one GPU.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Cover both schedules and the transport in the INT4 all-reduce test

The test gated only on SQNR, which cannot tell a transport bug from a
codec one: a chunk-addressing or flag-protocol fault and a codec
regression both show up as a worse number. Run the same cases over the
fp16 passthrough wire format, where the whole reduce is lossless on an
exact-grid input, and gate those on bit-identity with the fp32 reference
instead. A ring variant with one lap fp16 and the other int4 names which
lap is responsible when only one of them is.

Every case now runs on both the mesh and the ring. The ring's
reduce-scatter lap requantizes N-1 times where the mesh requantizes once,
so its SQNR falls with N -- 22.2 dB at TP2, 18.7 at TP4, ~15 at TP8
all-INT4. Defaulting that lap to INT6 at TP8 lifts it to ~21 dB, so one
18 dB floor now covers both schedules; the all-INT4 TP8 configuration is
still reachable through AITER_ALL_REDUCE_CODEC and keeps its own case at
the floor it actually delivers.

Cases that share a (world_size, algorithm, super_tile) group now ride a
single spawn and are memoized for the session. _run_rank already looped
over a list of shapes; this just stops calling it with one-element lists,
which is most of the wall time back on a file that is now 46 cases.

Adds a degenerate-input case (all-zero and far-sub-floor groups) that
pins the encode-reciprocal clamp: a zero extremum decodes to a zero
scale, and before the clamp that reached the codec as Inf and 0 * Inf
poisoned the whole tile. INT6 has four times less headroom there than
INT4, so it is the schedule that needs it.

The predicted super-tile now compares against the engine's clamped ST=1
grid rather than the requested grid_cap, which is what the host's own
selection compares against.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [FlyDSL] Add the all-reduce benchmark, roofline and policy-fitting scripts

bench_comm_allreduce sweeps every all-reduce candidate available on the
host -- RCCL, custom all-reduce, HIP quick-reduce, and the three FlyDSL
schedules -- over a shape list, on one process group, and reports
latency, achieved bandwidth and SQNR per candidate. Candidates that
cannot run a given shape are reported as declined rather than silently
skipped, so a sweep says which alternatives a winner actually beat.

transferbench_roofline turns a TransferBench point-to-point measurement
into a per-schedule lower bound: each family's wire volume as a function
of payload and world size, divided by the measured fabric rate. That is
what separates "this kernel is slow" from "this kernel is at the wire".

fit_allreduce_policy consumes a sweep and emits the family boundaries in
allreduce_policy's format, so the tables there are reproducible from
measurement rather than hand-maintained.

The shapes/ CSVs are the sweep lists the current policy tables were
fitted from: a small and a large payload sweep, and one that holds the
payload fixed while varying hidden to separate size effects from shape
effects.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Improve benchmarking script to run in fast mode by default.

* Fixed heuristics for the exact mode.

* Fix bugs in the benchmarking script.

* Update heuristics for xGMI interconnect.

* Fix classification of FlyDSL auto-deducted kernel in benchmarking script.

* Remove unintended Git modules.

* Add two new tuning knobs: workgroup size and ability to read ranks own contribution from registers instead of IPC inbox (self-skip).

* Update PCIe heuristics.

* Refactor FlyDSL all-rduce kernels integration to comms dispatcher.

* [FlyDSL] Scope OneShotAllReduce to its device instead of set_device

Mirrors what #4970 did for QuickAllReduceInt4: construction, launch and close
run under torch.cuda.device(), so building the engine no longer changes the
caller's current device.

Co-Authored-By: Claude <[email protected]>

* [FlyDSL] Address agent review feedback on the all-reduce dispatch

- Add a GPU-free regression test for the P1 finding: both FlyDSL selectors
  must decline a weakly- but not strictly-contiguous tensor (a full-storage
  transpose) instead of letting the engine raise after dispatch committed.
- Document the host-wide xGMI detection and the uniform-node assumption it
  relies on (P3).
- Drop a stray argument from the quick-reduce FlyDSL init log call; it had
  one more argument than placeholders.
- Re-run black (trailing whitespace, assert formatting back to main's) and
  suppress SIM102 on a const_expr guard, matching the other FlyDSL kernels.

Co-Authored-By: Claude <[email protected]>

* [FlyDSL] Move all-reduce tooling out of the multi-GPU test directory

The multi-GPU CI job runs every .py under op_tests/multigpu_tests/ as a
script, so tooling there ran as tests: fit_allreduce_policy.py failed on its
required argument and bench_comm_allreduce.py ran a full sweep.

- Remove fit_allreduce_policy.py and the sweep shape CSVs it was fed.
- Move bench_comm_allreduce.py and transferbench_roofline.py to
  op_tests/op_benchmarks/flydsl/, which CI does not execute, and update
  their usage text. --shape-csv stays as a user option.

Co-Authored-By: Claude <[email protected]>

* Remove fragile tests. Refactor multi-GPU tests for all-reduce to follow Aiter testing guidelines. Add the full kernel information to human readable kernel name.

* Black and ruff fixes. Improve comments about the use of CUDA events in the FluyDSL all-reduce tests.

* Add self-skip and block tunign knobs to two-steage mesh all-reduce.

* Use fx.generic_load, fx.generic_store, and fx.memory_fence to replace the inline ASM.

* Use system scope memory fence for releasing inboxes.

* Use uncached memory on PCIe when world size is two.

* Update aiter/ops/flydsl/kernels/quick_allreduce_int4.py

Address GitHub bot feedback.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove probe from 1-stage kernel.

* Remove the legacy buffer_ops.buffer_load and buffer_ops.buffer_store. Extract shared layout definition. Clen-up code.

* Ensure communicator initialization only compiles the relevant all-reduce instances.

* Trim the test suite for one-shot and quick all-reduce kernels.

* Collect shared all-reduce host wrapper assets to a shared module.

* Heuristics for xGMI interconnect.

* Update PCIe heuristics after the latest run.

* Add more cases to the benchmarking script.

* Addres black and ruff findings.

* Remove the custom logic for loading the HIP runtime library.

* Optimize memory fences for PCIe TP=2 case when uncached IPC memory is used.

* Fix a wrap-around bug in one-shot all-reduce.

* Improve benchmarking script such that it doesn't have bias towards FlyDSL instances.

* Optimized syncscope for xGMI interconnect.

* Update PCIe heuristics for TP=2 and for TP=4.

* Update xGMI heuristics. Introduce an env variable to override the min message size for FlyDSL one-stage all-reduce.

* Use _preload_compiled from TensorShim to run JIT compilation outside HIP graph capture.

* Black and ruff fixes.

* Add a Lamport (flagless) variant of the FlyDSL one-shot all-reduce.

The payload is its own flag: inbox slots hold a sentinel (bf16 NaN 0xFFFF in
every half-word) until a peer's data lands, the receiver polls all of its
sources together until no half-word is the sentinel, then re-arms the slot
two rounds ahead in a 3-buffer rotation. Senders rewrite a sentinel
half-word in their own payload to 0x7FFF, which is still NaN. That removes
the vmcnt(0) drain, both barriers and the flag round trip from every tile.

- kernel: `lamport` const_expr in make_one_shot_allreduce_kernel; uncached
  inbox only. The poll re-reads through relaxed system-scope atomics
  (_poll_v4i32) so the spin cannot be deleted. The first tile is peeled so
  its input load overlaps the colour load.
- IPC: UncachedIpcHeap.alloc takes a fill byte and synchronizes after the
  memset, so a late fill cannot erase a peer's first push.
- host: `lamport` is the 7th ONESHOT_LADDER field and an OneShotAllReduce
  knob; AITER_FLY_AR_ONESHOT_LAMPORT=0|1 pins it from the environment.
  Every shipped rung keeps lamport=False in this commit.
- tests: --lamport knob, Lamport spot configs at TP2/TP8, and a 300-call
  fresh-input stress checked bit for bit against a rank-order reference.
- bench: fly_1stage_lp and _lp variants of the pinned fly1s grid.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Ship the Lamport one-shot on xGMI and drop the one-shot floors there.

Sweep on 8x MI325X (gfx942), graph timing. Best Lamport config vs the flag
one-shot: TP2 -3..-23%, TP4 -3..-14%, TP8 -19..-41%. It ties or beats
cross_device_reduce down to 2 KiB at every world size, so the xGMI
min_bytes floors (56/48/112 KiB) go to 0.

ONESHOT_LADDER xGMI, all skip_self + lamport, atoms=1, cap 128:
  TP2  b128 to 256 KiB (one round), then b256
  TP4  b256
  TP8  b128

PCIe rungs stay on the flag variant (not measured).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Make Lamport all-reduce the default and add heuristics.

* Make self-skip default on one-shot and two-shot mesh algorithms. Redeuce the number of benchmarked configurations.

* Remove redundant/obsolete instances from benchmarking.

* Transferbench roofline fixes.

* Clean-up TransferBench runner script.

* Benchmarking script fixes.

* Move FlyDSL communication kernels into a single directory.

* Black & ruff fixes.

* Address first part of the code review feedback.

* Remove separate benchmarking scripts.

* Expand test scripts to run the benchmarking.

* Add gfx950/xGMI all-reduce policy rows; never pick the ring there.

The FlyDSL family policy was measured on gfx942 for xGMI. On gfx950/xGMI
(MI355X) the bench scenario of the all-reduce op tests shows:

* The ring never beats the mesh: 1.03x-1.16x slower at TP2 up to 512 MiB,
  2.2x-5.7x slower at TP4/TP8. The 128 MiB mesh_max sent large payloads to
  it; mesh_max is now unbounded there.
* cross_device_reduce's 2-stage kernel beats both the one-shot and the
  mesh over a wide middle range at TP4/TP8, so the one-shot ceiling drops to
  cdr's 2-stage switch and the mesh floor rises to where the mesh overtakes
  cdr (960 KiB at TP4, 1600 KiB at TP8). At TP2 the one-shot beats cdr up
  to 3 MiB and the mesh up to 448 KiB.

Rows measured on one arch live in ARCH_FAMILY_POLICY, keyed by
(arch, link, world_size), and replace the FAMILY_POLICY row on that arch
only; gfx942 keeps its rows. The resolvers and max_payload_bytes take an
optional arch, defaulting to this host's.

End to end through CudaCommunicator.all_reduce under graph capture (INT4
regime), against the old rows: never slower (within noise), 1.17x-1.54x at
TP4/TP8 mid-range, 2.47x (TP4) and 5.44x (TP8) at 256 MiB. Against stock
production with FlyDSL off: >= 0.99x at every size.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Make the all-reduce tuning ladders and policy records dataclasses.

Review feedback on #5461: ladder rungs were bare tuples, so every reader had
to know the field order.

* OneShotRung (min_bytes, atoms, grid_cap, fanout, block) and TwoShotRung
  (min_bytes, super_tile, grid_cap, block) replace the tuples of
  ONESHOT_LADDER, MESH_ST_LADDER and RING_ST_LADDER, and pick_rung() is the
  one implementation of "last rung at or below the payload" for both hosts.
* The records live in kernels/comm/allreduce_shared.py next to the rungs:
  FamilyPolicy, OneShotPolicy and QuantPolicy move there from
  allreduce_policy, with NO_MAX. allreduce_policy re-exports them.
* The mesh ladder comment described an older table; it now matches the
  rungs.
* OneShotAllReduce dropped a grid_cap ceiling branch that could not run:
  any grid_cap pins the configuration.

No behaviour change. Verified with the policy unit tests and both
multi-GPU verify scenarios on gfx950 (TP2/4/8).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Make the all-reduce heuristics readable from one module.

allreduce_policy.py now holds every tuned decision, in two levels, with a
module docstring that draws the payload axis:

* Level 1, which kernel: FamilyPolicy fields are renamed to say what they
  bound, in payload order -- oneshot_min, oneshot_max (was
  oneshot_max_exact), quant_min (was oneshot_max, which was not a one-shot
  maximum but the mesh floor), mesh_max, quant_max (was max_bytes).
  route() composes the two slots in CudaCommunicator.all_reduce order and
  returns oneshot / mesh / ring / fallback; the policy unit tests and the
  INT4 bench use it instead of private copies. The bench's copy reported
  "oneshot" for payloads that go to cross_device_reduce.
* Level 2, which configuration: ONESHOT_LADDER, MESH_ST_LADDER and
  RING_ST_LADDER move here from the kernel modules, which never used them.

No behaviour change: the rows keep their values under the new names. The
environment overrides keep their meaning. Verified with the policy unit
tests (plus a route() test for the gfx950/xGMI rows) and both multi-GPU
verify scenarios on gfx950.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Collect the all-reduce limits and shared constants in one place.

Review feedback on #5461: limits were restated across modules, and the ring
had a payload floor of its own that mirrored the policy by hand.

* kernels/comm/allreduce_shared.py has a "Limits" section: SUPPORTED_ARCHS,
  SUPPORTED_WORLDS, LINKS, SUPPORTED_BLOCKS, PAYLOAD_ALIGN_BYTES,
  MAX_PAYLOAD_BYTES, QUANT_MIN_PAYLOAD_BYTES and NO_MAX. The policy, the
  hosts, the codec, the one-shot kernel, CustomAllreduce, QuickAllReduce and
  the op tests import them instead of keeping their own copies (three
  SUPPORTED_ARCHS, two SUPPORTED_BLOCKS, two SUPPORTED_WORLDS, and the
  "pcie"/"xgmi" literals).
* The ring's standalone floor (_RING_MIN_PAYLOAD_BYTES_BY_WORLD, 4-12 MiB)
  is gone. It claimed to mirror mesh_max but matched no policy row, and
  production never used it (dispatch passes min_bytes=0). Both schedules
  now refuse the same thing on their own: payloads under
  QUANT_MIN_PAYLOAD_BYTES, the accuracy guard.
* The tuned constants MIN_BATCH_BLOCKS and RS_INT6_MIN_WORLD move to
  allreduce_policy with the rest of the tuning.
* The hosts' identical payload checks, link resolution, arch check and
  group checks become shared helpers: check_payload, resolve_link,
  require_arch, check_world_size and _validate_ipc_process_group.

Verified with the policy unit tests, both multi-GPU verify scenarios and
bench smoke runs on gfx950.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Code clean-up after refactoring the family policy and rungs for tuning ladders.

* Refactor FamilyPolicy to use explicit windows per algorithm. Clean-up the host wrappers to simply how the rungs of tuning ladders are used.

* Run only the production configs by default in the all-reduce tests.

* Clean-up comments and doc strings in ring all-reduce kernel.

* Ensure ring all-reduce gives bit.identical output for every rank. Add tests that execute production all-reduce dispatch. Fixed one-shot all-reduce window handling for th exact mode. Add an env variable to specify the interconnect type. Fix other small review findings.

* Rename factory for quick reduce ring kernel.

* Fix black issues, improve tests, and fix exact one-shot all-reduce window.

* Simplify handling of the one-shot all-reduce window.

* Rename all-reduce host side assets to have host prefix in the filename.

* Fix black and ruff.

* Small re-tune for PCIe.

* Add op_tests/multigpu_tests/flydsl_allreduce_bench.py on the test skip list since it contains no actual tests, only infrastructure.

* Address co-pilot review feedback.

* [FlyDSL] Rename the quick all-reduce assets to allow more codecs.

Mechanical rename, no behaviour change. The mesh and ring schedules carry
INT4, INT6 and FP16 wire formats, so the names stop saying INT4:

* kernels/comm/quick_allreduce_int4.py      -> quick_allreduce_mesh.py
* kernels/comm/quick_allreduce_int4_ring.py -> quick_allreduce_ring.py
* quick_allreduce_int4.py                   -> quick_allreduce.py
* quick_allreduce_int4_ipc.py               -> quick_allreduce_ipc.py
* test_flydsl_quick_allreduce_int4.py       -> test_flydsl_quick_allreduce.py
* QuickAllReduceInt4 -> FlyQuickAllReduce,
  make_quick_allreduce_int4_kernel -> make_quick_allreduce_mesh_kernel

The identifiers match PR #5555 so the two branches rename identically.
mega_moe_tp imports the IPC helper under its new name.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] Fused all-reduce + residual add + RMSNorm kernels.

One-shot, mesh and ring kernels gain a ``fusion="rmsnorm"`` build that runs
residual-add + RMSNorm as the epilogue of the all-reduce, with the tile sized
to one token row (``block = hidden / (8 * atoms)``) so the norm reduces
within a workgroup:

* ``kernels/comm/quick_allreduce_fusions.py``: the shared epilogue and the
  row-to-workgroup geometry, the padded geometry for widths with no native
  one (per-row bounded buffer descriptors mask the pad lanes), and the HBM
  exchange word that joins a row split over ``split`` workgroups.
* One-shot: split rows, padded widths and the self-skip; the plain launch
  passes the (unused) fused operands of the shared kernel signature.
* Mesh and ring: the epilogue per tile (mesh) or per chunk inside the ring
  pipeline. The ring's owner hands the epilogue the decoded packet, as the
  plain path does, so every rank ends with the same bits.
* ``validate_block`` accepts any 128-thread multiple up to 1024 besides the
  plain menu (``BLOCK_ALIGN``/``MAX_BLOCK`` in ``allreduce_shared``).

Host classes ``OneShotAllReduceRMSNorm`` and ``FlyQuickAllReduceRMSNorm``
build one engine per (hidden, rung) lazily or up front (``hiddens=``).

Policy, in the idiom of the plain one (``allreduce_policy``):
``FUSED_FAMILY_POLICIES`` of ``FamilyPolicy`` per (arch, link, world_size),
``FUSED_ONESHOT_LADDER`` of ``FusedOneShotRung``, ``FUSED_{MESH,RING}_ST_LADDER``
of ``FusedTwoShotRung`` and ``FUSED_QR_ROW_ATOMS``. ``AITER_FLY_AR_ACCURACY``
(default ``exact``) picks the quantized or the exact windows; overrides are
``AITER_FLY_AR_FUSED_<ALG>_{MIN,MAX}_BYTES``. Window maxima are exclusive now,
as in the plain policy. gfx950/xGMI reuses the gfx942/xGMI tables until tuned.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] Dispatch the fused all-reduce + RMSNorm in production.

``FlyDSLAllReduceRMSNorm`` lives in ``QuickAllReduce`` and owns one engine per
family the fused policy enables in the current ``AITER_FLY_AR_ACCURACY`` mode.
``CudaCommunicator.fused_allreduce_rmsnorm`` asks it first; a payload outside
every window, or a width no family can build, falls through to aiter's own
fused kernels.

Widths are built before capture (``AITER_FLY_AR_FUSED_HIDDENS``, ``hiddens=``,
``prime()`` or a warmup call); inside a capture an unbuilt width declines
rather than building. ``preload_fly_engines`` passes the hidden dim to the
fused engines' ``preload``.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] Tests for the fused all-reduce + RMSNorm.

* Policy unit tests for the fused tables: coverage of every platform,
  monotone dispatch, exact mode is one-shot only, ladder well-formedness,
  ``FUSED_QR_ROW_ATOMS``, overrides separate from the plain ones, accuracy
  mode and ``AITER_FLY_AR_FUSED_HIDDENS``.
* Codec tests at the row-sized blocks the fused builds use.
* ``--operation ar|ar_rmsnorm`` in both multi-GPU tests; verify runs both
  unless one is named.
* One-shot: SQNR on ``out`` and bit-exact ``residual_out`` at native and
  padded widths, pinned atoms/block, split rows (repeat, magnitude, slice
  lag), run-ahead and fresh inputs, and GPU-free geometry checks. Its ranks
  are subprocesses of the script (``--rank``); a user run's arguments are no
  longer parsed by the worker parser.
* Mesh/ring: SQNR, bit-exact residual on the lossless wire (native, padded
  and pinned super-tile), padded widths on INT4, mesh rank agreement and
  host-side geometry checks.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] Bench the fused all-reduce + RMSNorm, and pinned candidates.

The bench scenario of both multi-GPU tests takes ``--operation``:

* ``ar`` (default): the plain all-reduce, as before.
* ``ar_rmsnorm``: the fused kernels. The one-shot test times
  ``OneShotAllReduceRMSNorm`` against ``CustomAllreduce``'s fused kernel at
  both stage counts and against ``cdr``/``rccl`` + ``rmsnorm2d_fwd_with_add``,
  and reports ``prod`` (``CudaCommunicator.fused_allreduce_rmsnorm`` with
  FlyDSL off) and the fused policy's ``route``. The quick test times each
  ``FlyQuickAllReduceRMSNorm`` schedule against the HIP quick all-reduce's
  fused kernel and against the HIP quick all-reduce + norm.

``--candidates PATH`` reads pinned FlyDSL configurations from a candidate
file (``flydsl_allreduce_bench.load_candidates``: name, operation, algorithm,
one column per knob, sets) and times each as one more column of the same
spawn, so the stock kernels are timed once and the rotation covers every
candidate; ``--candidate-set`` selects rows by tag. This is what the tuning
suite drives in place of the removed standalone benchmark.

``graded_replay`` grades several outputs, and ``fused_reference`` is the
shared fp32 reference of the fused operation.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] Test a policy whose one-shot window is unbounded.

A one-shot that wins at every size, in both modes, is the answer a fit gives
on some platforms. Check that FamilyPolicy accepts it and selects the
one-shot at any payload.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] Tune the all-reduce tables from the tests' bench scenario.

The tuning suite moves to op_tests/multigpu_tests/flydsl_allreduce_tuning and
drives the bench scenario of the two multi-GPU tests instead of the removed
standalone benchmark:

* candidates.csv (generated by gen_candidates.py, checked by
  ``--check``) lists the pinned configurations the sweeps time, in sets:
  ``sweep``, ``validate``, ``fused``, ``fused_qr`` and ``smoke``. The fused
  grids are generated from the kernels' row geometries.
* bench_io.py reads the tests' ``--csv`` output into the fits' columns, and
  names the shipping engines and the stock kernels under fixed keys.
* fit_allreduce_policy.py joins the one-shot and mesh/ring CSVs of a shape,
  reconstructs the shipped dispatcher (``fly_auto``) from the policy in the
  ``--accuracy`` mode, and prints ``FamilyPolicy`` rows of ``Window``s and
  ``OneShotRung``/``TwoShotRung`` ladders keyed by (arch, link, world_size),
  checked by building them. Thresholds are half-open, as ``Window`` and
  ``select_rung`` are.
* fused/fit_fused.py and fused/analyze_fused.py do the same for the fused
  tables (``FUSED_FAMILY_POLICIES``, ``FusedOneShotRung``,
  ``FusedTwoShotRung``, ``FUSED_QR_ROW_ATOMS``).
* tune.sh keeps its commands. ``check`` also parses a pinned flydsl version
  that carries an environment marker.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Docstring updates.

* Remove unnecessary AITER_FLY_AR_ACCURACY env variable. Split all-reduce + RMSNorm fusion between QuickReduce and CustomAllReduce dispatchers. Update FlyDSL comm kernels Readme.

* Remove tuning scripts and files from source control.

* Consolidate all-reduce limits and move tunning ladder rungs and policies from kernel files to the shared host assets. Remove unnecessary default definitions.

* Black & ruff fixes.

* WIP: Refactor fused all-reduce into a separate epilogue.

* Improve benchmarking scripts.

* Compile all rungs within a window on the first call of a given width. Remove pytest from the fused all-reduce tests. Make row splitting an opt-in feature and fix the handing of NaN and Inf values. Document row splitting limitations in Readme.

* Add FlyDSL all-reduce pytests to CI run.

* Add a common check for the fused aliasing. Remove double routing for fused all-reduce dispatching. Ensure tests run the production geometry.

* Ensure all ranks resolve the same policies.

* Small clean-up.

* Make tuning ladders per hidden dim. Read the ladder from a JSON configuration file.

* Increase timeout in benchmarking script because of JIT compilation.

* Fix quick reduce benchmarking sweep.

* Increase timeout for the quick reduce benchmark due to JIT compilation.

* Update FamilyPolicies and tuning ladders after tunign sweep.

* Remove dead code.

* Fix black & ruff.

* Ruff fix.

* Document and tidy the fused QuickReduce RMSNorm Gemma/MXFP4 support

README, epilogue docs and test comments now describe the runtime Gemma
operand and the MXFP4 epilogue variant.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Port the #6369 low-latency fused-norm build to the mesh epilogue design

The mesh RMSNorm epilogue gains a latency option with a prefetch hook that
loads the residual ahead of the exchanges. A ladder rung may select it
(optional latency field, default false), and the host builds it as separate
engines with two resident workgroups per CU. It is correct but slower than the
default build on gfx950 TP8 hidden 2048, so no shipped rung uses it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Restrict the low-latency fused build to xGMI ladders

#6369's low-latency build targeted gfx950 over xGMI; over PCIe it measured
slower than the default build, so the ladder loader rejects a latency rung on
any other link. No shipped rung uses it. Also add --bench-only and a grid cap
override to the fused QuickReduce test, for measuring it on an xGMI box.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Rename latency to low_latency for fused all-reduce.

* Add a separate facade for FlyQuickAllReduce.

* Enable benchmarking the low-latency fused all-reduce.

* Consolidate the fused all-reduce tests.

* Black and ruff fixes.

* Move tuning ladder JSON config under configs/comm directory.

* Readme update.

* Fix GPU detection in the benchmarking scripts.

* Relax requirement that row must fit in one rank's chunk for mesh all-reduce.

* List candidates in test/benchmarking scripts. Add option to benchmark only direct Aiter competitors for tuning.

* Fix building low-latency assets.

* Update FamilyPolicy and tunning ladders for gfx950/xGMI combination.

* Ensure tests cover the shipped instances. Remove tests for non-shipped instances.

* Update tuning ladders for gfx950/xGMI after tuning sweep.

* Fix black and ruff.

* Update tuning ladders and policy after re-tunign sweep for gfx950/PCIe.

* Ensure all ranks agree on which FlyDSL all-reduce needs to be built. Add CPU test to verify the rank agreement logic and append to GPU tests to have  a case where one rank has FlyDSL all-reduce disabled.

* Load all-reduce kernels onto device at initialization. This ensures that possible HIP graph capture doesn't include module loads. Add tests where first call takes place inside a graph capture (no wram-up).

* Remove ring ladders that are not shipped.

* Fix black & ruff.

* Test fix after merge.

* Fix performance regression for fused all-reduce + RMSNorm.

* allow fused all-reduce + RMSNorm inside the HIP graph capture.

* Update TP=2 ring algorithm window policy for gfx950/xGMI.

* Fix failing policy test.

* Add a check that build and launch are outside HIP graph capture.

* Cache the check for hidden dim support. Add tunning ladders for new hidden dims.

* Rename shared IPC assets.

* Fix use sites of ipc?heap. Add compatibility layer.

* Ensure FlyDSL fused path declines if one rank fails to build for a given hidden dim. Update Readme. Add tests.

* Address Copilot code review findings.

* Fix black and ruff.

* Fix Aiter bot findings.

* Black and ruff fixes.

* Fix black.

* Add tests for zero bytes messages. Fix handling of zero bytes messages in one-shot all-reduce and quick-allreduce.

* Create alias class QuickAllReduceInt4 for vLLM.

* Add test test_flydsl_allreduce_rank_agreement.py to CI run.

* Add a test that checks the limits for row splitting in the one-shot fused all-reduce. Document limits in the Readme.

* Fix black and ruff.

* Fix min bytes for the vLLM alias.

* Fix quick-allreduce test execution for gfx942.

* Fix tests for all-reduce ring algorithm on PCIe.

* Update comment strings and Readme after FlyDSL 0.5.0 changes.

---------

Co-authored-by: Sami Remes <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: samremes <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR FlyDSL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants