Repository navigation
[FlyDSL] QuickAllReduce INT4: E5M2 group scale so groups above 480 no longer clip - #7258
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
samremes
left a comment
There was a problem hiding this comment.
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-2048is 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:
- 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.
- 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.
- #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.
|
Thanks @samremes, especially for the TP8 coverage via #7326. On the notes:
|
|
@aiter-bot review |
[ROCm/aiter] PR #7258 — [FlyDSL] QuickAllReduce INT4: E5M2 group scale so groups above 480 no longer clipRe-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):
|
|
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.
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.
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
left a comment
There was a problem hiding this comment.
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.pystill rests on the old 2^-10 step derivation.
|
Thanks @TennyWang1223, good catch, and confirmed. Fixed in bf76a90 as you suggested: Reproduced and verified on 8× MI355X (gfx950), FlyDSL 0.4.1, with one persistent FlyDSL cache (
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 Thanks for the gfx942 run and the perf numbers too. I've moved gfx942 to verified in the description. |
…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]>
bf76a90 to
662b23c
Compare
|
@TennyWang1223 @samremes rebased onto #5461, which moved the codec to New since your review:
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. |
…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]>
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]>
…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]>
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: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_WORLD8 → 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 filllarge_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:
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.AITER_FLY_AR_LINK=pcie); the traffic still goes over xGMI, so this checks numerics and control flow, not PCIe speed.--extendedpasses; 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_rankon the ring at TP8 exact; pinned TP8 int4/int4 15.33 dB (floor 15.0).rs_codec="int4".s5m2b12binaries and passes. Before the tag, the previous head reused main's binaries and failedevery-rank-2048at 1.08 dB.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_TAGin 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:
large_every_rankand the divisor cases; speed equal to main (median 0.999 over 7 rows).--extendedand the fused rmsnorm op test (8× MI350X): pass.--extendedpasses; ring TP4 21.44 dB, TP8 20.89–21.01 dB.s5m2b12binaries 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):
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_ranksets 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.test_extremum_near_e4m3_ceiling_saturates,..._past_e4m3_ceiling_saturates_monotonically) asserted the clip; they are replaced bytest_large_extremum_does_not_clip, which cannot pass with E4M3: main's own test asserts those extrema decode to at most 481.So the canonical tests encoded the clipping instead of rejecting it.
Changed op tests
op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py: filllarge_every_rank(mesh TP2, ring TP8); divisor assertion replaced (same cases); pinned ring caseint6/int4at TP8.op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py:test_ring_codec_defaults_widen_from_tp4expects 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.