Skip to content

[FlyDSL] QuickAllReduce INT4/INT5/INT6: fp32 divisor and pair-shared-exponent group scales - #7326

Draft
samremes wants to merge 1 commit into
mainfrom
samremes/qr-int4-fp32-divisor
Draft

samremes wants to merge 1 commit into
mainfrom
samremes/qr-int4-fp32-divisor

Conversation

@samremes

@samremes samremes commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Rewritten as one commit on main 0f8e5c18dc; the previous seven-commit
history (head a01ac33120, kept at
samremes/aiter:samremes/qr-int4-fp32-divisor-v1-formatbit) conflicted with
main and is replaced.

  1. Pair-shared-exponent (PSE) group scale for INT4, INT5 and INT6, on the
    mesh and the ring. It replaces E5M2 and the previous revision's per-slice
    E4M3/E5M2 format bit, which needed out-of-band metadata.
  2. fp32 divisor: the plain all-reduce's opt-in divisor divides each bf16
    load in fp32 before the fp16 narrowing and multiplies the result back in
    fp32 before the bf16 store, so values up to 65504 * divisor survive. It
    now works on the mesh and the ring with every wire format.

Wire layout and size, defaults, divisor bounds [1/16, 128] and the public
API are unchanged.

Motivation

  • Precision. E5M2 has a 2-bit mantissa: a group's scale can sit up to
    ~25% above its extremum, costing ~0.4 dB on every input. E4M3 is finer but
    caps at 480.
  • Range. On main the divisor is applied after the bf16→fp16 conversion
    and folded into the fp16 dequant, so no divisor lifts the 65504 ceiling. It
    is also mesh/INT4-only.
  • Cost of the previous fix. The per-slice format bit restored E4M3
    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

  • Scale format. Each 16-bit scale half-word holds two adjacent groups:
    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 the
    two 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**-11 and 2**-10. Cache tag: pse3b12.
  • Divisor. Plain epilogue bind(divisor=...): f32 divide on load and f32
    multiply on store, on mesh and ring (has_divisor=True for the ring). The
    fused kernels keep divisor 1, and the fused host API is unchanged.
  • Docs. Kernel and host docstrings and kernels/comm/README.md
    (accuracy limits, divisor) are updated.

Performance (if applicable)

MI355X (gfx950), xGMI, FlyDSL 0.5.3. Main 0f8e5c18dc against this change,
using the canonical bench (--scenario bench) in 4 interleaved main/PR
rounds. 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).

Hardware Workload/configuration Before After Change
MI355X ×2 plain mesh, 64/256/8192 × 4096 11.26 / 19.25 / 369.21 µs 11.07 / 19.17 / 369.02 µs geomean −0.7%
MI355X ×4 plain mesh, 48/256/8192 × 4096 10.56 / 15.49 / 199.71 µs 10.49 / 15.42 / 200.01 µs geomean −0.3%
MI355X ×8 plain mesh, 48/256/1537/8192 × 4096 11.15 / 13.58 / 37.67 / 119.43 µs 11.06 / 13.52 / 37.60 / 119.58 µs geomean −0.3%
MI355X ×4 plain ring, 64×4096 … 16384×8192 (5 shapes)¹ 22.36 … 2580.03 µs 22.34 … 2581.54 µs geomean +0.05%
MI355X ×8 plain ring, 64×4096 … 16384×8192 (5 shapes)¹ 36.30 … 3076.63 µs 36.16 … 3068.66 µs geomean −0.1%
MI355X ×4 fused add+RMSNorm mesh, hidden 4096/8192 (12 shapes) −1.9% … +0.1%
MI355X ×4 fused add+RMSNorm mesh, hidden 7168 (7 shapes) 8192×7168: 467.12 µs 455.72 µs −2.4% … −6.0%
MI355X ×8 fused add+RMSNorm mesh, hidden 4096/8192 (12 shapes) −4.7% … −0.4%
MI355X ×8 fused add+RMSNorm mesh, hidden 7168 (7 shapes) 8192×7168: 352.31 µs 301.94 µs −10.2% … −14.5%
MI355X ×4 / ×8 fused add+RMSNorm ring, all 19 shapes geomean −1.2% / −1.0%

¹ 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_eu hint caps allocation at 128 VGPRs, and both trees spill
there. 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

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

MI355X (gfx950) only. gfx942 was compiled for register analysis but not run
(see below).

Documentation

  • Docstrings updated
  • User guide updated (aiter/ops/flydsl/kernels/comm/README.md)
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

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

aabf075857

