Skip to content

[FlyDSL] QuickAllReduce INT4: add a shared global divisor to avoid E4M3 scale saturation - #6049

Merged
msaffari-amd merged 8 commits into
mainfrom
users/msaffari-amd/aiter/flydsl-qr-int4-global-divisor
Oct 26, 2026
Merged

msaffari-amd merged 8 commits into
mainfrom
users/msaffari-amd/aiter/flydsl-qr-int4-global-divisor

Conversation

@msaffari-amd

@msaffari-amd msaffari-amd commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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 by s before quantization and the result is multiplied by s once 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.py

  • allreduce(inp, out, stream=None, divisor=1.0). Existing positional calls keep working.
  • _check_divisor accepts finite values in [1/16, 128], so the fp16 restore stays a normal fp16. Anything else raises ValueError.
  • Every rank must pass the same divisor. This is the caller's responsibility and is not checked.
  • divisor is a runtime Float32 kernel argument, so changing it does not recompile.

Kernel: aiter/ops/flydsl/kernels/quick_allreduce_int4.py

  • Before the first pack, loaded values are multiplied by fp16(1/s), before the group max and the E4M3 byte.
  • _codec_quant and the second pack are unchanged.
  • On the store path, s is folded into the all-gather dequant scale, so the sum is multiplied by s once before the bf16 write.
  • Both super_tile == 1 and super_tile > 1 paths are covered.
  • With divisor=1, the output is bit-identical to the previous kernel.

Out of scope: choosing s from the live tensor, vLLM wiring, and the HIP QuickReduce kernel.

Test Plan

  • op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py on 8× MI355X (gfx950):
    • The existing cases run at the default divisor 1, unchanged.
    • New outlier case (std 100) at TP 8 on the ST=1 and ST=8 paths: clips at divisor 1, and divisor 8 must reach ≥ 18 dB and gain ≥ 3 dB.
    • New small-magnitude case (std 0.005) at TP 8 on the same paths: must pass at the default divisor.
  • Activation dumps from six sample models at TP 8, scored as whole-tensor and per-token SQNR against an fp32 all-reduce.
  • Old vs new kernel timing at TP 8.

Test Result

Test suite: passes.

Case SQNR
Random fill, divisor 1 19.20–19.21 dB
Small fill (std 0.005), divisor 1 18.96 dB
Outlier fill (std 100), divisor 1 → 8 14.09 → 19.21 dB

Sample models, TP 8 (SQNR, divisor 1 → 8)

Model Prefill Decode
A 17.06 → 19.14 dB 19.42 → 19.40 dB
B 10.78 → 18.36 dB 11.93 → 20.11 dB
C 19.05 → 19.05 dB 19.17 → 19.17 dB
D 8.19 → 24.71 dB 22.65 → 22.65 dB
E 19.72 → 19.72 dB 18.03 → 18.03 dB
F 17.93 → 17.93 dB 18.74 → 18.78 dB

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)

Fill Divisor 1 Divisor 8
std 0.02 19.21 dB 15.20 dB
std 0.005 18.96 dB 3.79 dB

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

@msaffari-amd
msaffari-amd requested review from a team and a balanced review from Copilot October 1, 2026 12:03
@github-actions

github-actions Bot commented Oct 1, 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
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6049 --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.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Validation permits fp16-unsafe divisors, and the new behavior lacks automated coverage.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

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
samremes previously approved these changes Oct 1, 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. Maybe add a test-case that covers a non-unit scale, like Copilot mentioned.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 13:13

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The cross-GPU kernel needs human review and head-matched GPU validation, and divisor rejection paths remain untested.

Review effort: Balanced
Findings: None

Resolved since last review (2)

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The distributed GPU-kernel behavior needs final hardware review, and the new validation contract lacks boundary and invalid-input tests.

Review effort: Balanced
Findings: None

@zufayu
zufayu requested a review from yadaish October 2, 2026 00:33
Copilot AI balanced review requested due to automatic review settings October 12, 2026 09:36

Copilot AI 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.

🟡 Changes recommended

The default-divisor behavior and new validation contract lack targeted regression coverage.

1 open finding

🧠 Review effort: Balanced

@zufayu zufayu assigned coderfeli and unassigned yadaish Oct 15, 2026
Copilot AI balanced review requested due to automatic review settings October 15, 2026 10:49

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

Review summary

1. PR description is out of date

  • The description says the range is [2^-14, 2^14], but the code caps it at DIVISOR_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, and o_proj/down_proj outputs.
  • 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!

Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:24

