Repository navigation
[Triton/Gluon] Add fused gated RMSNorm + MXFP4 quant - #6038
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
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
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.
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]>
19dcd41 to
cc066cb
Compare
…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]>
cc066cb to
500a2da
Compare
…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]>


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_quantdoes 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_projGEMM instead, for models whoseout_projis 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)inaiter/ops/triton/quant/fused_mxfp4_quant.py, with a unit test and a benchmark. No existing op changes.rms_norm(x) * weight * act(z)(orrms_norm(x * act(z)) * weightwithnorm_before_gate=False), asRMSNormGateddoes, withactivation"silu"or"sigmoid", passed to the kernel through_get_activation_from_str. The RMS is pergroup_sizeslice of a row (one GDN head), or per whole row if None.group_sizemust be a multiple of 32, so no MXFP4 block spans two groups.ytox.dtype, then quantizes with the shared_mxfp4_quant_op, so the codes and scales match norm followed bydynamic_mxfp4_quant.gemm_afp4wfp4_preshuffletakes them.transpose_scale=Truestores them column-major, likedynamic_mxfp4_quant, becausegemm_afp4wfp4reads that layout up to 2x faster from M=1024 (table below).Test Plan
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-Nextout_projshapes.Test Result
The test tolerates up to 1 in 100,000 differing codes: the kernel's
rsqrtand 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 bydynamic_mxfp4_quant.group_size128, sigmoid gate, bf16,transpose_scale=True,do_bench_cudagraph. Lower is better.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_afp4wfp4at N=2560 reading the same scales row-major → column-major, µs. Lower is better.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]