Skip to content

Add fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output - #2823

Merged
TennyWang1223 merged 6 commits into
ROCm:mainfrom
hubertlu-tw:fused_ar_rms_per_group_quant
Apr 29, 2026
Merged

TennyWang1223 merged 6 commits into
ROCm:mainfrom
hubertlu-tw:fused_ar_rms_per_group_quant

Conversation

@hubertlu-tw

Copy link
Copy Markdown
Contributor

Motivation

  1. ar_fusion_epilogue_per_group arg order — Declared (…, output, scale_out, bf16_output, active) but callers passed 11 args ending in (…, scale_out, active), binding bool to T* (invalid). The bf16 path never compiled; this PR fixes parameter order and threads optional bf16_output through 1-stage / 2-stage / split per-group kernels, dispatch, host op, pybind, and Python.
  2. GDN-style layers need FP8 + normed bf16 (e.g. gating) without a second kernel — today that required fused AR+RMS + separate per_1x128 quant. With emit_bf16=True, one kernel writes fp8+scale from the same fp32 accumulators as an optional bf16 side-output.

Modifications

Area Change
custom_all_reduce.cuh Epilogue: (..., output, scale_out, active = true, bf16_output = nullptr); per-group kernels + launchers + dispatchFusedAllReduceRMSNormQuantPerGroup pass bf16_output
custom_all_reduce.cu / .h / rocm_ops.hpp Host op: bf16_out_ptr (0 = off); pybind default 0
Python emit_bf16=False on fused_ar_rms_per_group_quant, custom_*, communicator / coordinator / TMP helpers; True → allocate bf16, return 4-tuple
Tests test_fused_ar_rms_per_group_quant.py: emit_bf16 in matrix; asserts bf16 vs fp8 dequant within one FP8 step

Backward-compatible: bf16_out_ptr=0, emit_bf16=False, C++ bf16_output=nullptr — existing 3-tuple / no-bf16 behavior unchanged.

Accuracy

Command (e.g. TP=8):

python3 op_tests/multigpu_tests/test_fused_ar_rms_per_group_quant.py

Result: All shape × emit_bf16 runs pass. per_group_err matches pre-PR FP8 (~<2e-5, rounding); bf16_vs_fp8 < 1.0 when emit_bf16=True.

GSM8K (Qwen3.5-397B-A17B-FP8, TP=8, MI355X, companion SGLang PR): accuracy 0.946→0.955, invalid 0.010→0.008; latency/tok/s in line with expectations (see full logs if needed).

Benchmarking

Paths compared (SGLang script, TP=8, MI355X): Split 3-kernel vs Fused 2-k (AR+RMS + quant) vs Fused 1-k (fp8 only) vs Fused 1-k+bf16 (this PR).

SGLANG_USE_AITER=1 torchrun --nproc_per_node=8 --master_port=29520 \
  benchmark/kernels/all_reduce/benchmark_fused_ar_rms_quant_amd.py \
  --dtype bf16 --group-size 128 --mode both --warmup 5 --iters 20 --repeats 3 \
  --prefill-shapes "128x<H>,512x<H>,1024x<H>,2048x<H>,4096x<H>" \
  --decode-shapes "1x<H>,8x<H>,32x<H>,64x<H>,128x<H>,256x<H>,512x<H>"

Headline: On decode-scale shapes, Fused 1k+bf16 is ~1.02×–1.13× vs Fused 2k across hidden sizes 4096 / 6144 / 7168 / 8192. Prefill (large tokens) stays within ~±3% of 2-kernel baseline — extra bf16 stores add bandwidth; large-prefill call sites can keep emit_bf16=False for fp8-only 1-kernel.

Kernel profile (Qwen3.5-397B-A17B-FP8, decode sample): fused per-group path replaces separate quant work; net −59 kernel launches per decode pass vs prior wiring (detail: 59/60 layer sites on fused path).

Serving (8192/8192, conc 16): throughput ~+2.5%, median TPOT ~−2.5% (same run configuration as internal A/B).