Behavior and intent

  • Scale. The quantized all-reduce's group scale moves from E5M2 to an
    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.
  • Divisor. The divisor moves to fp32 around the fp16 math, so it extends
    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:

  1. Non-monotonic scale below the floor: fixed by construction. The scale is
    max(round(ext), floor) on the scale code, so it is monotonic in the group
    extremum.
  2. Poll only the format words: moot. There is no format metadata any more.
  3. INT6 checked against the INT4 floor: the scale-range test now uses named
    per-codec floors (MESH_PINNED_SQNR_MIN_DB int5 23 / int6 29,
    RING_INT6_SQNR_MIN_DB 25) and per-fill CHANNEL_OUTLIERS_SQNR_MIN_DB.
    INT5 is covered too.
  4. Stale "one store" / "64 B tail" / "+ 64" docstrings: the multi-sector
    tail is gone. The remaining + 64 in inbox_bytes is main's ring
    handshake 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:

python -m pytest -q op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py
python op_tests/multigpu_tests/test_flydsl_quick_allreduce.py --scenario verify --operation ar --tp 2 4 8 --extended
python op_tests/multigpu_tests/test_flydsl_quick_allreduce.py --scenario verify --operation ar_rmsnorm --tp 2 4 8 --extended
  • Codec suite on aabf075857: 199 passed.
  • Plain extended verify at TP2/TP4/TP8: passed. Minimum SQNR is 20.45, 19.79
    and 19.46 dB.
  • Fused add+RMSNorm extended verify at TP2/TP4/TP8: passed.
  • The multi-GPU runs used the worktree before it was committed. Its kernel
    and host code match aabf075857. Later edits only set the
    channel_outliers floors from these measurements and fixed a docstring.
  • NaN/Inf inputs give finite, rank-identical output (probe).
  • Scale-range minima (whole-payload SQNR, divisor 1):
fill / path TP2 TP4 TP8
mesh int4 normal 20.45 19.80 19.46
mesh int5 normal 26.13 25.47 25.12
mesh int6 normal 32.15 31.49 31.14
mesh int5 channel_outliers 24.41 23.73 23.46
mesh int6 channel_outliers 29.36 28.70 28.39
ring int4/int4 normal 20.46 18.26 15.71
ring int6/int4 normal 22.07 21.81 21.29
ring int6/int6 normal 32.15 29.93 27.36
ring int6/int6 channel_outliers 29.33 27.35 25.06
  • 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.
  • Quiet rows next to massive-token outliers (mesh): at least 19.48 dB, against
    a floor of 19.
  • Register use is compile-only on gfx942 and gfx950. Most plain mesh rungs
    use fewer VGPRs; no shipping rung loses needed residency.

Unverified:

  • gfx942, and any hardware other than MI355X, was not run.
  • PCIe was not measured. The ring was timed on xGMI with borrowed gfx942
    rungs, because gfx950 xGMI has no ring ladder.
  • The fused speed-up is attributed to fewer spills from static ISA, not
    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_group
checks 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 and
    decode of every codec, checked against an independent CPU model of the PSE
    scale (test_matches_pair_shared_exponent_model), the shared-exponent gap
    rule, 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: adds
    test_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.

@github-actions

github-actions Bot commented Nov 2, 2026

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 7326 --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 Nov 2, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision a01ac33120b5 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/flydsl_tests/test_flydsl_quick_allreduce_codec.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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 added the ci:multi-gpu Trigger multi-GPU op tests on PR label Nov 2, 2026
@samremes samremes changed the title [FlyDSL] QuickAllReduce INT4: apply the divisor in fp32 so values above fp16 survive [FlyDSL] QuickAllReduce INT4: fp32-side divisor and per-slice E4M3/E5M2 group scale Nov 2, 2026
@samremes

samremes commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

ROCm/aiter PR #7326 — [FlyDSL] QuickAllReduce INT4: fp32-side divisor and per-slice E4M3/E5M2 group scale

Moves 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): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled) and this box cannot run the multi-GPU target (flydsl not installed here, torch sees 0 usable devices, all 8 GPUs at 98% VRAM); the target existed: op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py
Perf (advisory): NOT RUN — same environment gap (no usable GPU or flydsl on this box); the PR's own MI355X base-vs-head tables are the only perf evidence (fp32 divisor: noise to +0.2%; format bits: +2.7% on TP4 512×5120 decode, within 1% on prefill and fused shapes; TP8 with format bits unmeasured)

