Skip to content

[HIP] [Dist] Support gemma_norm in fused all-reduce + RMSNorm + per-group FP8 quant - #6472

Merged
zufayu merged 2 commits into
mainfrom
yuhua/ar-gemma-fuse
Oct 14, 2026
Merged

zufayu merged 2 commits into
mainfrom
yuhua/ar-gemma-fuse

Conversation

@zhuyuhua-v

Copy link
Copy Markdown
Contributor

Summary

tensor_model_parallel_fused_allreduce_rmsnorm_quant already accepts gemma_norm, but the per-group branch dropped it without a warning. A caller passing gemma_norm=True, quant_type="per_group" silently got a plain x * w RMSNorm.

This PR wires gemma_norm through to the fused kernels. The kernel reads the raw weight and computes x * (1 + w), with the + 1 in fp32. All three per-group kernel paths support it: 1-stage, 2-stage and split. The fallback used above the fused size limit also passes it through.

Why it is needed: Gemma-style norms (e.g. Qwen3.5's GemmaRMSNorm) used to get this fusion only by precomputing a 1 + w copy of the weight. That copy has two problems:

  • In-place weight updates such as an RLHF rollout sync do not refresh it, so the model keeps normalizing with the old weight and nothing raises.
  • It rounds 1 + w to bf16.

With this PR the caller passes the weight itself, and both problems go away.

Changes

Kernels (csrc/include/custom_all_reduce.cuh)

The per-group epilogue ar_fusion_epilogue_per_group already took a GEMMA_NORM template parameter; the per-token path uses the same w += 1.0f in fp32. What was missing:

Path Before After
allreduce_fusion_kernel_1stage_per_group (launcher) GEMMA_NORM hard-coded to false from the gemma_norm argument
allreduce_fusion_kernel_2stage_per_group no GEMMA_NORM parameter GEMMA_NORM template parameter
local_device_load_rmsnorm_quant_per_group_naive (split) no GEMMA_NORM parameter GEMMA_NORM template parameter
dispatchFusedAllReduceRMSNormQuantPerGroup — takes gemma_norm and forwards it to the launcher it picks
  • A small helper, per_group_launch_flags, turns the two runtime flags (transpose_scale, gemma_norm) into compile-time tags, matching how the launchers already handled transpose_scale.
  • With gemma_norm=false, every path instantiates the same kernel as before.

C++ entry / bindings (csrc/kernels/custom_all_reduce.cu, csrc/include/custom_all_reduce.h, csrc/include/rocm_ops.hpp, aiter/ops/custom_all_reduce.py)

fused_allreduce_rmsnorm_quant_per_group gets a trailing gemma_norm=false argument. Existing positional callers are unaffected.

Python (aiter/dist/)

  • custom_all_reduce.py: fused_ar_rms_per_group_quant and custom_fused_ar_rms_per_group_quant, including the CUDA-graph capture path.
  • communicator_cuda.py:
    • fused_allreduce_rmsnorm_quant_per_group forwards the flag to the fused kernel and to its fallback (fused_allreduce_rmsnorm(..., gemma_norm=...) + per-group quant).
    • The generic fused_allreduce_rmsnorm_quant now accepts gemma_norm for per_group; MXFP4 still raises NotImplementedError.
  • parallel_state.py: both registered ops (fused_allreduce_rmsnorm_quant_per_group_ and its _emit_bf16_ variant), their fake implementations, GroupCoordinator.fused_allreduce_rmsnorm_quant_per_group and _fused_allreduce_rmsnorm_quant_per_group_out_place. The flag does not change output shapes or strides.
  • communication_op.py: the per-group branch forwards gemma_norm instead of dropping it.

Test (op_tests/multigpu_tests/test_fused_ar_rms_per_group_quant.py)

  • New gemma_norm axis; the default sweeps both values, and --gemma-norm 0|1 pins one.
  • The reference is computed in fp32: rms_norm(x) * (w.float() + 1).

Unchanged: with gemma_norm=True the non-quant path still skips the quick-reduce fused RMSNorm branch (communicator_cuda.py, and not gemma_norm), as before.

Testing

python3 test_fused_ar_rms_per_group_quant.py -t 4 -d bf16 -s 1,4096 13,4096 16,4096 24,4096 32,4096 64,4096 128,4096 512,4096 2048,4096 8192,4096 16384,4096, on MI355X (gfx950), TP4:

  • Coverage: 88 cases (11 shapes × emit_bf16 × transpose_scale × gemma_norm). They span the 1-stage (≤ 16 tokens), 2-stage (≤ 64), split, and ≥ 64 MB fallback (8192 / 16384 tokens) paths.

  • Correctness: all cases pass checkAllclose(atol=0.05, rtol=0.05), plus the scale-stride and bf16-vs-fp8 checks. Exit code 0.

  • Latency: the same with and without gemma_norm. Min µs per call, row-major scale, no bf16 output:

    tokens gemma_norm=False gemma_norm=True
    24 11.48 11.57
    512 53.92 53.95
    16384 1318.29 1318.29
  • End to end: with this patch applied on top of 72546b3de, Qwen3.5-397B-A17B-FP8 (TP4, MTP3) in ATOM runs allreduce_fusion_kernel_1stage<bf16, bf16, 4, true> and allreduce_fusion_kernel_2stage_per_group<bf16, fp8, 4, GEMMA_NORM=true, TRANSPOSE_SCALE=true> in decode. gsm8k (first 250, InferenceX recipe) scores 246/250, against 248/250 for the previous precomputed-1 + w approach (±0.008 stderr).

Downstream user: ROCm/ATOM#2520 (Qwen3.5 decode fusion). It detects this capability from the gemma_norm parameter of GroupCoordinator.fused_allreduce_rmsnorm_quant_per_group and turns the fusion off on older aiter.

Signed-off-by: zhuyuhua-v <[email protected]>
@zhuyuhua-v
zhuyuhua-v requested review from a team and a balanced review from Copilot October 13, 2026 07:33
@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 (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
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 6472 --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.

@github-actions github-actions Bot changed the title [Dist] Support gemma_norm in fused all-reduce + RMSNorm + per-group FP8 quant [HIP] [Dist] Support gemma_norm in fused all-reduce + RMSNorm + per-group FP8 quant Oct 13, 2026
@github-actions github-actions Bot added the HIP label Oct 13, 2026

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 strided fallback rounds 1 + w before normalization, and the CUDA-graph forwarding path remains untested.

1 open finding
What changed in this PR

Adds Gemma-style RMSNorm support to fused all-reduce with per-group FP8 quantization.

Changes:

  • Propagates gemma_norm through Python, bindings, dispatch, and all kernel paths.
  • Adds compile-time Gemma/scale-layout kernel dispatch.
  • Extends the multi-GPU correctness sweep.
File Description
csrc/​include/​custom_all_reduce.cuh Adds Gemma support to all per-group kernels.
csrc/​kernels/​custom_all_reduce.cu Forwards the new native argument.
csrc/​include/​custom_all_reduce.h Updates the C++ declaration.
csrc/​include/​rocm_ops.hpp Exposes the optional binding argument.
aiter/​ops/​custom_all_reduce.py Updates the Python op signature.
aiter/​dist/​parallel_state.py Threads the flag through registered operations.
aiter/​dist/​device_communicators/​custom_all_reduce.py Forwards the flag through custom AR and capture paths.
aiter/​dist/​device_communicators/​communicator_cuda.py Enables per-group dispatch and fallback behavior.
aiter/​dist/​communication_op.py Exposes per-group Gemma behavior publicly.
op_tests/​multigpu_tests/​test_fused_ar_rms_per_group_quant.py Adds Gemma cases and reference calculations.

🧠 Review effort: Balanced


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

Signed-off-by: zhuyuhua-v <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 08:01

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 non-contiguous fallback can still round 1 + weight in fp16/bf16, and the tests can silently pass through the unfused fallback.

2 open findings
1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Silent fallback can hide failures in fused kernel dispatch

op_tests/​multigpu_tests/​test_fused_ar_rms_per_group_quant.py:280

This test calls the public communicator path, but that path catches every exception from custom_fused_ar_rms_per_group_quant and silently runs the unfused RMSNorm-plus-quant fallback. Consequently, all Gemma comparisons can pass even if the new 1-stage, 2-stage, or split kernel instantiations fail to launch or are never selected. Add a forced/direct fused-kernel check (or an observable assertion that no fallback occurred) for shapes in each dispatch range.

🧠 Review effort: Balanced

@XiaobingSuper
XiaobingSuper requested a review from zufayu October 13, 2026 08:54
@zufayu
zufayu requested a review from TennyWang1223 October 14, 2026 06:29
@zufayu zufayu self-assigned this Oct 14, 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

@zufayu
zufayu merged commit 301650a into main Oct 14, 2026
@zufayu
zufayu deleted the yuhua/ar-gemma-fuse branch October 14, 2026 07:29
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.

5 participants