Repository navigation
[FlyDSL] QuickAllReduce INT4: add a shared global divisor to avoid E4M3 scale saturation - #6049
Conversation
…M3 scale saturation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Validation permits fp16-unsafe divisors, and the new behavior lacks automated coverage.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds caller-controlled scaling to prevent E4M3 saturation in FlyDSL INT4 QuickAllReduce.
Changes:
- Adds divisor validation and runtime launch plumbing.
- Applies reciprocal scaling before quantization and restores scaling during dequantization.
| File | Description |
|---|---|
aiter/ops/flydsl/quick_allreduce_int4.py |
Exposes and validates the divisor. |
aiter/ops/flydsl/kernels/quick_allreduce_int4.py |
Implements scaling across both kernel paths. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
samremes
left a comment
There was a problem hiding this comment.
LGTM. Maybe add a test-case that covers a non-unit scale, like Copilot mentioned.
…utlier divisor test
TennyWang1223
left a comment
There was a problem hiding this comment.
Review summary
1. PR description is out of date
- The description says the range is
[2^-14, 2^14], but the code caps it atDIVISOR_MAX = 128(df8abcb). - The description says the test uses "divisor 16 ≥ 18 dB / gain ≥ 3 dB", and the results table has an "Outlier fill, divisor 16" row. The test actually uses
DEFAULT_DIVISOR(8). - Please re-run on the current HEAD and update the results.
2. Not enough evidence to change the default to 8
- The only metric is global SQNR, and large values dominate it. The cost of divisor 8 falls on small values: groups whose max is below ~0.06 lose precision, and values below ~0.004 become zero. Global SQNR hides exactly this kind of loss. Small-magnitude tokens are
common in decode, early layers, ando_proj/down_projoutputs. - Suggestion, either:
- add end-to-end accuracy (lm-eval/gsm8k) or per-token/per-layer SQNR before switching the default, or
- keep the default at 1 and make the divisor opt-in, so existing callers don't get different numbers without being told.
- Please add a small-magnitude test (e.g. std 0.005 at the default divisor). Right now every codec edge case runs at
divisor=1, so small values are never tested on the default path.
3. Divisor must match on every rank, but nothing checks it
If one rank passes a different divisor, there is no error. Ranks silently end up with different outputs and TP state diverges. Please document that this is the caller's responsibility, or add a debug-mode all-reduce check.
If I've got any of this wrong, please reply and correct me. Thanks!
…o [1/16, 128], add small-magnitude test
@TennyWang1223
|
|
It seems this PR improves KimiK3 accuracy on long context of needle in a haystack task. KimiK3 on lm_eval NIAH with HIP QR: with FlyDSL QR without this PR: with FlyDSL QR + this PR: |
# Conflicts: # aiter/ops/flydsl/kernels/quick_allreduce_int4.py # aiter/ops/flydsl/quick_allreduce_int4.py
Hi @TennyWang1223, merging main to fix a conflict dismissed your approval. Our changes are the same, and all tests pass. Could you re-approve? Thanks! |
|
@TennyWang1223 Could you please take the first review of the communication semantics for the current head? @coderfeli, please continue to cover the FlyDSL-specific implementation. I will co-review the AITER integration after those passes, including whether the merge-main only dismissed the previous approval or introduced a material behavior change. For reference, my preliminary pass did not find a remaining correctness blocker in the shared-divisor implementation; the earlier FP16-range, restoration-overflow, and subnormal concerns appear addressed. This is the closest of the communication PRs to approval. The current head also contains later fused RMSNorm and RMSNorm+MXFP4 changes. Please confirm on the current head that |
@zufayu Thanks for the review. Checked on the current head, TP 8, divisor=1: Numerics: plain, fused RMSNorm and RMSNorm+MXFP4 outputs are bit-identical to main on all 8 ranks, and the RMSNorm test passes with the same SQNR. |
|
@zufayu reviewed communication semantics, LGTM |
…isor (#6049) Port the divisor from the old quick_allreduce_int4 files to the renamed mesh kernel, FlyQuickAllReduce host and consolidated test. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Replaces the parked block with the eight branches it named, each pinned by SHA, and sets AITER_GPU_TARGETS=gfx950:128 so the AOT kernels are built for MI350P's 4 XCDs rather than the 8 a bare gfx950 implies. The fetch gains forcing refspecs for relbers/* and mi350p-tuning, which get force-pushed and would otherwise be left stale by a fetch that still exits 0. WITH_ALLREDUCE=0 merges clean onto AITER_MAIN: tree 4b3be64cbc4e65987e72cdfac58d9b77e90ae421, 15 MI350P config files, 753 rows. WITH_ALLREDUCE=1 stops on a modify/delete, which is left to reconcile rather than resolved here. flydsl-fused-comm-kernels deletes aiter/ops/flydsl/quick_allreduce_int4.py, its kernels/ counterpart and their op_test, having rewritten that path under kernels/comm/; main modifies the same three files in 41d4d8d (#6049). AITER_MAIN is pinned at the comm branch's own merge-base, so the MI350P branches carry main past that commit and the deletion meets the edit. None of the eight touches those files, so rebasing the comm branch onto the main AITER_MAIN names clears it.



Motivation
QuickReduce INT4 stores one E4M3 scale per group of 16 values, and E4M3 cannot go above 480. Activations with large outliers saturate that scale, values clip, and the all-reduce loses accuracy.
This PR adds an optional global divisor
s, the same on every GPU. Inputs are divided bysbefore quantization and the result is multiplied bysonce at the end, so values stay inside the codec's range:(a / s) + (b / s) = (a + b) / s.The default is 1, so existing callers get exactly the same result. For models with outliers, 8 is the recommended opt-in value, based on six sample models at TP 8. It is not the default because it costs accuracy on small-magnitude inputs.
Technical Details
Host:
aiter/ops/flydsl/quick_allreduce_int4.pyallreduce(inp, out, stream=None, divisor=1.0). Existing positional calls keep working._check_divisoraccepts finite values in[1/16, 128], so the fp16 restore stays a normal fp16. Anything else raisesValueError.divisoris a runtimeFloat32kernel argument, so changing it does not recompile.Kernel:
aiter/ops/flydsl/kernels/quick_allreduce_int4.pyfp16(1/s), before the group max and the E4M3 byte._codec_quantand the second pack are unchanged.sis folded into the all-gather dequant scale, so the sum is multiplied bysonce before the bf16 write.super_tile == 1andsuper_tile > 1paths are covered.divisor=1, the output is bit-identical to the previous kernel.Out of scope: choosing
sfrom the live tensor, vLLM wiring, and the HIP QuickReduce kernel.Test Plan
op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.pyon 8× MI355X (gfx950):Test Result
Test suite: passes.
Sample models, TP 8 (SQNR, divisor 1 → 8)
Divisor 8 recovers every input that clips, leaves the others unchanged, and no token gets worse in per-token SQNR.
Small-magnitude cost (why the default stays 1)
Performance: old and new kernels run at the same speed, at divisor 1 or 8, for prefill (32768 × 5120), 9216 × 5120 and decode (512 × 5120). The differences are within measurement noise.
Submission Checklist