Repository navigation
[HIP] [JIT] Enable gfx1250 QuickReduce for TP2 and TP4 - #5965
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
TennyWang1223
left a comment
There was a problem hiding this comment.
Review summary
Thanks for the work. The PullQ4 protocol itself looks sound to me:
- Per-tile epochs + ping-pong slots give the right WAR guarantee: observing a peer's epoch
e+1flag implies that peer's kernelehas completed, so reusing the epoch-eslot ate+2is safe. - The bulk path uses a disjoint region
[2·pq, 4·pq)with its own epoch, and it fits within the2·data_size_per_phaseallocation (Q4 transmits 9216 B per 32 KiB tile, so4·pq + 8 < 2·data_size_per_phase). - Every rank reduces in fixed rank order and also uses the quantized copy of its own contribution, so outputs are bit-identical across ranks.
The incidental fixes are welcome: static data_buffer_size, the numel-vs-bytes kMaxProblemSize check, int64 comm offsets, and noexcept destroy(). Please call them out in the PR description, since they change legacy behavior.
Blocking
- The new test breaks the multi-GPU CI runner (see item 1 below).
- Several changes land in code shared with gfx942/gfx950: CodecQ4
recv_atom, the IPC buffer layout, and quant-level binding. Those archs were not run. Please attach legacy QR correctness results and INT4 perf numbers on gfx942/gfx950 before merge.
1.op_tests/multigpu_tests/gfx1250_poc/test_gfx1250_quick_allreduce.py:297
.github/scripts/aiter_test.sh runs every file under op_tests/multigpu_tests as python3 $file with no arguments. --tp-size is required=True, so argparse exits with code 2 on every multi-GPU CI run, MI300 included. Even with arguments, _run_tp_test calls pytest.skip() outside pytest on non-gfx1250
machines. That raises Skipped, and the script exits non-zero.
Suggestions:
- Give
--tp-sizea default (or loop over TP2/TP4), andsys.exit(0)early when the device is not gfx1250. Alternatively, add the file toskip_tests. gfx1250_poc/reads like a scratch directory. Consider moving this regression test somewhere permanent.
2.csrc/include/quick_all_reduce.cuh:187
This changes the CodecQ4 scale load from "every lane loads" to "group leader loads + __shfl". CodecQ4 is shared with the gfx942/gfx950 INT4 two-shot path, which is the most-used QR configuration, and this adds a ds_bpermute per atom there.
Was this change needed for correctness on wave32, or is it a perf change? Either way, please share gfx942/gfx950 INT4 latency before and after, or keep the original load path under #if !defined(__gfx1250__).
3.csrc/include/quick_all_reduce.cuh:1695
Python now always passes quant_level to init_custom_qr. As a result, every communicator, including gfx942/gfx950 ones, is bound to a single level, and any call with a different level throws. That is fine for aiter's own wrapper, but it changes behavior for any caller that reuses a communicator across levels.
Please either note this in the description or only enforce the binding when use_pull_q4 is true.
4.aiter/dist/device_communicators/quick_all_reduce.py:290
On gfx1250, the only routable configuration is INT4 with use_fp16_kernels. With QUANTIZATION=FP/FP8/INT6/INT3 or CAST_BF16_TO_FP16=0, the communicator still initializes and allocates the IPC buffer (about 512 MiB per rank at the 256 MiB default), yet should_quick_allreduce never returns True. Suggest
disabling QR at init in those cases, with a log line.
Related:
- The description says FP/FP8/INT6 "passed" on gfx1250. Please clarify that this is via direct op calls only, not production routing.
- The
T=bf16, cast_bf2half=falsePullQ4 instantiations are unreachable from Python.
5.csrc/include/quick_all_reduce_gfx1250.cuh:42
AITER_QUICK_REDUCE_FORCE_PULL_Q4 and AITER_QUICK_REDUCE_FORCE_PULL_Q4_BULK are undocumented debug knobs read from C++ at init. The production route only reaches the bulk path, because the Python minimum is 8/16 MiB and the bulk threshold here is 1 MiB. Can we drop these env vars and the non-bulk PullQ4 path?
If non-bulk is kept, see item 6.
6.csrc/include/quick_all_reduce.cuh:1704
In non-bulk PullQ4, CTAs spin-wait on peers' per-tile flags. The grid goes up to kMaxNumBlocks = 304 * 4, a constant derived from MI300. With FORCE_PULL_Q4 set and bulk off, a large message launches 1216 CTAs that are not guaranteed to be co-resident, which can hang across ranks.
Please either cap the grid at a co-residency-safe value for gfx1250, or restrict non-bulk to small messages unconditionally.
7.csrc/include/quick_all_reduce_gfx1250.cuh:402
Correctness here depends on the quantize kernel's nontemporal payload stores being visible to peers after the kernel boundary and before this kernel's system-scope release. That only holds because dbuffer is allocated with hipDeviceMallocUncached. Please add a one-line comment saying so, so nobody changes the
allocation flags later without realizing it.
8.aiter/dist/device_communicators/quick_all_reduce.py:258
The gfx1250 default qr_max_size is 256 MiB, but the microbenchmark and serving runs set AITER_QUICK_REDUCE_MAX_SIZE_BYTES_MB=512. With defaults, the 512 MiB rows in the table fall back to CAR. Please either document this or align the default.
9. [nit] Arch gating
Both Python and C++ match only the gfx1250 prefix, so the rest of the gfx125x family stays disabled. If that's intentional, consider saying so in the description.
quick_reduce_scatter.cu, added on main by ROCm#6031, uses kWavefront, which this branch had renamed to kBlockX. Restore main's definition so the merged tree builds. The launch geometry is unchanged ({64, 4, 1}).
Motivation
QuickReduce assumed gfx9 launch and synchronization behavior and was not correct or graph-safe on gfx1250. This change enables BF16 INT4 QuickReduce on gfx1250 for TP2, TP4, and TP8, and keeps the existing path on gfx942 and gfx950.
Changes
Add a gfx1250 PullQ4 INT4 path. It runs three dispatches on one stream:
Every rank reduces in fixed rank order, so outputs are bit-identical across ranks.
Epoch-parity ping-pong payloads keep graph replays from overwriting data that peers are still reading.
A PullQ4 communicator is bound to INT4 and allocates only the PullQ4 layout, about 0.56× the max problem size. Legacy two-shot and fused-RMSNorm calls on it throw.
Route BF16 INT4 to QuickReduce only at the measured crossovers: TP2 ≥ 16 MiB, TP4 ≥ 8 MiB, TP8 ≥ 16 MiB. Smaller messages fall back to AITER custom all-reduce, or to RCCL at TP8, where AITER custom all-reduce is unavailable on gfx1250.
gfx1250 routes only
AITER_QUICK_REDUCE_QUANTIZATION=INT4withAITER_QUICK_REDUCE_CAST_BF16_TO_FP16=1. For any other quantization, orCAST_BF16_TO_FP16=0, the communicator is disabled at init with a log line and no IPC buffer is allocated. PullQ4 kernels are instantiated only for the BF16→FP16 route.The gfx1250 default for
AITER_QUICK_REDUCE_MAX_SIZE_BYTES_MBis 512 MiB (about 288 MiB allocated per rank), matching the benchmark and serving configuration.Only the
gfx1250prefix is enabled, in both Python and C++. Other gfx125x parts stay disabled until they are validated.gfx1250 layouts, PullQ4 kernels, route selection, and launch helpers live in
quick_all_reduce_gfx1250.cuh. Codecs, legacy two-shot kernels, communicator lifecycle, and IPC setup stay shared. There are no debug environment variables.init_custom_qrtakes an optionalquant_level; the original three-argument call still works.Changes in code shared with gfx942/gfx950
Code compiled without
__gfx1250__keeps main's behavior on the two-shot hot path:send/recvare split into per-atom helpers with identical logic.__shfl, wave32 lane math ingroup_abs_max, system-scope flag atomics) are behind#if defined(__gfx1250__).d_flag_colorsizing are unchanged.Incidental fixes that change legacy behavior:
data_buffer_sizeis no longerstatic, so a second communicator with a different max size is sized correctly.kMaxProblemSizecheck compares bytes instead of element count.int64_t.destroy()isnoexcept, continues best-effort cleanup, and closes peer handles through the host-side pointer list.Validation
Hardware: gfx1250 in DPX mode (8 partitions with 96 CUs each; GPU pairs 0/1, 2/3, 4/5, 6/7 share a package).
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True. QuickReduce IPC-exports only its ownhipExtMallocWithFlagsbuffer and never registers PyTorch tensors.test_quick_all_reduce_rmsnorm.pypasses.test_quick_all_reduce.pyfails identically on main on gfx1250, because it hardcodes TP8 and AITER custom all-reduce rejects TP8 on gfx1250.git diff --checkpass.ENABLE_CK=0 PYTHONPATH=$PWD python3 op_tests/multigpu_tests/test_quick_all_reduce_gfx1250.pyThe test runs with no arguments, loops over the available TP sizes, and exits 0 on non-gfx1250 devices, so it is safe under
.github/scripts/aiter_test.sh.gfx942/gfx950: TODO, attach legacy QuickReduce correctness results and INT4 latency (before/after).
Microbenchmark
Configuration:
Speedup is
baseline / QuickReduce.Crossovers:
Commands:
The QuickReduce rows below each TP's routing minimum (for example TP4 4 MiB) were measured with the minimum temporarily lowered for benchmarking only.
Serving A/B (SGLang)
Setup:
HIP_FORCE_DEV_KERNARG=1.AITER_QUICK_REDUCE_QUANTIZATION=INT4,AITER_QUICK_REDUCE_CAST_BF16_TO_FP16=1, andAITER_QUICK_REDUCE_MAX_SIZE_BYTES_MB=512.The previous revision of this PR measured 0.958 / 994.27 tok/s / 65,963.41 ms / 21,132.39 ms / 43.83 ms in the same setup, so the refactor has no end-to-end regression. No GPU fault or traceback occurred.
SGLang needs a small integration to reach AITER QuickReduce on gfx1250: its own QuickReduce wrapper is gfx94/gfx95-only, and it consults custom all-reduce before QuickReduce. The A/B used the following local patch. With
AITER_QUICK_REDUCE_QUANTIZATIONunset, SGLang behavior is unchanged.SGLang patch used for the A/B (
python/sglang/srt/distributed/parallel_state.py)Commands:
Run the following server, accuracy, and serving commands once for each case:
Known unrelated issue: with
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True, this server aborts during decode graph capture inside AITER custom all-reduce (hipIpcGetMemHandlein graph-buffer registration), with or without QuickReduce. It will be tracked and fixed separately.Checklist
aiter_test.shwith no arguments and exits 0 on non-gfx12503rdparty/changes