Copilot AI 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.

🟡 Changes recommended

The implemented default and its regression coverage must be reconciled with the advertised default-on saturation protection.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

@msaffari-amd

msaffari-amd commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Review summary

1. PR description is out of date

  • The description says the range is [2^-14, 2^14], but the code caps it at DIVISOR_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, and o_proj/down_proj outputs.

  • 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!

@TennyWang1223
Thanks for the review. All three points are addressed in 95811d6:

  1. Description: updated to match the code, with the results re-run.
  2. Default divisor: agreed. Your std-0.005 case drops from 18.96 dB at divisor 1 to 3.79 dB at divisor 8, so the default is back to 1 and the divisor is opt-in. 8 is documented as the recommended value for models with outliers; on the sample models it recovers every input that clips, and no token gets worse in per-token SQNR. The std-0.005 case is now in the test at the default divisor.
  3. Same divisor on every rank: documented in the allreduce docstring and the description as the caller's responsibility. I didn't add a check, because it would need an extra all-reduce on every call.

@amd-mghanimi

Copy link
Copy Markdown

It seems this PR improves KimiK3 accuracy on long context of needle in a haystack task.

KimiK3 on lm_eval NIAH

with HIP QR:

|    Tasks    |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|-------------|------:|------|-----:|-----:|---|-----:|---|------|
|niah_single_2|      1|none  |     0|131072|↑  | 0.960|±  |   N/A|
|             |       |none  |     0|  4096|↑  |-1.000|±  |   N/A|
|             |       |none  |     0| 65536|↑  | 0.978|±  |   N/A|

with FlyDSL QR without this PR:

|    Tasks    |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|-------------|------:|------|-----:|-----:|---|-----:|---|------|
|niah_single_2|      1|none  |     0|131072|↑  | 0.934|±  |   N/A|
|             |       |none  |     0|  4096|↑  |-1.000|±  |   N/A|
|             |       |none  |     0| 65536|↑  | 0.976|±  |   N/A|

with FlyDSL QR + this PR:

|    Tasks    |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|-------------|------:|------|-----:|-----:|---|-----:|---|------|
|niah_single_2|      1|none  |     0|131072|↑  | 0.982|±  |   N/A|
|             |       |none  |     0|  4096|↑  |-1.000|±  |   N/A|
|             |       |none  |     0| 65536|↑  | 0.996|±  |   N/A|

TennyWang1223
TennyWang1223 previously approved these changes Oct 19, 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

# Conflicts:
#	aiter/ops/flydsl/kernels/quick_allreduce_int4.py
#	aiter/ops/flydsl/quick_allreduce_int4.py
Copilot AI balanced review requested due to automatic review settings October 20, 2026 10:30

Copilot AI 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.

🔵 Needs a closer look

Multi-GPU numerical compatibility and performance require final human confirmation of hardware validation.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@msaffari-amd

Copy link
Copy Markdown
Contributor Author

LGTM

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!

Copilot AI balanced review requested due to automatic review settings October 21, 2026 08:26

Copilot AI 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.

🔵 Needs a closer look

Multi-GPU numerical correctness, default-result equivalence, and performance need independent confirmation on supported hardware.

No open issues 🎉

Review effort: Balanced

@zufayu

zufayu commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

@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 divisor=1 preserves the expected fused-path numerical behavior and does not introduce a material performance regression from the additional packed FP16 divide/multiply work. With that confirmation and current-head owner reapproval, I am comfortable approving it.

@msaffari-amd

Copy link
Copy Markdown
Contributor Author

@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 divisor=1 preserves the expected fused-path numerical behavior and does not introduce a material performance regression from the additional packed FP16 divide/multiply work. With that confirmation and current-head owner reapproval, I am comfortable approving it.

@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.
Performance: no material regression. Fused and fused+MXFP4 are within noise of main

@TennyWang1223

Copy link
Copy Markdown
Contributor

@zufayu reviewed communication semantics, LGTM

@msaffari-amd
msaffari-amd merged commit 41d4d8d into main Oct 26, 2026
@msaffari-amd
msaffari-amd deleted the users/msaffari-amd/aiter/flydsl-qr-int4-global-divisor branch October 26, 2026 14:21
vpietila-amd added a commit that referenced this pull request Oct 28, 2026
…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]>
RElbers added a commit that referenced this pull request Oct 28, 2026
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.
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.

8 participants