Skip to content

[FlyDSL] QRInt4: INT4 two-shot all-reduce for gfx942/gfx950 - #4970

Merged
samremes merged 59 commits into
mainfrom
samremes/flydsl-qr-int4
Sep 22, 2026
Merged

samremes merged 59 commits into
mainfrom
samremes/flydsl-qr-int4

Conversation

@samremes

@samremes samremes commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add QRInt4: FlyDSL INT4 two-shot all-reduce (reduce-scatter, then all-gather) for gfx942/gfx950, TP 2/4/8.
  • Rank tile is 1152 B: 1024 B INT4 + 128 B group-16 E4M3. Fanout is 18×64 B NT stores (8+8+2). Super-tile is 1 or 8.
  • Host: HIP IPC inbox, ST pick, bf16 payload. Tests gate SQNR ≥ 18 dB vs fp32 NCCL on every rank.

This is a Python launcher (from aiter.ops.flydsl import QuickAllReduceInt4). It is not wired into the HIP QuickReduce dispatch tables.

Why this is faster than HIP QR INT4

HIP QR INT4 (CodecQ4) is one tile per handshake. This kernel packs ST=8 tiles under one last-sector handshake, and uses lockstep 64 B NT fanout.

Group-16 E4M3 also beats HIP CodecQ4 numerics: SQNR ~19.2 dB vs fp32 all-reduce (HIP INT4 is ~18.3 dB / rel MAE ~0.123).

Evidence (8× TP8, isolation run_perftest, bf16)

gfx942 (MI325X, 304 CU)

tokens × hidden ST FlyDSL µs HIP QR INT4 µs vs HIP
512 × 5120 1 23.62 30.75 −23%
512 × 4096 1 22.00 28.56 −23%
32768 × 5120 8 834 1121 −26%

gfx950 (MI355X, 256 CU)

tokens × hidden ST FlyDSL µs HIP QR INT4 µs vs HIP
512 × 5120 1 20.4 28.8 −29%
512 × 4096 1 18.1 26.5 −32%
32768 × 5120 8 558 1061 −47%

Test plan

  • python3 op_tests/multigpu_tests/test_flydsl_quick_allreduce_int4.py -- validity and perf tests

Made with Cursor

samremes and others added 15 commits August 20, 2026 09:12
Drop unused wave-join and single-wave fanout compiles; default and test the fp16 codec.
Compile-only and cache warming belong in developer scripts, not pytest or QRInt4QuadFanout.compile.

Co-authored-by: Cursor <[email protected]>
inttoptr + make_buffer_tensor (nbytes OOB) and BufferCopy128b tiled copies replace the tile/atom/tid arithmetic for local dwordx4 loads and stores. IPC/XGMI fanout stays global_store_dwordx4 nt.
… measured keeper; drop unused codec/force_super/bf16 ALU and qr_int4_mem, compiling via flyc.compile.

Co-authored-by: Cursor <[email protected]>
…R does the same), and time QRInt4 with run_perftest.
gfx942 already lowers vector<2xf16> to v_pk_max/min/mul/add/fma, so the
llvm.inline_asm helpers and f32 absmax round-trip are unnecessary.
The two-shot NT fanout and last-sector handshake are unchanged; gfx942 SQNR vs fp32 all-reduce still passes at TP 2/4/8.

Co-authored-by: Cursor <[email protected]>
TP2 ST=8 was packing the next tile into LDS while wave 0 still loaded the previous one. Also match aiter FlyDSL dtype/device checks and stop sorting IPC group ranks.

Co-authored-by: Cursor <[email protected]>
Each rank already scored vs its local fp32 NCCL all-reduce. The parent
kept rank 0 only, so a broken all-gather on a non-zero rank could pass.

Co-authored-by: Cursor <[email protected]>
@github-actions

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; main branch always runs both MI35X and MI300X
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 4970 --add-label <label>

PR title tags:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf] and op tags like [MLA] are left untouched. Add the no-auto-title label to opt this PR out of title tagging.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

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.

Pull request overview

Adds a public gfx942 FlyDSL INT4 two-shot all-reduce implementation for TP 2/4/8.

Changes:

  • Implements reduce-scatter/all-gather with INT4 and E4M3 quantization.
  • Adds HIP IPC buffer management and super-tile launch selection.
  • Adds distributed SQNR tests and benchmarking support.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
