Skip to content

[Feat] [AMD] distributed: JIT quick all-reduce for TP4 on gfx950 - #46692

Merged
hnyls2002 merged 13 commits into
sgl-project:mainfrom
kevin-mii:m31-amd/k3-allreduce
Nov 1, 2026
Merged

hnyls2002 merged 13 commits into
sgl-project:mainfrom
kevin-mii:m31-amd/k3-allreduce

Conversation

@kevin-mii

@kevin-mii kevin-mii commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Part of the MiniMax-M3.1-Flash AMD series that replaces #45936 (closed with its base branch minimax-m3.1-flash): kernel PRs #46690 (attention), #46691 (MoE / GEMM) and #46692 (quick all-reduce), each on main; then #46693 with the M3.1 call sites and #46694 (indexer CP). It follows the DeepSeek-V4.1 AMD layout (#41018-#41021, then #41308).

Summary

  • A JIT copy of sgl-kernel's quick all-reduce (jit/csrc/distributed/quick_all_reduce/, quick_all_reduce_hip.cuh, ops/communication/quick_all_reduce_hip.py), restructured for latency (the per-tile wire layout is wave-major) and cut to the INT4 / INT8 codecs at TP4 on bf16 data. It keeps sgl-kernel's buffer sizes, flags and arithmetic, so at the level it runs its outputs are bitwise equal to sgl-kernel's, including a partial last tile and bf16 values past fp16's range. Asked for INT4, it runs all-reduces below SGLANG_ROCM_QUICK_REDUCE_INT8_BELOW_MB (default 64 MiB; 0 keeps INT4 at every size) in INT8, about 1/16 of INT4's error, and logs that once at init; the JIT INT4 column below 64 MB in the table is the kernel called at INT4 directly. jit_serves() takes only gfx950, and qr_supports(fa, dtype) tells a caller that a JIT handle reduces bf16 only.
  • Nothing in this PR calls the module: [Feat] [AMD] minimax: Support MiniMax-M3.1-Flash on MI350X / MI355X (gfx950) #46693 wires it in (custom_all_reduce_ops behind SGLANG_ROCM_QUICK_ALL_REDUCE_JIT, on gfx950 only, the GPU it is validated on; QuickAllReduce asks qr_supports() so float16 goes to the next all-reduce). Review it here as a kernel; the serving numbers below come from [Feat] [AMD] minimax: Support MiniMax-M3.1-Flash on MI350X / MI355X (gfx950) #46693.

Changes to existing kernels

None; every source file is new and HIP-only. The existing test_quick_allreduce_bf16_range gains the JIT cases.

Not in this PR

  • Each communicator allocates twice its max size (4 GiB per GPU at the 2 GiB default), as sgl-kernel's does, although the kernel indexes its slots by block and so uses at most 256 tiles per phase. Shrinking it would return that memory to the KV cache; it is left for a follow-up.
  • sgl-kernel's own quick_all_reduce.h keeps data_buffer_size function-static, so the first communicator's size sticks process-wide; this JIT copy sizes it per communicator and leaves the original untouched.

Verification

  • MI350X (ROCm 7.2 image, AITER acf8fdf93), this branch alone on main: test_quick_allreduce_bf16_range 3 passed (8 GPUs). pre-commit clean.
  • Latency at TP4 on MI350X, bf16 messages, eager, us per all-reduce (sgl-kernel = the AOT qr_all_reduce this replaces):
Message aiter bf16 custom AR sgl-kernel INT8 JIT INT8 JIT / sgl-kernel sgl-kernel INT4 JIT INT4 JIT / sgl-kernel
1 MB 18.4 29.6 14.2 0.48 26.9 13.7 0.51
2.4 MB 28.1 40.5 20.1 0.49 31.9 16.7 0.52
8 MB 79.2 92.8 51.3 0.55 56.7 38.3 0.68
32 MB 389.3 267.8 177.6 0.66 157.9 104.2 0.66
63 MB 576.8 446.8 345.9 0.77 261.7 194.8 0.74
128 MB 1003.0 699.5 0.70 462.2 391.7 0.85
400 MB 2308.6 2181.6 0.94 1415.5 1249.5 0.88

The JIT INT8 beats aiter's bf16 custom all-reduce from 1 MB, where sgl-kernel's INT8 does not until about 16 MB; that is what lets the integration PR lower aiter's custom-AR cutoff to 2.4 MiB. One run; single-size outliers in other columns (RCCL at 8 MB, sgl-kernel INT4 at 16 and 256 MB) were left out.

  • Serving, measured in the integration PR (MI350X TP 4, NVFP4 KV, DSpark acceptance simulated at 3 tokens per step, 32K-token contexts, two repeats on each of two GPU sets). With sgl-kernel's quick all-reduce instead (SGLANG_ROCM_QUICK_ALL_REDUCE_JIT=0) at the same 2.4 MiB custom-AR cutoff, decode TPOT grows 4.0% at 32 concurrent requests and 2.6% at 64, and 32K-token prefill 1.9%. With main's 64 MiB cutoff as well: 3.6%, 6.7% and 4.3%. At 1 and 8 requests every all-reduce stays under the cutoff, on aiter's custom all-reduce.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ⏳ Run #41356558931
