Repository navigation
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
Launch tuning must move to configuration data, and the stochastic-rounding path needs coverage for the new branch.
Review effort: Balanced
Findings: 1
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.
| (17, 4096), | ||
| (32, 4096), | ||
| (48, 4096), | ||
| (64, 4096), |
| NUM_ITER = 1 | ||
| BLOCK_SIZE_M = 16 | ||
| BLOCK_SIZE_N = 128 | ||
| NUM_WARPS = 4 | ||
| NUM_STAGES = 1 |
2f906e5 to
158f622
Compare
|
@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 On moving the bucket to JSON: |
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]>
158f622 to
a1fbd9f
Compare
| (48, 4096), | ||
| (64, 4096), | ||
| (40, 7168), | ||
| (64, 14336), |
There was a problem hiding this comment.
#4383 has been merged.
This includes additional test shapes to increase test coverage.
NimitPtl
left a comment
There was a problem hiding this comment.
Would recommend to review and incorporate changes recommended by the co-pilot review bot.
|
@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:
|


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