Full microbenchmark: decode (CUDA-graph, µs — median per rank)
Shape Split 3k Fused 2k Fused 1k Fused 1k+bf16 Speedup vs Fused 2k
1 × 4096 24.3 19.5 17.8 18.0 1.08x
8 × 4096 25.7 21.0 19.1 19.9 1.06x
32 × 4096 25.9 23.7 21.0 21.0 1.13x
64 × 4096 27.2 24.5 22.1 22.3 1.10x
128 × 4096 30.5 27.9 25.7 26.0 1.07x
256 × 4096 37.1 35.2 32.5 32.7 1.08x
512 × 4096 50.2 47.7 44.3 45.0 1.06x
1 × 6144 25.4 20.4 19.1 19.0 1.07x
8 × 6144 26.8 22.5 20.9 20.9 1.07x
32 × 6144 27.8 24.8 22.6 22.7 1.10x
64 × 6144 31.2 28.1 25.4 25.6 1.09x
128 × 6144 34.7 32.2 29.9 30.1 1.07x
256 × 6144 43.2 42.1 39.5 39.8 1.06x
512 × 6144 62.5 63.0 58.9 60.0 1.05x
1 × 7168 27.0 20.9 19.5 19.6 1.06x
8 × 7168 27.4 22.9 21.9 21.8 1.05x
32 × 7168 28.9 25.3 23.7 23.6 1.07x
64 × 7168 31.8 28.5 26.4 26.8 1.06x
128 × 7168 36.6 34.2 31.7 31.6 1.08x
256 × 7168 47.0 45.6 42.5 43.0 1.06x
512 × 7168 69.4 68.8 65.8 66.7 1.03x
1 × 8192 26.7 20.9 20.4 19.9 1.05x
8 × 8192 28.2 23.3 22.1 21.9 1.07x
32 × 8192 29.5 25.5 24.2 24.1 1.06x
64 × 8192 32.6 28.9 26.9 27.0 1.07x
128 × 8192 39.0 36.1 33.7 34.1 1.06x
256 × 8192 50.7 49.5 45.8 46.9 1.05x
512 × 8192 75.4 74.6 71.6 72.9 1.02x

At decode scale, Fused 1k+bf16 is 1.02×–1.13× vs Fused 2k across all four hidden sizes.

Full microbenchmark: prefill (eager, µs — median per rank)
Shape Split 3k Fused 2k Fused 1k Fused 1k+bf16 Speedup vs Fused 2k
128 x 4096 57.0 54.5 48.6 50.1 1.09x
512 x 4096 55.9 55.6 49.3 50.6 1.10x
1024 x 4096 73.9 74.1 70.0 71.8 1.03x
2048 x 4096 121.9 125.5 122.5 124.3 1.01x
4096 x 4096 221.3 238.5 222.3 234.9 1.02x
128 x 6144 56.8 54.8 48.5 49.2 1.11x
512 x 6144 66.7 62.8 58.8 60.5 1.04x
1024 x 6144 98.9 99.8 98.6 99.5 1.00x
2048 x 6144 172.9 178.3 173.7 175.8 1.01x
4096 x 6144 331.1 357.1 338.4 345.1 1.03x
128 x 7168 57.1 54.8 49.4 50.0 1.10x
512 x 7168 72.8 69.0 65.6 66.9 1.03x
1024 x 7168 112.0 112.7 111.3 113.2 1.00x
2048 x 7168 197.0 206.3 202.0 202.5 1.02x
4096 x 7168 382.5 416.7 398.9 404.5 1.03x
128 x 8192 103.4 94.4 80.6 53.0 1.78x
512 x 8192 78.4 74.7 72.4 72.6 1.03x
1024 x 8192 124.5 124.4 123.1 125.4 0.99x
2048 x 8192 222.5 237.3 224.2 237.1 1.00x
4096 x 8192 434.7 472.4 457.8 467.2 1.01x

Notes: Small prefill (128 tokens) is still ~1.09×–1.11× at 4096 / 6144 / 7168. The 128 × 8192 row (1.78×) is an outlier from a slow Fused 2k sample — Fused 1k at that shape is ~80.6 µs, consistent with the decode trend. Large prefill (tokens ≥ 1024) is bandwidth-bound; 1k+bf16 stays within ~±3% of Fused 2k; use emit_bf16=False on those paths if only fp8 is needed.

Checklist

  • test_fused_ar_rms_per_group_quant.py passes for emit_bf16 ∈ {False, True} on covered hidden sizes
  • Black / Ruff on touched Python; clang-format on touched csrc/ as needed
  • No API break for default args

ar_fusion_epilogue_per_group had the bf16_output parameter declared but
not plumbed through: the per-group kernels were passing 11 positional
args with `active` landing in the `bf16_output` slot, so the file did
not compile when bf16_output was enabled, and no caller could request
the unquantized bf16 view.

Swap (active, bf16_output) in the epilogue so the existing 11-arg
callers bind correctly, and thread an optional `bf16_output` pointer
through the 1-stage, 2-stage, and split per-group kernels, their
launchers, dispatchFusedAllReduceRMSNormQuantPerGroup, the host
fused_allreduce_rmsnorm_quant_per_group op, and the pybind signature
(new `bf16_out_ptr` kwarg defaulting to 0).