aiter/ops/flydsl/__init__.py Exports QRInt4.
aiter/ops/flydsl/kernels/qr_int4.py Implements the host launcher.
aiter/ops/flydsl/kernels/qr_int4_kernel.py Implements the FlyDSL GPU kernel.
aiter/ops/flydsl/kernels/qr_int4_ipc.py Provides HIP IPC memory helpers.
op_tests/flydsl_tests/test_flydsl_qr_int4.py Adds correctness and benchmark coverage.
Suppressed comments (1)

aiter/ops/flydsl/kernels/qr_int4_kernel.py:630

  • The ST=8 runtime loop has the same non-carried color update: each super-tile handshake needs the previous iteration's color, and the final value is stored after the loop. Rewrite this loop with explicit init/yield state so later batches cannot publish or wait on a stale color.
            for i in range(fx.Int32(0), n_block_tiles, st_i):

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/ops/flydsl/kernels/qr_int4.py Resolved
samremes and others added 3 commits August 24, 2026 16:15
Fail SQNR on NaN or a zero-power reference with error. Drop the NCCL
fallback for Gloo object gather. Reject a rank or world_size that does
not match the process group.

Co-authored-by: Cursor <[email protected]>
Extend arch support to gfx950, parameterize inbox/launch grid_cap (default
1216 to match HIP QR), and tighten the canonical test bench with --grid-cap
and optional JSON export.

Co-authored-by: Cursor <[email protected]>
@samremes samremes changed the title [FlyDSL] QRInt4: INT4 two-shot all-reduce for gfx942 [FlyDSL] QRInt4: INT4 two-shot all-reduce for gfx942/gfx950 Aug 25, 2026
@samremes
samremes requested a balanced review from Copilot August 25, 2026 13:03

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

aiter/ops/flydsl/kernels/qr_int4.py:220

  • When stream is omitted, Stream(None) targets the default HIP stream rather than PyTorch's current stream. A call made inside with torch.cuda.stream(s): can therefore read inp before its producer on s finishes and write out on an unexpected stream. Resolve the current stream for this device, as the other FlyDSL wrappers do.
        if stream is None:
            stream = Stream(None)

Comment thread aiter/ops/flydsl/kernels/qr_int4.py Resolved
IPC inbox setup needs CPU broadcast_object_list and node-local HIP IPC
handles. Fail fast before allocating buffers, matching QuickAllReduce.

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

The synchronization-sensitive GPU kernel lacks head-matched validation and has unresolved API and benchmark-reproducibility issues.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings September 18, 2026 07:28

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

Device selection is not consistently honored during architecture checks and first-time JIT compilation.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

aiter/ops/flydsl/quick_allreduce_int4.py:180

  • get_gfx_runtime() reports the first architecture found by rocminfo; it is not tied to the explicit device argument. On a heterogeneous host this can reject a supported selected GPU, or accept an unsupported one and then compile for it. Resolve the device index first and validate that device's gcnArchName.
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

samremes and others added 2 commits September 18, 2026 08:22
flyc.compile loads a HIP module on the ambient device; wrap _run_compiled so a communicator built for a non-current GPU still compiles and dispatches there.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 18, 2026 08:22

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

The low-level cross-GPU synchronization kernel lacks a head-bound runtime validation report.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 18, 2026 14:11

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

Device-specific architecture validation and inbox alignment issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Balanced

@zufayu

zufayu commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

need to clean Copilot comment

@samremes

samremes commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

need to clean Copilot comment

@zufayu

  1. Asserting against the minor nit mentioned by Copilot for tiny grids.
  2. The get_gfx_runtime is aiter-wide helper, so I will use it also here rather than deviate.

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 launcher does not reject streams belonging to a different GPU, risking invalid cross-device launches.

Review effort: Balanced
Findings: None

Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate caller stream belongs to the engine device

aiter/​ops/​flydsl/​quick_allreduce_int4.py:286

A caller can pass a torch.cuda.Stream belonging to another GPU; it is wrapped without validation and then used to launch a kernel whose tensors and IPC allocations are on self.device. This can fail the launch or execute against addresses from the wrong device. Require a PyTorch stream on the engine device before converting it to FlyDSL's Stream.

@samremes

Copy link
Copy Markdown
Contributor Author

Copilot:

The launcher does not reject streams belonging to a different GPU, risking invalid cross-device launches.

It is caller's responsibility to provide a valid stream, especially when it is an optional parameter and default is already correct, we could do endless validation for anything here. Other ops in aiter don't do this either so I won't deviate from the common pattern.

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