Skip to content

[Triton/Gluon] Make scaleM_pad a runtime argument in the act_mul + MXFP4 quant kernels - #5927

Merged
azaidy merged 2 commits into
ROCm:mainfrom
OpenRelayInc:mxfp4-act-quant-scalem-pad-runtime
Oct 7, 2026
Merged

azaidy merged 2 commits into
ROCm:mainfrom
OpenRelayInc:mxfp4-act-quant-scalem-pad-runtime

Conversation

@prashant182

@prashant182 prashant182 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Makes scaleM_pad a runtime argument in the two act_mul + MXFP4 quant Triton kernels, so they stop JIT-compiling a new variant for every batch size.

Motivation

Two kernels declare scaleM_pad as tl.constexpr:

  • _act_mul_and_dynamic_mxfp4_quant_kernel, behind act_mul_and_mxfp4_quant;
  • _fused_reduce_act_mul_and_dynamic_mxfp4_quant_kernel.

With shuffled scales, scaleM_pad = cdiv(M, 256) * 256, so every distinct token count, rounded up to 256, compiles a new kernel variant. That is 64 or more variants up to 16K tokens.

We hit this after fusing GELU(tanh) times up plus the MXFP4 quant ahead of the a4w4 down_proj GEMM, for Gemma 4 31B on MI355X. In a vLLM serving trace near saturation:

  • 8.3% of mixed prefill/decode step time was idle;
  • 99% of that idle time sat in 7 gaps of about 190 ms each, between the gate_up GEMM and this kernel.

Those gaps are Triton compiles happening mid-serving.

Technical Details

scaleM_pad is only read in one mask comparison:

bs_mask = (bs_offs_m < scaleM_pad)[:, None] & (bs_offs_n < scaleN_pad)[None, :]

As a runtime integer the generated code is the same comparison against a scalar argument, so outputs cannot change. Triton still specializes integer arguments on == 1 and on divisibility by 16. The two values this argument takes (1 without padding, a multiple of 256 with it) therefore produce at most two variants.

The PR also drops scaleM_pad from the fused kernel's make_kernel_repr key list. That repr reads specialization constants, so a runtime argument would render as scaleM_pad_None.

Test Result

On one MI355X (gfx950) against main (330f127), I swept act_mul_and_mxfp4_quant(x, "gelu_tanh", shuffle=True) over 14 batch sizes (M = 16384, 9000, 5000, 3000, 1500, 700, 300, 257, 513, 1025, 4097, 12000, 144, 3) at Gemma 4 31B's gate/up width (2 x 21504), each process starting from a fresh Triton cache:

Kernel variants compiled Calls that compiled (>50 ms)
main 12 12 (~250 ms each)
This PR 4 4

On main, each of the 12 compiles is a new 256-row bucket of M. With this PR, the 4 that remain are the kernel's distinct EVEN_M_N and block configurations. With seeded inputs, outputs are bit-identical to main for all 14 sizes.

Op tests on gfx950 with this PR:

  • op_tests/triton_tests/test_activation.py -k mxfp4: 396 passed.
  • op_tests/triton_tests/quant/test_fused_mxfp4_quant.py -k act_mul: 288 passed.

In serving, measured on aiter v0.1.21.post2 with the same one-line change, the stalls disappeared from the trace. There, a GELU(tanh) times up + MXFP4 quant fusion ahead of the a4w4 down_proj went from looking like a regression at the latency knee to +1.8% prefill throughput.

Submission Checklist

…ant kernels

_act_mul_and_dynamic_mxfp4_quant_kernel and
_fused_reduce_act_mul_and_dynamic_mxfp4_quant_kernel declare scaleM_pad
(cdiv(M, 256) * 256 with shuffled scales) as tl.constexpr, but only use it
in a mask comparison. Every new token count rounded to 256 therefore
JIT-compiles a new kernel variant, which under serving load lands as
~0.2 s stalls mid-request. Pass it as a runtime argument and drop it from
the fused kernel's repr key list.
@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; main branch always runs both MI35X and MI300X
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 5927 --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.

@prashant182
prashant182 marked this pull request as ready for review September 29, 2026 06:58
@prashant182
prashant182 requested a review from a team September 29, 2026 06:58
@github-actions github-actions Bot changed the title [Triton] Make scaleM_pad a runtime argument in the act_mul + MXFP4 quant kernels [Triton/Gluon] Make scaleM_pad a runtime argument in the act_mul + MXFP4 quant kernels Sep 29, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot September 29, 2026 09:33

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

🟢 Approval recommended

The focused changes preserve mask semantics and are supported by broad correctness and compilation-variant testing.

Review effort: Balanced
Findings: None

What changed in this PR

Makes scaleM_pad runtime-bound in two MXFP4 quantization kernels, reducing shape-dependent Triton compilations without changing computation.

Changes:

  • Converts scaleM_pad from tl.constexpr to a runtime argument.
  • Removes the runtime value from the fused kernel’s specialization-based representation.
File Description
aiter/​ops/​triton/​_triton_kernels/​activation.py Makes scaleM_pad runtime-bound in activation/multiply quantization.
aiter/​ops/​triton/​_triton_kernels/​quant/​fused_mxfp4_quant.py Applies the same change to fused reduction and updates its kernel representation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@prashant182

Copy link
Copy Markdown
Contributor Author

This also affects ROCm/ATOM. atom/model_ops/activation.py calls fused_reduce_act_mul_and_mxfp4_quant(x, "silu", shuffle=True) on its MXFP4 SiLU path. That is the second kernel this PR changes, so ATOM's MLP recompiles for every new 256-row bucket of token count while it serves.

I measured that exact call: 14 token counts, N1 = 2304, a fresh Triton cache, Triton 3.8.0, one MI355X, main b68b0e5.

Calls that JIT-compiled Compile time
main 12 of 14 about 160 ms each, 610 ms for the first
This PR 4 of 14 the kernel's distinct EVEN_M_N / block variants

Outputs and scales are bit-identical to main for all 14 sizes.

The PR's workflows are all at action_required because the PR comes from a fork. @Dewei-Wang-sh, could you approve the CI run and take a look when you have a moment?

@azaidy
azaidy requested a review from NimitPtl October 5, 2026 22:39

@NimitPtl NimitPtl 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 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 d34df29 into ROCm:main Oct 7, 2026
2 checks passed
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.

5 participants