⚠️ [verified] The residency audit behind the new _PINNED_PLAIN = {(4, 8)} pin (aiter/ops/flydsl/kernels/quick_allreduce_int4.py:70) is gfx950-only, and on gfx942 the PR reports VGPRs for that one build alone (159 unpinned, against the ~102 that 5 workgroups/CU requires) while every other plain build stays unpinned on an arch those same numbers show allocating far past gfx950 for identical code — if any of them exceeds its _RESIDENT_WGS_PER_CU budget on gfx942, the host launches more workgroups than are co-resident and the release pollers spin forever, hanging every TP config on a supported arch the PR never ran. Author must report the gfx942 VGPR allocation for every plain build (or pin them like (4,8)) and run the gfx942 op test before merge.
⚠️ [verified] TP8 — the kernel's default world size — was never run with the format-bit commits, and the TP8 ST8 release-word packing (8 format bits per wave, 2 waves per word, 2 words) is a layout no TP2/TP4 run can produce (TP4 ST8 packs one wave per word across 4 words; TP2 ST8 uses the over-16-bit two-chunk-per-wave shape), so a packing bug there reaches the production config as a poller hang or a silently wrong format decode. Author must let the added ci:multi-gpu label's TP8 validity and divisor sections of op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py run and pass before merge, or run them on 8 idle GPUs.
⚠️ [verified] The PR changes the fused add+RMSNorm path (_norm_store_tile_atoms' fp32 restore, aiter/ops/flydsl/kernels/quick_allreduce_int4.py:873) and compiles the format-bit transport into the 12-atom WIDE builds, but its test changes cover only the plain 8-atom path — op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py, the only test that runs allreduce_rmsnorm and the only one that can produce the WIDE layout (48 format bits per wave, 2-word LDS records, 3 chunks per wave at TP2 hidden 6144 ST8), is untouched and never stated as run. Author must confirm that test passed on this branch; the PR's fused perf rows are 4096-hidden 8-atom builds and do not cover it.
📝 [verified] _load_i32_uncached (aiter/ops/flydsl/kernels/quick_allreduce_int4.py:302) lost both its callers to the new _load_release/_release_seen spin and is now dead code. Author must delete it or state why it stays.

@samremes

samremes commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. All four findings are on this PR's own commits; none touches #7258's three commits (#7258 changes no VGPR allocation). Addressed in 4dc24b69bd ([FlyDSL] QuickAllReduce INT4: pin plain ST8 builds to their residency):

  1. gfx942 residency. Compile-only VGPR allocation for every plain build, on both archs, against main, [FlyDSL] QuickAllReduce INT4: E5M2 group scale so groups above 480 no longer clip #7258 and the fp32-divisor commit, is now in the PR description under Residency. Short version:
    • ST8 builds loop over several tiles per workgroup, so their grid must be co-resident. TP2 and TP4 ST8 are now pinned (gfx942 TP4 ST8 was 159 VGPRs on the fp32-divisor commit). TP8 ST8 holds 5 workgroups per CU on both archs, which covers the default 1216 grid. Its table value of 6 was already unreachable on main (82 VGPRs on gfx950), and gfx942 main is at 141 VGPRs, 3 per CU.
    • ST1 builds stay unpinned. Under the default super-tile, ST1 only runs when the payload has at most grid tiles, one tile per workgroup. Workgroups past residency start as a second wave, and no workgroup waits on a later workgroup of its own rank, so this is not a hang. Pinning TP4 ST1 was measured on gfx950: 20 B spill, 1.5% slower at 320 tiles and 3.2% slower at 960 tiles, where the unpinned grid is 192 workgroups past residency.
    • gfx942 at runtime is still unverified: no MI300X here, and the ci:multi-gpu job runs on MI350X.
  2. TP8. Both multi-GPU op tests passed on 8 idle MI355X with default arguments (TP8, TP4 and TP2 sections), on 98597510dd and on the pinned variant. Every build of the head is byte-identical in ISA to one of those two. TP8 in-range rows are 19.21–20.02 dB, and the above-fp16 fill is 33.86 dB at divisor 8 on both ST paths. TP8 timing is in the description: plain prefill −2.6%, fused within 2.4% (noise).
  3. Fused test. op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4_rmsnorm.py passes at TP8, TP4 and TP2, including the 6144-hidden wide builds at TP4 (33.3 dB) and TP2 (36.3 dB).
  4. Dead code. _load_i32_uncached is removed.

@samremes
samremes force-pushed the samremes/qr-int4-fp32-divisor branch from 4dc24b6 to f39e3bb Compare November 4, 2026 16:04
@samremes samremes changed the title [FlyDSL] QuickAllReduce INT4: fp32-side divisor and per-slice E4M3/E5M2 group scale [FlyDSL] QuickAllReduce INT4/INT6: fp32 divisor and adaptive group scales Nov 4, 2026
@samremes
samremes force-pushed the samremes/qr-int4-fp32-divisor branch from f39e3bb to a01ac33 Compare November 4, 2026 18:03
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)

@msaffari-amd msaffari-amd Nov 10, 2026 •

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.

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:

Suggested change
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?

Comment on lines +979 to +989
# 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)

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.

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?

Suggested change
# 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.

Comment on lines +1680 to +1684
floor = (
SQNR_MIN_DB_TP8_INT4_RING
if algorithm == "ring" and rs_codec == "int4" and tp >= 4
else SQNR_MIN_DB
)

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.

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:

Suggested change
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):

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.

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]>
@samremes
samremes force-pushed the samremes/qr-int4-fp32-divisor branch from a01ac33 to aabf075 Compare November 27, 2026 16:19
@samremes samremes changed the title [FlyDSL] QuickAllReduce INT4/INT6: fp32 divisor and adaptive group scales [FlyDSL] QuickAllReduce INT4/INT5/INT6: fp32 divisor and pair-shared-exponent group scales Nov 27, 2026

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants