Skip to content

[FlyDSL] QuickAllReduce INT4: E5M2 group scale so groups above 480 no longer clip - #7258

Merged
TennyWang1223 merged 1 commit into
ROCm:mainfrom
vorapolsiloai:qr-int4-e5m2-scale
Nov 4, 2026
Merged

TennyWang1223 merged 1 commit into
ROCm:mainfrom
vorapolsiloai:qr-int4-e5m2-scale

Conversation

@vorapolsiloai

@vorapolsiloai vorapolsiloai commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

The FlyDSL quick all-reduce codec (kernels/comm/quick_allreduce_codec.py, used by the mesh and the ring, INT4 and INT6) stores each 16-value group's scale as E4M3 with bias 7, which spans only [2^-7, 480]. A group whose max |x| is above 480 clips to about 480, both when a rank quantizes its partial and when the reduced sum is re-quantized for the all-gather; the ring re-quantizes its running sum at every hop, so sums of a few values near 300 clip too. #5461 documents this as a limitation.

Real models exceed it. On MiniMax-M3 (vLLM, MI355X) all-reduce outputs reach 6,400–16,800, and vLLM routes BF16 INT4 QuickReduce to this kernel whenever AITER is on (vllm-project/vllm#59478). The result is silently wrong output: MMMU val drops from ~0.66 to 0.27–0.31 at TP2, TP4 and TP8.

This PR stores the group scale as E5M2 with bias 12 ([2^-12, 1.75·2^19]): same byte, same wire layout, same instruction count. Every fp16 extremum fits at the default divisor.

Relation to #6049: its opt-in divisor (default 1, so callers that pass none, including vLLM, still clip) is kept with the same API and bounds; it is no longer needed to avoid the clip. Its test is adapted: divisor 1 must now meet the SQNR floor on the outlier fill, and divisor 8 may cost at most 1 dB.

Rebased onto #5461, which moved the kernel into kernels/comm/ and added INT6 and the ring; the change now covers both codecs and both schedules.

Changes

  • kernels/comm/quick_allreduce_codec.py:
    • E5M2 (bias 12) group-scale encode/decode.
    • Codec.scale_min_e5: INT6 divides by 32, so its scale is floored at 2^-10 (INT4 keeps 2^-12) to keep the fp16 encode factor finite.
    • Codec.scale_rounds_up: INT6 rounds the scale up instead of to nearest. Rounding to nearest can clip the group extremum by up to 1/8, which is one INT4 step but four INT6 steps (−2.4 dB on INT6). INT4 keeps rounding to nearest.
    • SCALE_CODEC_TAG (s5m2b12): FlyDSL does not hash the codec helpers into its disk cache key, so the tag is put in both kernels' launch names (kernels/comm/quick_allreduce_int4.py, quick_allreduce_int4_ring.py). Without it a warm cache keeps loading E4M3 binaries (reported by @TennyWang1223).
  • allreduce_policy.py: RS_INT6_MIN_WORLD 8 → 4. The ring requantizes its partial sum at every hop; at TP4 an all-INT4 ring had only 0.26 dB of margin over the 18 dB floor (18.26 dB with E4M3) and lands at 17.89 dB with E5M2, so its reduce-scatter lap now defaults to INT6 from TP4 (agreed with @vpietila-amd). This is ring-only, which production routes to on PCIe hosts; the mesh (xGMI) is unchanged. Moving it back to TP8 once a precision-preserving scale lands (per-slice E4M3/E5M2, [FlyDSL] QuickAllReduce INT4/INT5/INT6: fp32 divisor and pair-shared-exponent group scales #7326) is planned as its own PR, verified on MI350P.
  • quick_allreduce_int4.py: divisor-bounds comment restated for E5M2 (bounds unchanged). README and docstrings no longer describe the 480 clip.
  • op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py: the tests that asserted saturation at 480 now assert that extrema up to 60000 do not clip; the analytic bound uses the 2-bit scale mantissa (1/8); new tests for small extrema and the scale floor.
  • op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py: new fill large_every_rank (2048 on every rank, so partials and the sum are above 480) for the mesh at TP2 and the ring at TP8; divisor test adapted as above; pinned ring case with an INT6 reduce-scatter lap at TP8.

Test

On this branch (rebased on main 8f1d6bd), FlyDSL 0.4.1:

  • Codec tests, MI355X: 78/78 pass. Round-trip SQNR, main → this PR, normal fill: INT4 22.2 → 21.9 dB, INT6 33.4 → 33.5 dB.
  • test_flydsl_quick_allreduce_int4.py, 8× MI355X: passes at TP8/4/2, incl. large_every_rank (exact) and the divisor cases (outlier fill 19.1 dB at divisor 1 and 8). Against main on the same node, 7 shipping rows: time ratio median 0.999 (0.987–1.003), SQNR −0.34 to −0.38 dB. Also passes on 8× MI350X.
  • test_flydsl_quick_allreduce_int4.py --extended, 8× MI350X: pass.
  • test_flydsl_quick_allreduce_int4_rmsnorm.py, 8× MI350X: pass.
  • Ring correctness (PCIe path): there is no PCIe (MI350P) host available to us, so the ring was run on 8× MI350X with the policy forced to plan as PCIe (KFD link probe hidden in the test process, AITER_FLY_AR_LINK=pcie); the traffic still goes over xGMI, so this checks numerics and control flow, not PCIe speed. --extended passes; ring TP4 (now INT6 reduce-scatter) 21.44 dB, was 17.89 dB with INT4; ring TP8 int6/int4 20.89–21.01 dB; large_every_rank on the ring at TP8 exact; pinned TP8 int4/int4 15.33 dB (floor 15.0).
  • Not measured: ring performance on PCIe (MI350P). The only PCIe-relevant change is INT6 instead of INT4 on the ring's reduce-scatter lap at TP4: 26 instead of 18 sectors per rank-tile on that lap, so a bandwidth-bound TP4 ring call takes at most about (26+18)/(18+18) ≈ 1.22× as long. Kernel-side proxy on xGMI (same node, INT4 vs INT6 reduce-scatter at TP4): 512×5120 115 → 124 µs (×1.07), 2304×4096 249 → 276 µs (×1.11), 8192×4096 616 → 753 µs (×1.22), 9216×4096 680 → 824 µs (×1.21); large payloads match the bandwidth bound. Callers can still pin rs_codec="int4".
  • Warm FlyDSL cache: main fills a persistent cache, then this branch builds new s5m2b12 binaries and passes. Before the tag, the previous head reused main's binaries and failed every-rank-2048 at 1.08 dB.
  • gfx942 (8× MI300X, by @TennyWang1223, previous head): every case passes with a fresh cache; normal fill 19.20 → 18.84 dB; TP8 speed within noise.
  • End to end, MiniMax-M3 VL on vLLM, MI355X, MMMU val (previous head, same INT4 codec): TP2 0.2756 → 0.6344, TP4 0.2711 → 0.6567, TP8 0.31 → 0.66 (QuickReduce off: 0.64 / 0.67 / 0.668).

Trade-off: INT4 in-range SQNR drops by about 0.3–0.4 dB on normal data and about 0.9 dB with per-channel outliers (measured by @samremes), because the scale has 2 mantissa bits instead of 3. Recovering it (e.g. per-slice E4M3/E5M2, #7326) is a follow-up. Values above 65,504 still saturate in the fp16 arithmetic; #7326 also addresses that.

PR Self-Review

Reviewed revision

662b23c

Behavior and intent

The quick all-reduce codec (mesh and ring, INT4 and INT6) stored each 16-value group's scale as E4M3 with bias 7, spanning [2^-7, 480]. A group whose max |x| exceeds 480 clips to about 480 on every pack and, on the ring, on every hop; nothing reports it. MiniMax-M3 all-reduce outputs reach 6,400–16,800, so MMMU val on MI355X drops from ~0.66 to 0.27–0.31 at TP2/4/8.

The scale is now E5M2 with bias 12, covering [2^-12, 1.75·2^19]: same byte, layout and instruction count, and every fp16 extremum fits. INT6 floors its scale at 2^-10 and rounds it up, so its encode factor stays in fp16 and its extremum is never clipped by scale rounding. The ring's reduce-scatter lap defaults to INT6 from TP4 (was TP8), because an all-INT4 ring at TP4 drops to 17.89 dB, under the 18 dB floor. SCALE_CODEC_TAG in the launch names invalidates FlyDSL disk-cache binaries built with the old codec. Trade-off: INT4 loses about 0.3–0.4 dB in-range SQNR (0.9 dB with per-channel outliers); INT6 is unchanged.

Validation and unverified scope

Validated on this revision, FlyDSL 0.4.1:

  • Codec tests (MI355X): 78/78 pass; INT4 22.2 → 21.9 dB, INT6 33.4 → 33.5 dB on a normal fill.
  • INT4 op test (8× MI355X and 8× MI350X): passes at TP8/4/2, incl. large_every_rank and the divisor cases; speed equal to main (median 0.999 over 7 rows).
  • --extended and the fused rmsnorm op test (8× MI350X): pass.
  • Ring with the policy forced to plan as PCIe (8× MI350X over xGMI): --extended passes; ring TP4 21.44 dB, TP8 20.89–21.01 dB.
  • Warm-cache check: new s5m2b12 binaries are built over a cache filled by main.

Validated on the previous head (same INT4 codec): gfx942 by @TennyWang1223; MiniMax-M3 VL MMMU on vLLM recovers to 0.63–0.66 at TP2/4/8.

Unverified (remains to be checked):

  • Ring performance on a PCIe host (MI350P): not measured, no host available; bound and xGMI proxy in Test. Ring correctness was checked with forced PCIe planning on xGMI.
  • gfx942 on this revision.
  • End-to-end accuracy of other models that use this kernel under the INT4 in-range SQNR change.
  • Multi-GPU op tests are skipped in PR CI, so CI does not exercise this kernel.

PR-specific question

What would each changed op test fail on before this PR, and why doesn't an existing canonical test already cover it?

  • large_every_rank sets every rank's partial, and therefore the sum, to 2048, above the E4M3 maximum of 480. With the E4M3 scale it fails the SQNR floor (1.08 dB < 18, measured on the pre-[FlyDSL] [CI] One stage and two-stage ring all-reduce kernels for PCIe interconnects #5461 kernel, which has the same codec) because the scale clips on both packs.
  • The codec saturation tests (test_extremum_near_e4m3_ceiling_saturates, ..._past_e4m3_ceiling_saturates_monotonically) asserted the clip; they are replaced by test_large_extremum_does_not_clip, which cannot pass with E4M3: main's own test asserts those extrema decode to at most 481.
  • The divisor test asserted the clip (divisor 8 had to beat divisor 1 by 3 dB); it now requires divisor 1 to reach the floor, which fails before this PR.

So the canonical tests encoded the clipping instead of rejecting it.

Changed op tests

  • op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py: fill large_every_rank (mesh TP2, ring TP8); divisor assertion replaced (same cases); pinned ring case int6/int4 at TP8.
  • op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py: test_ring_codec_defaults_widen_from_tp4 expects INT6 at TP4 (was ..._widen_only_at_tp8).
  • op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py: saturation tests replaced by no-clip tests; analytic bound 1/16 → 1/8; small-extremum test parametrized (1e-3, 1e-4); scale-floor test.

@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:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7258 --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.

@aiter-bot

aiter-bot commented Oct 31, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 662b23cabf62 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

The quick all-reduce codec (mesh and ring, INT4 and INT6) stored each 16-value group's scale as E4M3 with bias 7, spanning [2^-7, 480]. A group whose max |x| exceeds 480 clips to about 480 on every pack and, on the ring, on every hop; nothing reports it. MiniMax-M3 all-reduce outputs reach 6,400–16,800, so MMMU val on MI355X drops from ~0.66 to 0.27–0.31 at TP2/4/8.

The scale is now E5M2 with bias 12, covering [2^-12, 1.75·2^19]: same byte, layout and instruction count, and every fp16 extremum fits. INT6 floors its scale at 2^-10 and rounds it up, so its encode factor stays in fp16 and its extremum is never clipped by scale rounding. The ring's reduce-scatter lap defaults to INT6 from TP4 (was TP8), because an all-INT4 ring at TP4 drops to 17.89 dB, under the 18 dB floor. `SCALE_CODEC_TAG` in the launch names invalidates FlyDSL disk-cache binaries built with the old codec. Trade-off: INT4 loses about 0.3–0.4 dB in-range SQNR (0.9 dB with per-channel outliers); INT6 is unchanged.

Validation and unverified scope

Validated on this revision, FlyDSL 0.4.1:
- Codec tests (MI355X): 78/78 pass; INT4 22.2 → 21.9 dB, INT6 33.4 → 33.5 dB on a normal fill.
- INT4 op test (8× MI355X and 8× MI350X): passes at TP8/4/2, incl. `large_every_rank` and the divisor cases; speed equal to main (median 0.999 over 7 rows).
- `--extended` and the fused rmsnorm op test (8× MI350X): pass.
- Ring with the policy forced to plan as PCIe (8× MI350X over xGMI): `--extended` passes; ring TP4 21.44 dB, TP8 20.89–21.01 dB.
- Warm-cache check: new `s5m2b12` binaries are built over a cache filled by main.

Validated on the previous head (same INT4 codec): gfx942 by @TennyWang1223; MiniMax-M3 VL MMMU on vLLM recovers to 0.63–0.66 at TP2/4/8.

Unverified (remains to be checked):
- Ring performance on a PCIe host (MI350P): not measured, no host available; bound and xGMI proxy in Test. Ring correctness was checked with forced PCIe planning on xGMI.
- gfx942 on this revision.
- End-to-end accuracy of other models that use this kernel under the INT4 in-range SQNR change.
- Multi-GPU op tests are skipped in PR CI, so CI does not exercise this kernel.

PR-specific question

What would each changed op test fail on before this PR, and why doesn't an existing canonical test already cover it?

- **`large_every_rank`** sets every rank's partial, and therefore the sum, to 2048, above the E4M3 maximum of 480. With the E4M3 scale it fails the SQNR floor (1.08 dB < 18, measured on the pre-#5461 kernel, which has the same codec) because the scale clips on both packs.
- **The codec saturation tests** (`test_extremum_near_e4m3_ceiling_saturates`, `..._past_e4m3_ceiling_saturates_monotonically`) asserted the clip; they are replaced by `test_large_extremum_does_not_clip`, which cannot pass with E4M3: main's own test asserts those extrema decode to at most 481.
- **The divisor test** asserted the clip (divisor 8 had to beat divisor 1 by 3 dB); it now requires divisor 1 to reach the floor, which fails before this PR.

So the canonical tests encoded the clipping instead of rejecting it.

Changed op tests

- `op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py`: fill `large_every_rank` (mesh TP2, ring TP8); divisor assertion replaced (same cases); pinned ring case `int6/int4` at TP8.
- `op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py`: `test_ring_codec_defaults_widen_from_tp4` expects INT6 at TP4 (was `..._widen_only_at_tp8`).
- `op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py`: saturation tests replaced by no-clip tests; analytic bound 1/16 → 1/8; small-extremum test parametrized (1e-3, 1e-4); scale-floor test.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

samremes
samremes previously approved these changes Nov 2, 2026

@samremes samremes 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 checked it on 8× MI355X (gfx950) with FlyDSL 0.4.1, at a94f0b3.

  • Tests. The op test passes on this head at TP2 and TP4. The TP8 validity and divisor cases pass on #7326. #7326 is this branch plus a change that gives byte-identical output for every in-range input, so those TP8 results apply here too.
  • Fixes the clipping. Outputs around 18k at divisor 1 go from 0.25 to 28.4 dB at TP4, and every-rank-2048 is now exact. No non-finite outputs in any case.
  • Divisor 8 no longer costs anything on small inputs. Std 0.005 goes from 3.5 to 18.8 dB.
  • Perf. At TP8, 512×5120 and 32768×5120 are unchanged against main: 21.3 vs 21.8 µs and 555.3 vs 555.2 µs.

Non-blocking notes:

  1. The in-range cost depends on the data. On normal fills it is −0.36 dB. On in-range data with per-channel outliers (lognormal channel scales, max 326, below 480) it is about −0.9 dB: 19.31 → 18.41 dB at TP4. That might be worth stating in the trade-off. Recovering it, for example with a per-slice format bit or a shared per-slice exponent, can be a follow-up and shouldn't block this.
  2. Values above 65,504 still clip at 65,536 whatever the divisor. #7326, stacked on this PR, applies the divisor in fp32 to fix that.
  3. #7093 also edits _codec_quant. Its exhaustive codec test covers "all 256 E4M3 scale bytes" through _e4m3_to_f32. Whichever PR lands second needs a rebase, and that test needs re-checking on the E5M2 values.

@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

Thanks @samremes, especially for the TP8 coverage via #7326. On the notes:

  1. Agreed. I've added the ~0.9 dB outlier-channel case (19.31 → 18.41 dB at TP4) to the trade-off in the description. A per-slice format bit or shared exponent is a follow-up.
  2. Yes, leaving that to [FlyDSL] QuickAllReduce INT4/INT5/INT6: fp32 divisor and pair-shared-exponent group scales #7326; noted in the description.
  3. Noted in the description: whichever of this and [FlyDSL] QuickAllReduce INT4: faster poll and codec, kernel-arg peers, gfx950 engine plans #7093 lands second rebases and ports the 256-scale-byte codec test to the E5M2 decode.

@vorapolsiloai
vorapolsiloai marked this pull request as ready for review November 2, 2026 12:57
@vorapolsiloai
vorapolsiloai requested a review from a team November 2, 2026 12:57
@github-actions github-actions Bot added the FlyDSL label Nov 2, 2026
@samremes

samremes commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

[ROCm/aiter] PR #7258 — [FlyDSL] QuickAllReduce INT4: E5M2 group scale so groups above 480 no longer clip

Re-encodes the INT4 quick all-reduce's per-group scale byte from E4M3 (max 480) to E5M2 with bias 12 (span [2^-12, 1.75·2^19]), so group sums above 480 — MiniMax-M3 all-reduce outputs reach ~16k — no longer saturate, at a documented 0.4–0.9 dB in-range SQNR cost.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 disabled the auto-run and this box cannot run the target (torch 2.15.0+cpu, all 8 GPUs at 98–99% VRAM); target op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py; the codec math itself was verified on CPU (all 256 decode bytes and all 63,488 finite fp16 round-trips: decode exact, no scale saturation, byte 0x00 only for +0).
Perf (advisory): NOT RUN — no idle GPU on this box and CPU-only torch; the PR's own base-vs-head timings on MI355X are un-reproduced here (TP2 3/48 MiB 43.5→43.4 / 315→315 µs; TP8 2/48/384 MiB 16.2/108/623 → 15.7/108/623 µs; independent reviewer TP8 512×5120 21.3 vs 21.8 µs and 32768×5120 555.3 vs 555.2 µs vs main).

⚠️ [verified] The E5M2 codec change in aiter/ops/flydsl/kernels/quick_allreduce_int4.py also feeds the fused add-RMSNorm epilogue, whose only op test — op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py, same 18 dB SQNR floor plus a 1% tight-mismatch budget over 17 cases — no reported run executed (the author ran the plain op test at TP2, the independent check TP2/TP4, and the PR lists the fused epilogues as unverified), so a case sitting within the measured 0.4–0.9 dB in-range drop of the floor — the plain kernel's normal fill is at 18.81 dB post-change — would fail only after merge, since multi-GPU tests are skipped in PR CI. Author must run the rmsnorm op test at TP2/TP4 on this head before merge.
⚠️ [verified] Both new divisor assertions in op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py (divisor 1 must reach the 18 dB floor; divisor 8 may cost at most 1 dB) execute only in the TP8 block, which every reported run of this head skipped — the TP8 divisor cases pass only on stacked #7326, whose divisor multiply is fp32 where this branch's is fp16, so the byte-identity transfer covers the power-of-2 divisor 8 on in-range fills but the new bounds as written have never executed on the branch they land on. Author must run the TP8 divisor block on this head (8 GPUs) before merge, or record the byte-identity argument in the test.
📝 [verified] The E5M2 scale in aiter/ops/flydsl/kernels/quick_allreduce_int4.py costs every INT4 QuickReduce user 0.36–0.9 dB in-range SQNR (19.18→18.81 dB normal fill, 19.31→18.41 dB with per-channel outliers at TP4, the PR's and the independent reviewer's numbers), and end-to-end accuracy is verified for MiniMax-M3 VL only (MMMU 0.63–0.66 vs 0.64–0.67 with QuickReduce off) while vLLM routes BF16 INT4 QuickReduce to this kernel whenever AITER is on. Reviewer should ask for one more model's accuracy check on this head, or accept the documented trade-off.

@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

Ran the two op tests the bot review asked for, on this head (a94f0b3). Both pass.

Setup: 8× MI350X (gfx950), FlyDSL 0.4.1, aiter imported from a checkout of a94f0b3. Each test was run with no arguments on 8 visible GPUs, so it sweeps TP8, TP4 and TP2 on its own.

test_flydsl_quick_allreduce_int4.py: exit 0. Codec cases (incl. every-rank-2048), TP8/TP4/TP2 validity shapes, and the TP8 divisor block all pass on this branch:

outlier fill divisor 1 divisor 8
512×5120 18.83 dB 18.83 dB
32768×5120 18.84 dB 18.84 dB

Divisor 1 clears the 18 dB floor and divisor 8 costs 0 dB, so the new bounds now hold on this head, not only on #7326.

test_flydsl_quick_allreduce_int4_rmsnorm.py (fused add-RMSNorm epilogue): exit 0. All validity cases pass at TP8 (11), TP4 (17) and TP2 (17): fused equals unfused exactly (error 0, also with the MXFP4 output), and all ranks are equal. Output SQNR is far from the 18 dB floor:

TP sqnr_out_db (min–max)
8 29.7–30.1
4 32.7–33.0
2 35.6–35.9

These were on MI350X, not MI355X, and without a main baseline on the same node, so I'm reporting correctness only. Speed vs main at TP8 is in @samremes' review above.

On the third point (accuracy of models other than MiniMax-M3): not run. The trade-off is in the description: -0.4 dB in-range SQNR on normal data, -0.9 dB with per-channel outliers.

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

Stale FlyDSL disk cache: the codec change is not part of the cache key

FlyDSL builds its disk-cache key by hashing the launch/kernel source plus the functions reachable through their co_names and closures. _f32_to_e4m3 / _e4m3_to_f32 are only called from nested defs (_codec_quant, _recv_quantized), so they are never hashed. Base and head produce the same manager_key and the same cache dir (launch_quick_allreduce_int4_ws{N}_st{S}_<key>). On any host with a warm ~/.flydsl/cache, the old E4M3 binary is loaded and the fix silently does nothing.

Repro

8× MI300X, gfx942, FlyDSL 0.4.0, head a94f0b3:

# warm default cache (this kernel ran before on this box)
python3 op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py
# -> AssertionError: every-rank-2048 tp=2: SQNR 1.08 dB < 18.0   (the pre-fix number)

# same code, empty cache
FLYDSL_RUNTIME_CACHE_DIR=$(mktemp -d) python3 op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py
# -> all cases pass (TP2 codec, TP2/4/8 validity, TP8 divisor)

This is exactly the deployment that needs the fix: a vLLM host that already served MiniMax-M3 with the old aiter, then upgraded, keeps MMMU at around 0.27, and nothing reports it.

Suggested fix

Put a codec tag in the launch name, which the cache dir is named after (aiter/ops/flydsl/kernels/quick_allreduce_int4.py ~L1183). Keep the tag as a constant next to the codec so the next format change (e.g. #7326) has to bump it:

# next to _f32_to_e4m3 / _e4m3_to_f32
# Bump whenever the group-scale codec changes: the helpers are not part of the
# FlyDSL cache key, so this tag is what invalidates binaries built with the old one.
SCALE_CODEC_TAG = "s5m2b12"
    launch_quick_allreduce_int4.func.__name__ = (
        f"launch_quick_allreduce_int4_{SCALE_CODEC_TAG}_ws{world_size}_st{super_tile}"
        f"{atoms_tag}{norm_tag}"
    )

To verify the fix, run the warm-cache command above again without clearing the cache. It should now pass.

Other notes

  • gfx942 validated (listed as unverified in the description): with a fresh cache every case passes. Normal-fill SQNR is 19.20 → 18.84 dB, matching your gfx950 numbers.

  • Perf: base vs head at TP8, hidden 5120, median of 3 runs. Within run-to-run noise:

    tokens base (µs) head (µs)
    512 63.5 65.8
    9216 308.1 309.7
    32768 998.4 999.6
  • Minor: the kernel module docstring (L6) and the comments at L655 / L929 still say E4M3. The divisor-bounds comment in aiter/ops/flydsl/quick_allreduce_int4.py still rests on the old 2^-10 step derivation.

@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

Thanks @TennyWang1223, good catch, and confirmed. Fixed in bf76a90 as you suggested: SCALE_CODEC_TAG = "s5m2b12" sits next to the codec helpers, with a comment saying to bump it on any codec change, and it is part of the launch name, so the cache directory changes with it.

Reproduced and verified on 8× MI355X (gfx950), FlyDSL 0.4.1, with one persistent FlyDSL cache (/root/.flydsl) shared across these steps, in order and without clearing it:

step tree test result cache dirs
1 main 0dd2716 int4 pass creates launch_quick_allreduce_int4_ws{2,4,8}_st{1,8}_<key>
2 main int4 rmsnorm pass creates ..._ws{2,4,8}_st*_rms*_<key>
3 a94f0b3 (before this fix) int4 fail: every-rank-2048 tp=2: SQNR 1.08 dB < 18.0 reuses step 1's dirs, same <key>
4 bf76a90 int4 pass, incl. TP8 divisor (18.83 / 18.84 dB at divisor 1 and 8) new launch_quick_allreduce_int4_s5m2b12_ws* dirs
5 bf76a90 int4 rmsnorm, TP2 pass, 17/17 new ..._s5m2b12_ws2_*_rms* dirs

Step 3 is your repro on gfx950. The fused rmsnorm test on bf76a90 also passes at TP8 (11/11) and TP4 (17/17) on 8× MI350X: fused equals unfused exactly, ranks equal, output SQNR 29.7–30.1 dB at TP8 and 32.7–33.0 dB at TP4.

Also in bf76a90: the module docstring and the comments that still said E4M3 now say scale or E5M2, and the divisor-bounds comment is restated for E5M2 (smallest dequant step 2^-15; at DIVISOR_MIN the restored step is 2^-19, an fp16 subnormal that still holds the 2-bit mantissa exactly). The bounds themselves are unchanged.

Thanks for the gfx942 run and the perf numbers too. I've moved gfx942 to verified in the description.

@TennyWang1223
TennyWang1223 self-requested a review November 4, 2026 10:17
TennyWang1223
TennyWang1223 previously approved these changes Nov 4, 2026

@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

…ger clip

The quick all-reduce codec (mesh and ring, INT4 and INT6) stores each
16-value group's scale as signed E4M3 with bias 7, which spans
[2**-7, 480]. A group whose extremum is above 480 clips to about 480, both
when a rank quantizes its partial and when the reduced sum is requantized;
the ring requantizes at every hop, so sums of a few values near 300 clip
too. MiniMax-M3 all-reduce outputs reach 6400-16800, and vLLM routes BF16
INT4 quick reduce here whenever AITER is on, so MMMU on MI355X drops from
about 0.66 to 0.27-0.31 at TP2/4/8.

Store the scale as E5M2 with bias 12 instead, spanning
[2**-12, 1.75 * 2**19]: same byte, same wire layout, same instruction
count, and every fp16 extremum fits. INT6 divides by 32 instead of 8, so
its smallest scale is floored at 2**-10 to keep the fp16 encode factor
finite (Codec.scale_min_e5). The scale has 2 mantissa bits instead of 3:
INT4 rounds it to nearest and loses about 0.3 dB in-range SQNR; INT6 rounds
it up (Codec.scale_rounds_up), which avoids clipping the group extremum by up
to 1/8 (four INT6 steps) and keeps INT6 at E4M3's SQNR.

The ring requantizes its partial sum at every hop, and at TP4 an all-INT4
ring had only 0.26 dB of margin over the 18 dB floor (18.26 dB with E4M3);
with E5M2 it lands at 17.89 dB. Default the ring's reduce-scatter lap to INT6
from TP4 instead of TP8 (RS_INT6_MIN_WORLD = 4). On PCIe this sends up to
26/18 of the reduce-scatter bytes at TP4; a precision-preserving scale
(per-slice E4M3/E5M2) would let it move back to TP8.

FlyDSL does not hash the codec helpers into its disk cache key, so add
SCALE_CODEC_TAG to both kernels' launch names; without it a warm cache
keeps loading E4M3 binaries.

Tests: the codec tests assert that large extrema no longer clip (instead of
asserting saturation at 480), with the analytic bound widened to the 2-bit
scale mantissa; the op test adds a fill above 480 on every rank for the
mesh and the ring, and the divisor test now requires divisor 1 to reach the
SQNR floor and divisor 8 to cost at most 1 dB. A pinned int6/int4 ring case
runs at TP8.

Signed-off-by: Vorapol Assavasangthong <[email protected]>
@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

@TennyWang1223 @samremes rebased onto #5461, which moved the codec to kernels/comm/quick_allreduce_codec.py (shared by the mesh and the ring, INT4 and INT6), so this needs another look. Same E5M2 change and SCALE_CODEC_TAG, now in the shared codec and in both kernels' launch names. INT4 numbers and speed are unchanged from what you approved.

New since your review:

  • INT6 floors its scale at 2^-10 and rounds it up (Codec.scale_min_e5, Codec.scale_rounds_up). Rounding to nearest cost INT6 2.4 dB; now 33.4 → 33.5 dB vs main.
  • The ring's reduce-scatter lap defaults to INT6 from TP4 (RS_INT6_MIN_WORLD 8 → 4, agreed with @vpietila-amd): an all-INT4 ring at TP4 went from 18.26 to 17.89 dB, under the 18 dB floor; with INT6 it is 21.44 dB.
  • The codec tests that asserted the 480 clip now assert no clip.

Ring correctness was checked on xGMI with the policy forced to plan as PCIe; PCIe (MI350P) performance is not measured (bound and xGMI proxy in the description). Full test list in the description.

@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

@TennyWang1223
TennyWang1223 merged commit 5eccc0c into ROCm:main Nov 4, 2026
eppaneamd added a commit that referenced this pull request Nov 4, 2026
eppaneamd added a commit that referenced this pull request Nov 4, 2026
…odes onto the #5461 mesh kernel

Re-apply the sequence-parallel modes of this PR on the kernel and host that
#5461 rewrote (per-rank binaries, peers-only publish/wait, runtime n_blocks,
inbox memory modes, engines keyed by (super_tile, block)) and on the E5M2 group
scale of #7258.

Kernel (kernels/comm/quick_allreduce_int4.py): make_quick_allreduce_int4_kernel
takes mode="ar" | "rs" | "ag". "rs" and "ag" run one phase of the INT4 mesh on
its own, for super_tile=1, the 8-atom tile and no fused norm. Rank d owns a
contiguous block of N / world_size bytes; the tile machinery is unchanged and
only the HBM address of an atom moves, through a full / shard layout local to the
mesh kernel (_sp_payload_io) with the runtime n_blocks stride. Both modes send
through the all-gather slots and start every round with a payload-free `ready`
flag, since a single phase has no second-phase guard against inbox reuse.
Unlike the all-reduce, which adds its own share from registers, "rs" quantizes
this rank's own partial through the codec and accumulates every rank in rank
order with the same dequant, so a row's value does not depend on which rank owns
it. The JIT symbol gets an `_rs` / `_ag` suffix and the single-phase builds pin
waves_per_eu to the plain kernel's residency.

Host (quick_allreduce_int4.py): reduce_scatter(inp, out), all_gather(inp, out)
and compile_sp(full, shard). They run on the super_tile=1 engine at the default
block (shared inbox and colors) and raise for the ring, an inbox other than
"uncached", or a ladder without that engine. There is no min_bytes floor.
compile_sp now loads both builds with preload_launcher like preload: it checks
the shapes, launches nothing and overwrites nothing, and takes no stream. A
single-phase launch under CUDA graph capture raises unless its build is loaded.
check_tensors is split out of check_payload (same behaviour and signature) for
the pair check.

README documents the modes. The op test imports from kernels.comm and builds its
engine from a one-rung ladder instead of super_tile / grid_cap.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Rony Leppänen <[email protected]>
vpietila-amd added a commit that referenced this pull request Nov 5, 2026
Merged with c3a44c0 (the tip of the already squash-merged #5461 branch) as
the merge base, so only the fused branch's own commits are compared against
main. Resolutions:
- Port #7258 (E5M2 group scale, RS_INT6_MIN_WORLD=4, SCALE_CODEC_TAG) into the
  renamed quick_allreduce{,_mesh,_ring}.py, test_flydsl_quick_allreduce.py and
  allreduce_policy.py.
- Keep both test entries in .github/scripts/split_tests.sh.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
eppaneamd added a commit that referenced this pull request Nov 6, 2026
…he 4 GiB window; fix two stale comments

reduce_scatter and all_gather raise before any launch when the full tensor is
larger than the 4 GiB buffer window, as the all-reduce does; nothing exercised
that check. Add one oversized, uninitialized pair to the refusal cases (whole
tiles, tp times the shard, one step past MAX_PAYLOAD_BYTES): every other check
passes on it, so only the window check can refuse it.

Also: the test's expected-NMSE comment named the E4M3 group scale (the codec has
the E5M2 scale since #7258), the ranged-fill comment said a sum of similar
magnitudes is exact (it rarely rounds), and a host comment named a method that
does not exist (sp_launch for _sp_launcher).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Rony Leppänen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants