Skip to content

[Triton/Gluon] [Perf] Fix dynamic_mxfp4_quant launch grid for decode-sized M - #6018

Closed
reger-men wants to merge 2 commits into
ROCm:mainfrom
reger-men:mxfp4-quant-decode-launch
Closed

reger-men wants to merge 2 commits into
ROCm:mainfrom
reger-men:mxfp4-quant-decode-launch

Conversation

@reger-men

Copy link
Copy Markdown
Contributor

For M > 32 and N <= 16384, dynamic_mxfp4_quant launches one BLOCK_SIZE_M=32 x (BLOCK_SIZE_N=128 * NUM_ITER=4) tile per program. At decode batch sizes thats almost no programs: M=64, N=4096 gives a 2x8 grid, 16 programs on a 256 CU part. Kernel time doubles going from M=32 to M=48 (2.93 -> 6.59 us at N=4096) and it ends up 2.3-2.4x slower than the HIP per_1x32 quant there.

This adds a 16 < M <= 64 branch that launches one 16x128 tile per program. I swept BLOCK_SIZE_M/N, NUM_ITER, warps and stages at M 1-64 for N=4096 and N=14336, and that tile is within 0.11 us of the best launch everywhere from M=8 to M=64. M <= 16 keeps the old launch, M > 64 and the N <= 1024 path are unchanged.

Quant is per row and per 32-element block, so the tiling doesn't touch the math. Output bytes (fp4 payload and e8m0 scales) are identical to the old launch on 119 (M, N) points, M 1-128 and N 256-28672, for round-to-nearest and for stochastic rounding. The existing test_dynamic_mxfp4_quant cases never reach this branch (M is 1 or >= 128 there), so I added decode-sized shapes with large N. 48 passed on the old launch and on the new one.

Kernel time, old -> new:

  • N=4096 M=24 2.98 -> 2.74, M=32 2.93 -> 2.69, M=48 6.59 -> 2.72, M=64 6.36 -> 2.72 us
  • N=14336 M=24 3.12 -> 2.80, M=32 3.17 -> 2.73, M=48 6.72 -> 2.94, M=64 6.48 -> 3.00 us

Served Llama-3.1-8B-Instruct MXFP4 (W4A4) under vLLM on one MI355X, where the MXFP4 linear quantizes its activation through this function. GPU idle, clock pinned, tuned decode configs in place, p50 ms/tok: bs32 3.401 -> 3.334 (-2.0%), bs64 4.104 -> 3.655 (-10.9%), bs1-16 unchanged. Greedy output is byte-identical, and at full size GSM8K, ARC-Challenge and MMLU pick the same answer on every item.

It's independent of #6015 (the afp4wfp4 decode configs, different files), either can go first.

This overlaps #4383, which sends gfx950 bf16 input to a new Gluon quant kernel. Its M 33..64 config is the same 32x512 tile per program, so the small grid would come back there. This PR speeds up the Triton path that ships today. If #4383 lands first I'll port the change into its Gluon config bucket and re-measure. #4894 and #3494 touch the same launch block too.

@reger-men
reger-men requested a review from a team September 30, 2026 17:56
@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
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 6018 --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

Launch tuning must move to configuration data, and the stochastic-rounding path needs coverage for the new branch.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Optimizes Triton MXFP4 quantization for decode-sized batches by increasing launch parallelism.

Changes:

  • Adds a 16×128 launch configuration for 16 < M <= 64.
  • Adds boundary and representative decode-shape tests.
File Description
aiter/​ops/​triton/​quant/​quant.py Adds the decode-sized launch branch.
op_tests/​triton_tests/​quant/​test_quant_mxfp4.py Adds coverage for affected shapes.

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

Comment on lines +241 to +244
(17, 4096),
(32, 4096),
(48, 4096),
(64, 4096),
Comment on lines +293 to +297
NUM_ITER = 1
BLOCK_SIZE_M = 16
BLOCK_SIZE_N = 128
NUM_WARPS = 4
NUM_STAGES = 1
@reger-men

Copy link
Copy Markdown
Contributor Author

@Dewei-Wang-sh could you have a look when you get a chance?

The review comment on the SR test was right: the reproducibility shapes all had N <= 1024, so the small-N override picked the launch and the new 16x128 tile never ran with use_sr=True. I added (40, 4128), partial tile in both M and N, and (64, 14336). Full test_quant_mxfp4.py on MI355X is 54 passed, the 48 skips are the gfx1250-only nvfp4 cases. I also compared this branch against main byte for byte over 408 cases (M 1..128, N 1024..28672, RTN bf16 and SR bf16/fp32 with a fixed seed and offset), none differ, so the SR output doesnt depend on the tile either.

On moving the bucket to JSON: dynamic_mxfp4_quant has no config loader on main, the whole launch block in quant.py is the existing if-chain and this PR adds one branch to it. #4383 is the one that adds quant_config_utils and configs/gfx950/gluon/quant/mxfp4/. I'd rather not add a second quant loader next to it, so once #4383 lands I'll move this bucket into that config (for gfx950 bf16 it then runs the Gluon kernel anyway). Rebased on main.

For M > 32 and N <= 16384, dynamic_mxfp4_quant launches one
BLOCK_SIZE_M=32 x (BLOCK_SIZE_N=128 * NUM_ITER=4) tile per program. At
decode batch sizes that is almost no programs: M=64, N=4096 gives a 2x8
grid, 16 programs on a 256 CU part. Kernel time doubles going from M=32
to M=48 (2.93 -> 6.59 us at N=4096, 3.17 -> 6.72 us at N=14336) and it
is 2.3-2.4x slower than the HIP per_1x32 quant there.

This adds a 16 < M <= 64 branch that launches one 16x128 tile per
program. I swept BLOCK_SIZE_M/N, NUM_ITER, warps and stages at M 1-64
for N=4096 and N=14336, and that tile is within 0.11 us of the best
launch everywhere from M=8 to M=64. M <= 16 keeps the old launch (the
gain there is under 0.1 us), M > 64 and the N <= 1024 path are
unchanged.

Quant is per row and per 32-element block, so the tiling does not touch
the math. Output bytes (fp4 payload and e8m0 scales) are identical to
the old launch on 119 (M, N) points, M 1-128 and N 256-28672, for both
round-to-nearest and stochastic rounding. The existing
test_dynamic_mxfp4_quant cases never reach this branch (M is 1 or >= 128
there), so I added decode-sized shapes with large N.

Kernel time, old -> new:

- N=4096   M=24 2.98 -> 2.74, M=32 2.93 -> 2.69, M=48 6.59 -> 2.72, M=64 6.36 -> 2.72 us
- N=14336  M=24 3.12 -> 2.80, M=32 3.17 -> 2.73, M=48 6.72 -> 2.94, M=64 6.48 -> 3.00 us

Served, Llama-3.1-8B-Instruct-MXFP4-W4A4 under vLLM on MI355X (the MXFP4
linear quantizes its activation through this function), GPU idle, clock
pinned, p50 ms/tok:

- bs32  3.401 -> 3.334 (-2.0%)
- bs64  4.104 -> 3.655 (-10.9%)

bs1-16 unchanged, greedy output byte-identical.

Signed-off-by: adlashab <[email protected]>
The SR shapes in the reproducibility test all have N <= 1024, so the
small-N override picks their launch and the new 16x128 tile was not
exercised with use_sr=True. Add (40, 4128), which has a partial tile
in both M and N, and (64, 14336).

Signed-off-by: adlashab <[email protected]>
@reger-men
reger-men force-pushed the mxfp4-quant-decode-launch branch from 158f622 to a1fbd9f Compare October 5, 2026 16:13
@azaidy
azaidy requested a review from NimitPtl October 5, 2026 22:36
(48, 4096),
(64, 4096),
(40, 7168),
(64, 14336),

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.

#4383 has been merged.
This includes additional test shapes to increase test coverage.

@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.

Would recommend to review and incorporate changes recommended by the co-pilot review bot.

@reger-men

Copy link
Copy Markdown
Contributor Author

@NimitPtl thanks, #4383 covers what this PR was for, so I'm closing it as superseded. I measured on MI355X (64 calls per cudagraph replay, clock pinned): on main the bf16 no-SR call now goes to the Gluon kernel, and at 16 < M <= 64 it runs 2.6-2.9 us for N=4096 and 14336, same as M 4..16. Before #4383 the Triton 32x512 tile took 6.3-6.8 at M 33..64. Putting my 16x128 tile into the JSON doesnt help on Gluon (equal at N=4096, up to 0.3 us slower at 14336), so there is nothing left to port.

Two things I noticed while measuring:

  • the M_LEQ_1 / M_LEQ_2 entries make M=1 and M=2 slower than M=4. On main today M=1 takes 4.6-5.1 us and M=2 3.1-3.7 for N from 1088 to 28672. A 1x512 tile for both buckets brings them to 2.5-2.7 us with byte identical output, I opened [Triton/Gluon] [Config] [Perf] [gfx950] Use 1x512 Gluon MXFP4 quant tiles for M <= 2 #6443 for it (JSON only).
  • the Triton fallback (use_sr=True, or fp16/fp32 input) still uses the 32x512 coverage at M 33..64, 5.8-6.2 us at N=4096 vs 2.7 with a 16x128 tile. I can send a small PR for that one if you want it.

@reger-men reger-men closed this Oct 12, 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