Latest PR Test (Extra): ❌ Run #41356558741
Latest PR Test (AMD ROCm 10): ⏳ Run #41356558860

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

Kevin Mi and others added 5 commits October 26, 2026 20:59
A JIT build of sgl-kernel's quick all-reduce, restructured for latency and cut to the INT4 / INT8 codecs at TP4 on bf16 data; same buffers, flags and arithmetic, so outputs are bitwise equal to sgl-kernel's. No callers yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t show

The base header still said the copy serves the INT4 two-shot only; it serves
INT8 as well. Its note that the grid cap comes from the loader repeats the
QR_MAX_BLOCKS #error two lines below, so it goes.

The entry-point header chained four clauses into one sentence; it keeps the
provenance (sgl-kernel's qr_* calls) and the cut (INT4 / INT8, TP4, bf16 cast
to fp16), and leaves the bitwise claim to the kernel headers that make it.

raise_flags' comment restated its four-line body; the reason every wave
waits for its own stores already sits on wait_own_stores.

In the test, the grid-stride note now says which sizes exceed the grid, and
the fallback cases note lists the INT4-at-TP2 case it left out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The module docstring said the JIT build keeps sgl-kernel's buffer layout; the
per-tile wire layout is wave-major now, and what it keeps is the buffer sizes,
flags and arithmetic, as the kernel header says. It is now a summary line plus
one paragraph.

jit_serves' docstring ran three noun phrases together; it now names the
argument and the two environment settings it reads.

The fallback test's docstring named SGLANG_ROCM_QUICK_ALL_REDUCE_JIT, which
this PR does not define (the integration PR adds it), and said a group raises
at its first all-reduce, while TP2 would raise already at init. The bitwise
test's docstring dropped the design note and keeps the contract.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only the bf16 packed_* specializations used it, and the JIT copy dropped
them with the bf16 kernels; nv_bfloat162 stays for the load/store casts.
gfx950 device assembly of both codecs is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n one helper

Both JIT workers defined the same nested open_comm and repeated the
argument-order lambda, with the comment that explains it on only one of
them. _open_comms now opens the pair in the same order (sgl-kernel first,
then JIT), so each worker makes one call.

The quant levels were a local 1, 2, 3 in one worker and bare 1 / 3 next to
a named int6 in the other; both now read QuickReduceRegime, whose values
QuickAllReduce passes as the level. The values are unchanged.

No case was added or removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kevin-mii

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 27, 2026
Kevin Mi and others added 3 commits October 28, 2026 02:49
…n errors, cap the size

destroy() closed peer handles read from dbuffer_list, a device allocation, and
closed every peer even when open_handles never ran; it now walks the host
buffer_list and skips unopened peers, which init resets. The wrapper's destroy
runs the teardown before delete, so a HIP error raises instead of terminating
from the noexcept destructor. init rejects max sizes past 2 GiB, beyond which
the 32-bit phase offsets wrap. All three were inherited from sgl-kernel's copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ches the bf16 build

init cannot see the dtype, so a float16 model at TP4 with the JIT flag set got a
generic tensor-dtype error at its first large all-reduce.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and past fp16's range

Every size was a whole number of 32 KiB tiles and |x| stayed near 350, so the
JIT build's tail handling and its reordered load / FP16_OVFL convert were never
compared with sgl-kernel's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…annot show

Drop comments that restate the code or narrate how the copy diverged from sgl-kernel's, the latency numbers in the INT8 threshold comment, first person and inline backticks; fold the wrapper's \param/\return lines into its briefs and correct the Phase-2 and grid-stride test comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kevin-mii kevin-mii added the bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) label Oct 29, 2026
Kevin Mi and others added 4 commits October 29, 2026 19:29
Picks up sgl-project#47127, which fixes main's test_gdn_prefill_graph that pr-test-finish fails on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and name the INT8 cut

- jit_serves() now also requires gfx950, where the build and its 256-block
  grid were validated, instead of leaving that check to the caller.
- qr_supports(fa, dtype) says whether a handle reduces a dtype (a JIT handle
  takes bf16 only), so a communicator can hand float16 to another all-reduce
  instead of hitting the ValueError mid-forward.
- The size below which an INT4 request runs INT8 is now
  SGLANG_ROCM_QUICK_REDUCE_INT8_BELOW_MB (default 64, 0 runs INT4 at every
  size), read per handle at init and logged once on rank 0.
- The error messages no longer name SGLANG_ROCM_QUICK_ALL_REDUCE_JIT, which
  the integration PR defines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's TensorMatcher (sgl-project#47300) now holds a bound device to its options and
names the platform GPU kDLGPU; this ROCm-only entry point still asked for
kDLCUDA, so every all-reduce on a rocm device failed the match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hnyls2002
hnyls2002 merged commit fdf2266 into sgl-project:main Nov 1, 2026
145 of 167 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants