Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
@aiter-bot review |
ROCm/aiter PR #7326 — [FlyDSL] QuickAllReduce INT4: fp32-side divisor and per-slice E4M3/E5M2 group scaleMoves the QuickAllReduce INT4 divisor to the fp32 side of the fp16 codec math so reduced sums up to 65504×divisor survive the fp16 ceiling, and picks the 16-value group scale's format per 512-value wave slice (E4M3 where the slice fits it, E5M2 otherwise), shipping the per-slice format bits through the release sector the receiver already polls. Review (advisory):
|
|
Thanks. All four findings are on this PR's own commits; none touches #7258's three commits (#7258 changes no VGPR allocation). Addressed in
|
4dc24b6 to
f39e3bb
Compare
f39e3bb to
a01ac33
Compare
| rounding = fx.Int32(1) << (shift - fx.Int32(1)) | ||
| rounded = (abs(x).bitcast(fx.Int32) + rounding).shrui(shift) | ||
| magnitude = rounded - offset | ||
| magnitude = (magnitude < 0).select(rounded & mantissa_mask, magnitude) |
There was a problem hiding this comment.
Minor, non-blocking: when the group max is below the format's minimum scale, this keeps the value's own mantissa bits, so the scale lands anywhere in [1, 1.875]x the minimum and isn't monotonic (max 0.0035 gets 0.0137, max 0.0039 gets 0.0088). Using mantissa 0 always gives the smallest legal scale, and the byte == 0 -> 1 guard below still keeps it safe:
| magnitude = (magnitude < 0).select(rounded & mantissa_mask, magnitude) | |
| magnitude = (magnitude < 0).select(fx.Int32(0), magnitude) |
If you take this, please also bump SCALE_CODEC_TAG. Could you also add a short comment on why E4M3_SLICE_MIN is 2^-6 rather than the E4M3 minimum 2^-7?
| # Every metadata word must carry this epoch: observing the first | ||
| # word alone cannot rule out a partially updated release sector. | ||
| n_poll = n_push * metadata.release_i32 | ||
| for rnd in range_constexpr((n_poll + block - 1) // block): | ||
| slot = tid + fx.Int32(rnd * block) | ||
| if slot < n_poll: | ||
| spin_src = slot // fx.Int32(metadata.release_i32) | ||
| spin_src = (spin_src >= self_rank).select( | ||
| spin_src + fx.Int32(1), spin_src | ||
| ) | ||
| word = slot % fx.Int32(metadata.release_i32) |
There was a problem hiding this comment.
Only the first format_words words carry format bits, and decode never reads past them. Every flag store follows the release fence, so any word with the current epoch already orders the payload (main polls only word 0). The epoch-only words therefore don't need polling or caching. This is a simplification rather than a big win, since the 16 words share one 64 B line, but it drops the extra lanes, the second polling wave at TP8 and the extra LDS stores. Could you consider it?
| # Every metadata word must carry this epoch: observing the first | |
| # word alone cannot rule out a partially updated release sector. | |
| n_poll = n_push * metadata.release_i32 | |
| for rnd in range_constexpr((n_poll + block - 1) // block): | |
| slot = tid + fx.Int32(rnd * block) | |
| if slot < n_poll: | |
| spin_src = slot // fx.Int32(metadata.release_i32) | |
| spin_src = (spin_src >= self_rank).select( | |
| spin_src + fx.Int32(1), spin_src | |
| ) | |
| word = slot % fx.Int32(metadata.release_i32) | |
| # Every word that carries format bits must have this epoch: | |
| # observing the first word alone cannot rule out a torn sector. | |
| n_poll = n_push * metadata.format_words | |
| for rnd in range_constexpr((n_poll + block - 1) // block): | |
| slot = tid + fx.Int32(rnd * block) | |
| if slot < n_poll: | |
| spin_src = slot // fx.Int32(metadata.format_words) | |
| spin_src = (spin_src >= self_rank).select( | |
| spin_src + fx.Int32(1), spin_src | |
| ) | |
| word = slot % fx.Int32(metadata.format_words) |
The ring _wait (tid < metadata.release_i32) can use format_words the same way.
| floor = ( | ||
| SQNR_MIN_DB_TP8_INT4_RING | ||
| if algorithm == "ring" and rs_codec == "int4" and tp >= 4 | ||
| else SQNR_MIN_DB | ||
| ) |
There was a problem hiding this comment.
INT6 is checked against the same 18 dB floor as INT4, but measures about 29-32 dB here (TP2: normal 32.1, tiny 31.7, channel_outliers 29.3). An INT6 regression in the round-up or floor path would pass unnoticed. After rebasing on main, the per-codec MESH_PINNED_SQNR_MIN_DB from #5555 could be reused, which also covers INT5:
| floor = ( | |
| SQNR_MIN_DB_TP8_INT4_RING | |
| if algorithm == "ring" and rs_codec == "int4" and tp >= 4 | |
| else SQNR_MIN_DB | |
| ) | |
| floor = ( | |
| SQNR_MIN_DB_TP8_INT4_RING | |
| if algorithm == "ring" and rs_codec == "int4" and tp >= 4 | |
| else MESH_PINNED_SQNR_MIN_DB.get(rs_codec, SQNR_MIN_DB) | |
| if algorithm == "mesh" | |
| else SQNR_MIN_DB | |
| ) |
channel_outliers is only 0.3 dB above the INT6 floor at TP2, so please check its margin at TP4/TP8. The ring INT6 rows could get their own floor the same way. Also, could the quiet-token 19.0 below become a named constant?
| _store_flag_peer( | ||
| _push_base(safe) + _i32_to_bytes(elem), color, flag_policy | ||
| ) | ||
| for sector in range_constexpr(metadata.release_i32 // 16 - 1, -1, -1): |
There was a problem hiding this comment.
Nit: with a multi-sector tail this is one store per sector, so the docstring line above ("the whole handshake is one store instruction from wave 0") is no longer always true. Same for the ring's "64 B tail" comment on flags_bytes and the "+ 64" in the host inbox_bytes docstring.
…ivisor Replace the E5M2 group scale with an in-band pair-shared-exponent scale: each 16-bit word holds two adjacent groups' scales, a 5-bit exponent with a 3-bit mantissa for the first and a 6-bit exponent offset for the second, plus their signs. It keeps E5M2's range [2**-12, 1.875 * 2**19] with three mantissa bits instead of two and needs no per-slice format metadata, ballots or second encode. INT4 rounds the scale to nearest; INT5 and INT6 round up with their 2**-11 and 2**-10 floors. The wire layout and size are unchanged. Apply the plain all-reduce's divisor in fp32: divide every bf16 load before the fp16 narrowing and multiply every store back before the bf16 conversion, so magnitudes up to 65504 * divisor survive. The divisor now works on the mesh and the ring with every wire format; the fused kernels keep divisor 1. Tests: a CPU oracle for the scale encoding and every codec round trip; the multi-GPU scale-range test covers normal, tiny, channel-outlier, massive-token and above-fp16 fills on the mesh (INT4/5/6) and the ring (INT4, INT6, INT6/INT4), with named per-codec and per-fill SQNR floors. Co-authored-by: Copilot <[email protected]>
a01ac33 to
aabf075
Compare
Summary
Rewritten as one commit on main
0f8e5c18dc; the previous seven-commithistory (head
a01ac33120, kept atsamremes/aiter:samremes/qr-int4-fp32-divisor-v1-formatbit) conflicted withmain and is replaced.
mesh and the ring. It replaces E5M2 and the previous revision's per-slice
E4M3/E5M2 format bit, which needed out-of-band metadata.
load in fp32 before the fp16 narrowing and multiplies the result back in
fp32 before the bf16 store, so values up to
65504 * divisorsurvive. Itnow works on the mesh and the ring with every wire format.
Wire layout and size, defaults, divisor bounds
[1/16, 128]and the publicAPI are unchanged.
Motivation
~25% above its extremum, costing ~0.4 dB on every input. E4M3 is finer but
caps at 480.
and folded into the fp16 dequant, so no divisor lifts the 65504 ceiling. It
is also mesh/INT4-only.
precision, but its ballots, second encode and metadata polling cost up to
+3.3% (TP8 small plain) and +2.3–2.5% (ring). PSE keeps the precision
in-band and needs none of that.
Changes
group A as a 5-bit exponent (bias 12) and a 3-bit mantissa, group B as a
6-bit offset (exponent within A−4…A+3, plus mantissa), and both signs. The
range stays
[2**-12, 1.875 * 2**19], so no fp16 extremum clips. When thetwo exponents are too far apart, the smaller scale is raised and only that
group loses mantissa bits. INT4 rounds the scale to nearest; INT5 and INT6
round up, with floors
2**-11and2**-10. Cache tag:pse3b12.bind(divisor=...): f32 divide on load and f32multiply on store, on mesh and ring (
has_divisor=Truefor the ring). Thefused kernels keep divisor 1, and the fused host API is unchanged.
kernels/comm/README.md(accuracy limits, divisor) are updated.
Performance (if applicable)
MI355X (gfx950), xGMI, FlyDSL 0.5.3. Main
0f8e5c18dcagainst this change,using the canonical bench (
--scenario bench) in 4 interleaved main/PRrounds. Each cell is the median of per-round medians; ratio = PR / main
(below 1 is faster). The HIP reference baseline in the same runs is the drift
control (geomean ratio 0.998–1.000).
¹ No production ring ladder exists for gfx950 xGMI, so these runs
temporarily copied the gfx942 xGMI ring rungs into the policy (a
measurement-only import hook). Both trees ran the same rungs.
The hidden-7168 fused gain comes from register spilling. Block 896 is 14 waves,
so the
waves_per_euhint caps allocation at 128 VGPRs, and both trees spillthere. This change spills less (compile-only, rank 0: TP8 ST1 70 → 58 spilled
VGPRs, scratch 284 → 236 B; TP8 ST8 95 → 73). The spills themselves are on
main and stay out of scope.
The bench SQNR on its normal fill is 0.34–0.42 dB higher on every shape
(TP8 plain mesh 19.11–19.12 → 19.46–19.50 dB, TP8 fused mesh about
20.87 → 21.25 dB, TP8 fused ring about 22.69 → 23.06 dB).
Testing
MI355X (gfx950) only. gfx942 was compiled for register analysis but not run
(see below).
Documentation
aiter/ops/flydsl/kernels/comm/README.md)Dependencies
Breaking Changes
None. Outputs at divisor 1 change numerically, because the group scale is
more precise. Every rank must run the same software, as before. A divisor
other than 1 is now accepted on the ring and on INT5/INT6, where it used to
raise.
PR Self-Review
Reviewed revision
aabf075857Behavior and intent
in-band pair-shared-exponent float. This recovers E4M3-like 3-bit mantissa
precision without E4M3's 480 cap and without per-slice metadata. In a CPU
simulation of the real codecs (INT4 normal fill), E5M2 gives 21.82 dB, the
format bit 22.23 and PSE 22.23. On outlier-heavy fills PSE beats both:
massive tokens 25.90 / 25.90 / 30.04 dB, every-row 6k channel outliers
20.99 / 21.04 / 21.84 dB. Only PSE costs nothing at run time.
the range to
65504 * divisor. On main it cannot lift the fp16 ceiling.It is extended to the ring and to every codec.
Review items on the previous revision:
max(round(ext), floor)on the scale code, so it is monotonic in the groupextremum.
per-codec floors (
MESH_PINNED_SQNR_MIN_DBint5 23 / int6 29,RING_INT6_SQNR_MIN_DB25) and per-fillCHANNEL_OUTLIERS_SQNR_MIN_DB.INT5 is covered too.
tail is gone. The remaining
+ 64ininbox_bytesis main's ringhandshake tail and is correct.
On the bot's residency finding: compile-only VGPRs on gfx942 and gfx950 show
no shipping rung below the residency it needs. Every gfx942 rung caps its
grid at 128 (below 304 CUs), and gfx950 TP4 ST1 block 256 keeps 4 waves
(INT4, 122 VGPRs; main 127).
Validation and unverified scope
MI355X (gfx950), ROCm 10.1, torch 2.14, FlyDSL 0.5.3 (pinned), with fresh
FlyDSL caches:
aabf075857:199 passed.and 19.46 dB.
and host code match
aabf075857. Later edits only set thechannel_outliersfloors from these measurements and fixed a docstring.above_fp16(values beyond fp16) at divisor 8 gives 19.2–42.2 dB,depending on the codec and TP. At divisor 1 it saturates (1.9–2.5 dB), as
expected, and the output stays finite.
a floor of 19.
use fewer VGPRs; no shipping rung loses needed residency.
Unverified:
rungs, because gfx950 xGMI has no ring ladder.
profiled.
PR-specific question
Is the pair-shared exponent safe when two adjacent groups differ by more than
the 4/3-binade offset? Yes. The larger group keeps its own exact scale. The
smaller one is raised to the nearest representable value, so it never clips
and only loses mantissa bits.
test_shared_exponent_coarsens_only_the_smaller_groupchecks this against a CPU model at every gap. The mesh quiet-row check in
the multi-GPU test covers the same property end to end: at least 19 dB on the
rows next to massive-token outliers, 19.48 dB measured.
Changed op tests
op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py: GPU encode anddecode of every codec, checked against an independent CPU model of the PSE
scale (
test_matches_pair_shared_exponent_model), the shared-exponent gaprule, the scale floors, no clipping past fp16, and INT5 accuracy between
INT4 and INT6. Before this
PR these tests modeled E5M2 and would fail on the new scale. Nothing else
checks the scale encoding bit for bit; the multi-GPU tests see only an
aggregate SQNR.
op_tests/multigpu_tests/test_flydsl_quick_allreduce.py: addstest_quick_allreduce_scale_range. It runs normal, tiny, channel-outlier,massive-token and above-fp16 fills on the mesh (INT4/5/6) and the ring
(INT4, INT6, INT6/INT4), at divisors 1 and 8, with per-codec and per-fill
floors, plus a check of the quiet rows next to outliers. Before this PR,
above-fp16 at divisor 8 saturates on main, INT6 regressions passed the
18 dB INT4 floor, and a divisor on the ring raised. The existing verify
cases use one fill at divisor 1 and do not cover these ranges.