Repository navigation
[Triton/Gluon] Make scaleM_pad a runtime argument in the act_mul + MXFP4 quant kernels - #5927
Conversation
…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.
🏷️ 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
🟢 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_padfromtl.constexprto 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.
|
This also affects ROCm/ATOM. I measured that exact call: 14 token counts, N1 = 2304, a fresh Triton cache, Triton
Outputs and scales are bit-identical to The PR's workflows are all at |
Makes
scaleM_pada 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_padastl.constexpr:_act_mul_and_dynamic_mxfp4_quant_kernel, behindact_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_projGEMM, for Gemma 4 31B on MI355X. In a vLLM serving trace near saturation:gate_upGEMM and this kernel.Those gaps are Triton compiles happening mid-serving.
Technical Details
scaleM_padis only read in one mask comparison: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
== 1and 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_padfrom the fused kernel'smake_kernel_reprkey list. That repr reads specialization constants, so a runtime argument would render asscaleM_pad_None.Test Result
On one MI355X (gfx950) against
main(330f127), I sweptact_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:mainOn
main, each of the 12 compiles is a new 256-row bucket ofM. With this PR, the 4 that remain are the kernel's distinctEVEN_M_Nand block configurations. With seeded inputs, outputs are bit-identical tomainfor 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.post2with the same one-line change, the stalls disappeared from the trace. There, a GELU(tanh) times up + MXFP4 quant fusion ahead of the a4w4down_projwent from looking like a regression at the latency knee to +1.8% prefill throughput.Submission Checklist