Python wrappers (CustomAllreduce, CudaCommunicator, GroupCoordinator,
tensor_model_parallel_fused_allreduce_rmsnorm_quant_per_group) take a
new `emit_bf16` flag that defaults to False. When True, allocate a
bf16 buffer, pass its data pointer to the op, and return
`(fp8, residual_out, scale, bf16)` instead of the 3-tuple. The 2-kernel
fallback inside CudaCommunicator reuses the bf16 output from
fused_allreduce_rmsnorm so the caller gets the same 4-tuple shape.

Unit test op_tests/multigpu_tests/test_fused_ar_rms_per_group_quant.py
now iterates over emit_bf16 in {False, True} and asserts the bf16
side-output agrees with the fp8+scale dequant to within one FP8
rounding step. Backward-compatible: all new args default to disabled,
no caller needs to change.
@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 (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-355 Run Triton tests on MI355 in addition to MI325
ci:sglang SGLang integration tests
ci:atom ATOM benchmark (DeepSeek-R1 + GPT-OSS)
ci:vllm vLLM benchmark
ci:all All of the above

Add labels via the sidebar or gh pr edit 2823 --add-label <label>

The fused ar_fusion_epilogue_per_group uses a packed-16B load plus an
intra-group butterfly __shfl_xor abs-max reduction, which imposes four
implicit constraints on group_size in addition to the n % group_size
check. A violation previously produced silently wrong scales rather
than a clean failure -- especially hard to debug under CUDA-graph
capture/replay where launch errors surface asynchronously.

Now both the C++ host dispatcher and the Python entry point enforce:

  (a) group_size > 0
  (b) group_size % PACK_SIZE == 0 (PACK_SIZE = 16 / sizeof(T))
  (c) threads_per_group = group_size / PACK_SIZE is a power of two
  (d) threads_per_group <= 64 (wavefront size on CDNA gfx94x/gfx950)
  (e) n % group_size == 0

The Python validator (_validate_per_group_size) runs at the top of
CustomAllreduce.fused_ar_rms_per_group_quant and raises a synchronous
ValueError, giving an actionable call-site error instead of a
post-launch asynchronous RuntimeError.

Tests: - Non-distributed test_group_size_validation_python_check covering
   (a)-(e) with both passing and failing inputs; also bad element_size
   and non-int group_size. Runs first in __main__.
 - --sweep-group-size flag sweeps {32, 64, 128, 256, 512} x
   {(128,4096), (512,4096), (1024,4096)} x {emit_bf16=F,T} at the
   given TP to validate every admitted group_size end-to-end against
   the unfused reference.
 - --skip-python-check escape hatch and group_size summary column.
Made-with: Cursor
@hubertlu-tw hubertlu-tw changed the title Fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output Add Fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output Apr 27, 2026
@hubertlu-tw hubertlu-tw changed the title Add Fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output Add fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output Apr 27, 2026
@TennyWang1223
TennyWang1223 merged commit 4331ad7 into ROCm:main Apr 29, 2026
27 checks passed
Liang-jianhao97 pushed a commit that referenced this pull request May 7, 2026
…ut (#2823)

* Add fused_ar_rms_per_group_quant

* Fused AR+RMSNorm+per-group FP8 quant: optional bf16 side-output

ar_fusion_epilogue_per_group had the bf16_output parameter declared but
not plumbed through: the per-group kernels were passing 11 positional
args with `active` landing in the `bf16_output` slot, so the file did
not compile when bf16_output was enabled, and no caller could request
the unquantized bf16 view.

Swap (active, bf16_output) in the epilogue so the existing 11-arg
callers bind correctly, and thread an optional `bf16_output` pointer
through the 1-stage, 2-stage, and split per-group kernels, their
launchers, dispatchFusedAllReduceRMSNormQuantPerGroup, the host
fused_allreduce_rmsnorm_quant_per_group op, and the pybind signature
(new `bf16_out_ptr` kwarg defaulting to 0).

Python wrappers (CustomAllreduce, CudaCommunicator, GroupCoordinator,
tensor_model_parallel_fused_allreduce_rmsnorm_quant_per_group) take a
new `emit_bf16` flag that defaults to False. When True, allocate a
bf16 buffer, pass its data pointer to the op, and return
`(fp8, residual_out, scale, bf16)` instead of the 3-tuple. The 2-kernel
fallback inside CudaCommunicator reuses the bf16 output from
fused_allreduce_rmsnorm so the caller gets the same 4-tuple shape.

Unit test op_tests/multigpu_tests/test_fused_ar_rms_per_group_quant.py
now iterates over emit_bf16 in {False, True} and asserts the bf16
side-output agrees with the fp8+scale dequant to within one FP8
rounding step. Backward-compatible: all new args default to disabled,
no caller needs to change.

* Fix linter errrors

* Strengthen group_size validation for per-group FP8 AR+RMSNorm quant

The fused ar_fusion_epilogue_per_group uses a packed-16B load plus an
intra-group butterfly __shfl_xor abs-max reduction, which imposes four
implicit constraints on group_size in addition to the n % group_size
check. A violation previously produced silently wrong scales rather
than a clean failure -- especially hard to debug under CUDA-graph
capture/replay where launch errors surface asynchronously.

Now both the C++ host dispatcher and the Python entry point enforce:

  (a) group_size > 0
  (b) group_size % PACK_SIZE == 0 (PACK_SIZE = 16 / sizeof(T))
  (c) threads_per_group = group_size / PACK_SIZE is a power of two
  (d) threads_per_group <= 64 (wavefront size on CDNA gfx94x/gfx950)
  (e) n % group_size == 0

The Python validator (_validate_per_group_size) runs at the top of
CustomAllreduce.fused_ar_rms_per_group_quant and raises a synchronous
ValueError, giving an actionable call-site error instead of a
post-launch asynchronous RuntimeError.

Tests: - Non-distributed test_group_size_validation_python_check covering
   (a)-(e) with both passing and failing inputs; also bad element_size
   and non-int group_size. Runs first in __main__.
 - --sweep-group-size flag sweeps {32, 64, 128, 256, 512} x
   {(128,4096), (512,4096), (1024,4096)} x {emit_bf16=F,T} at the
   given TP to validate every admitted group_size end-to-end against
   the unfused reference.
 - --skip-python-check escape hatch and group_size summary column.
Made-with: Cursor

---------

Co-authored-by: kk <[email protected]>
Co-authored-by: TennyWang1223 <[email protected]>
maeehart added a commit to maeehart/vllm that referenced this pull request May 25, 2026
…erns

Adds ``test_rocm_aiter_all_reduce_rmsnorm_group_quant_fp8_fusion_pass_replace``
plus a ``TestAiterAllReduceRMSNormGroupQuantFP8Model`` to validate the three
new ``VllmPatternReplacement`` classes this PR registers on
``RocmAiterAllReduceFusionPass``:

* ``AiterAllreduceFusedRMSNormGroupQuantFP8Pattern`` (no-residual)
* ``AiterAllreduceFusedAddRMSNormGroupQuantFP8Pattern`` (with-residual,
  single ``rms`` consumer)
* ``AiterAllreduceFusedAddRMSNormGroupQuantWithIndexerPattern`` (with-
  residual, DSv3.2 indexer fan-out -- parametrized over both
  ``triton_per_token_group_quant_fp8`` and ``rocm_aiter_group_fp8_quant``
  producers, matching the two registrations added in commit 4)

The model uses four ``rms_norm`` sites that together exercise all three
patterns (matched_count == 4), and chains the FP8 quant output back into
the next AllReduce by manually dequantizing through the per-group scale
so we do not depend on a real FP8 block-scaled GEMM kernel.

Mirrors the structure and assertions of the sibling
``TestAllReduceRMSNormStaticQuantFP8Model`` test as Rohan138 requested
in review.

Validated on 2-GPU MI355X (TP=2, ``smci355-1b112-b13-19``) with the
PR 42864 docker image (aiter v0.1.14-rc0 + ROCm/aiter#2823 wrapper
patches via aiterPR3075): all 4 (``enable_rms_norm_custom_op`` x
``use_triton_quant``) combos PASS in ~32s.

Signed-off-by: Markus Hartikainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
frida-andersson added a commit to maeehart/vllm that referenced this pull request Jun 2, 2026
… probe

Per Rohan138 on vllm-project#42864: mark the feature probe for removal once vLLM bumps its pinned AITER past v0.1.13.post1 (ROCm/aiter#2823 is expected to ship in v0.1.14).

Signed-off-by: Frida Andersson <[email protected]>
a-sidorova added a commit to a-sidorova/vllm that referenced this pull request Sep 23, 2026
vLLM's ROCm base image (docker/Dockerfile.rocm_base) pins AITER
v0.1.22.post1, which already ships both fused AllReduce+RMSNorm+FP8-quant
launchers: the per-token kernel landed in v0.1.12 (ROCm/aiter#1990) and
the per-group kernel in v0.1.14 (ROCm/aiter#2823). The runtime hasattr
probes that gated pattern registration for graceful degradation on older
builds are therefore always true and can be removed.

- aiter_custom_all_reduce: drop build_supports_per_group_quant /
  supports_per_group_quant and the per-token equivalents.
- allreduce_rms_fusion: register the per-group and per-token quant
  patterns unconditionally; drop the now-dead warning_once branches.
- tests: drop the skip guards (and the unused AiterCustomAllreduce
  import) that keyed off the probes.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Alexandra Sidorova <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants