Skip to content

[Triton/Gluon] Add fused gated RMSNorm + MXFP4 quant - #6038

Merged
azaidy merged 5 commits into
ROCm:mainfrom
mjkvaak-amd:triton/fused-rms-gated-mxfp4-quant
Oct 21, 2026
Merged

azaidy merged 5 commits into
ROCm:mainfrom
mjkvaak-amd:triton/fused-rms-gated-mxfp4-quant

Conversation

@mjkvaak-amd

@mjkvaak-amd mjkvaak-amd commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

GDN layers with an MXFP4 out_proj (Qwen3.5, Qwen3.8) run a gated RMSNorm and then a separate MXFP4 activation quant before the GEMM. fused_rms_gated_mxfp4_quant does both in one kernel. AITER already has the gated FP8 version (fused_rms_gated_fp8_group_quant) and the ungated MXFP4 one (fused_rms_mxfp4_quant). vllm-project/vllm#59553 uses it.

No duplicate among open PRs; #5881 fuses the gated norm into a BF16 out_proj GEMM instead, for models whose out_proj is not quantized.

Technical Details

New op fused_rms_gated_mxfp4_quant(x, weight, z, eps, *, norm_before_gate=True, activation="silu", group_size=None, transpose_scale=False) in aiter/ops/triton/quant/fused_mxfp4_quant.py, with a unit test and a benchmark. No existing op changes.

  • Computes rms_norm(x) * weight * act(z) (or rms_norm(x * act(z)) * weight with norm_before_gate=False), as RMSNormGated does, with activation "silu" or "sigmoid", passed to the kernel through _get_activation_from_str. The RMS is per group_size slice of a row (one GDN head), or per whole row if None. group_size must be a multiple of 32, so no MXFP4 block spans two groups.
  • Rounds y to x.dtype, then quantizes with the shared _mxfp4_quant_op, so the codes and scales match norm followed by dynamic_mxfp4_quant.
  • Returns fp4 codes (M, N // 2) and e8m0 scales (M, N // 32), unshuffled. Scales are row-major by default, as gemm_afp4wfp4_preshuffle takes them. transpose_scale=True stores them column-major, like dynamic_mxfp4_quant, because gemm_afp4wfp4 reads that layout up to 2x faster from M=1024 (table below).
  • The launch split (512 elements per warp) does not depend on M, so a row's result does not either.

Test Plan

  • MI355X (gfx950), AITER v0.1.25 in the vLLM ROCm nightly container, with this branch's sources.
  • python3 -m pytest -q op_tests/triton_tests/quant/test_fused_mxfp4_quant.py -k rms_gated: one correctness test against a torch reference, after dequantization. It covers the GDN shape (N=3072, group 128), a whole row of 256 with a masked tail, and a whole row of 4096 on several warps, at M=1 and 1000. Two variants between them cover both gate orders, both activations, bf16 and fp16, and both scale layouts.
  • op_tests/op_benchmarks/triton/bench_fused_rms_gated_mxfp4_quant.py, and the fused kernel against the norm + quant it replaces in vLLM, at the Qwen3.8-Flash-Next out_proj shapes.

Test Result

op_tests/triton_tests/quant/test_fused_mxfp4_quant.py -k rms_gated
12 passed, 2356 deselected in 5.43s

The test tolerates up to 1 in 100,000 differing codes: the kernel's rsqrt and torch's can differ in the last bit, which moves a value sitting on an E2M1 rounding boundary.

Kernel, µs per call, against the gated norm vLLM runs today (Inductor-compiled, or FLA's rmsnorm_fn) followed by dynamic_mxfp4_quant. group_size 128, sigmoid gate, bf16, transpose_scale=True, do_bench_cudagraph. Lower is better.

M N=6144: fused Inductor norm + quant FLA norm + quant N=3072: fused Inductor norm + quant FLA norm + quant
1 2.0 5.1 4.1 2.0 6.1 3.6
16 2.1 7.0 4.1 2.1 6.9 4.3
64 2.2 9.3 6.8 2.2 9.1 6.6
1024 9.6 16.5 16.1 5.8 12.1 11.5
8192 63.6 78.7 81.8 33.3 41.7 42.5

The codes and scales are identical to Inductor norm + quant in every cell. At small M the fused kernel costs one launch instead of two; at large M it saves writing out and re-reading the normalized activation.

Scale layout, gemm_afp4wfp4 at N=2560 reading the same scales row-major → column-major, µs. Lower is better.

K M=512 M=1024 M=8192
6144 19.3 → 18.4 110.5 → 86.2 222.6 → 173.0
768 7.5 → 6.2 29.0 → 14.0 59.4 → 29.1

In vLLM (vllm-project/vllm#59553, Qwen3.8-Flash-Next on MI355X, measured before the activation change, which makes the kernel 2–8% faster): gated norm + quant + GEMM is 20–49% faster at M ≤ 512 and 2–18% faster at M = 1024–8192. Serving output throughput rises 0.6% (geomean, 3 repeats, TP2), with GSM8K and NIAH unchanged.

Submission Checklist

Co-authored-by: Cursor [email protected]

@mjkvaak-amd
mjkvaak-amd requested a review from a team October 1, 2026 05:58
@github-actions github-actions Bot changed the title [Triton] [Kernel] Add fused gated RMSNorm + MXFP4 quant [Triton/Gluon] [Kernel] Add fused gated RMSNorm + MXFP4 quant Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

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
multigpu 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: 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 6038 --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.

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

🟡 Changes recommended

Runtime validation must not rely on removable assertions, and the new kernel needs a checked-in benchmark.

Review effort: Balanced
Findings: 1 High severity · 2 Low severity

Open (3)
What changed in this PR

Adds fused gated RMSNorm and MXFP4 quantization to reduce decode-time kernel launches and intermediate memory traffic.

Changes:

  • Adds and exports the public quantization wrapper.
  • Implements the Triton fused kernel.
  • Adds numerical coverage across shapes, dtypes, activations, and gate ordering.
File Description
aiter/​ops/​triton/​quant/​fused_mxfp4_quant.py Adds validation, allocation, and kernel launch logic.
aiter/​ops/​triton/​_triton_kernels/​quant/​fused_mxfp4_quant.py Implements fused normalization, gating, and MXFP4 quantization.
aiter/​ops/​triton/​quant/​__init__.py Exports the new public API.
op_tests/​triton_tests/​quant/​test_fused_mxfp4_quant.py Adds numerical and shape tests.

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

@zufayu
zufayu requested review from a team and vgokhale October 2, 2026 00:34
@mjkvaak-amd
mjkvaak-amd marked this pull request as draft October 2, 2026 07:08
@zufayu
zufayu removed request for a team and vgokhale October 3, 2026 00:31
@azaidy azaidy assigned azaidy and unassigned vgokhale Oct 5, 2026
mjkvaak-amd and others added 3 commits October 19, 2026 23:07
fused_rms_gated_mxfp4_quant runs RMSNormGated (per-group RMSNorm with a
SiLU or sigmoid z gate, before or after the norm) and the per-1x32 MXFP4
activation quant in one launch, writing unshuffled e8m0 scales. This is
the input of an MXFP4 linear after a gated norm, such as the GDN out_proj
in Qwen3.5/3.8 with online MXFP4 quantization, which today runs the norm
and the quant as two kernels.

The gated activation is rounded to the input dtype before quant, as in
the unfused sequence.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
Shape, contiguity, activation and weight-size checks raised through
assert, which python -O strips; an unsupported activation then ran as
SiLU and a short weight read out of bounds. They now raise ValueError,
the docstring covers eps, norm_before_gate and the group_size contract,
and op_tests/op_benchmarks/triton/bench_fused_rms_gated_mxfp4_quant.py
times the kernel at the Qwen3.8-Flash-Next out_proj shapes against the
MXFP4 quant alone and the unfused torch sequence.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
gemm_afp4wfp4 reads row-major activation scales up to 2x slower than the
column-major ones dynamic_mxfp4_quant returns once M reaches 1024, which
erased the fused kernel's gain in prefill. transpose_scale=True stores the
scales column-major, with the same values.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd
mjkvaak-amd force-pushed the triton/fused-rms-gated-mxfp4-quant branch from 19dcd41 to cc066cb Compare October 19, 2026 23:14
…oup size

512 elements per warp (BLOCK_SIZE_M=4 on one warp at group_size 128),
whatever the row count. At group_size 128 on MI355X that is 10-21% faster
than the row-count based choice from 512 tokens up, and within 0.4 us of
the best swept split in decode. Adds a whole-row group_size=None case at
N=4096 to the test, which takes the multi-warp branch.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd
mjkvaak-amd force-pushed the triton/fused-rms-gated-mxfp4-quant branch from cc066cb to 500a2da Compare October 19, 2026 23:29
@mjkvaak-amd mjkvaak-amd changed the title [Triton/Gluon] [Kernel] Add fused gated RMSNorm + MXFP4 quant [Triton] [Kernel] Add fused gated RMSNorm + MXFP4 quant Oct 20, 2026
@mjkvaak-amd
mjkvaak-amd marked this pull request as ready for review October 20, 2026 19:12
@github-actions github-actions Bot changed the title [Triton] [Kernel] Add fused gated RMSNorm + MXFP4 quant [Triton/Gluon] [Kernel] Add fused gated RMSNorm + MXFP4 quant Oct 20, 2026
@mjkvaak-amd mjkvaak-amd changed the title [Triton/Gluon] [Kernel] Add fused gated RMSNorm + MXFP4 quant [Triton/Gluon] Add fused gated RMSNorm + MXFP4 quant Oct 20, 2026
@zufayu
zufayu requested a review from k50112113 October 21, 2026 01:31
@zufayu
zufayu requested a review from a team October 21, 2026 01:31
…unction

The kernel took the activation name and branched on it. It now takes the
jitted function from _get_activation_from_str, as the other fused quant
kernels do, with swish mapped to silu. The common activations use exp2,
which makes the kernel 2-8% faster at the Qwen3.8-Flash-Next out_proj
shapes on MI355X, and its codes differ from the torch reference in 11 of
494M elements, against 24 before.

The tests are reduced to one correctness test of 12 cases: the GDN group
shape, a whole row with a masked tail, and the multi-warp whole row, each
at M 1 and 1000, with every gate order, activation, dtype and scale layout
covered once.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
@mjkvaak-amd
mjkvaak-amd requested a review from azaidy October 21, 2026 06:46

@azaidy azaidy 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!

@azaidy
azaidy merged commit bc36872 into ROCm:main Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants