Repository navigation
Conversation
ahuzmeza
marked this pull request as ready for review
October 29, 2026 00:09
Member
|
This basically looks good to me, thanks for taking care of adding the kernel. Can you please rebase since now #4781 has been merged? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On GPUs without NAX, affine
quantized_matmulwith 3–16 rows never usesqmv_mma, becauseuse_qmv_mmareturns false for affine (quantized.cpp L645-647).Those shapes (batched decode, speculative decoding) fall back to
qmv/qmv_wideor toqmm, whose 32-row tiles are mostly padding at this size. #4712 addedqmv_mmafor the fp formats only. This is the non-NAX side of the picture.This PR ports #4712's
fp_qmv_mmato affine for non-NAX GPUs:Results
End to end on an M2 Pro,
mlx-community/gemma-4-e4b-it-4bit,mlx_lm.benchmark -p 512 -g 128 -b 8 -n 2:batch-8 decode goes from 70.0 to 202.1 tok/s (2.89×). Batch 1 remains unchanged.
Speedup over main, chained Qwen3-4B decoder shapes, bf16, group size 64 (95% intervals in the details below):
mxfp8 is the control and measures 1.00 throughout.
Part of the 6–8-row gain on the M2 Pro comes from main's own dispatch. On gen 13/14, main's batch limit sends the MLP projections to
qmm, which is slower there than main'sqmv. Measured against main with that limit raised, the gain at 6–8 rows is 2.09–2.84×, and batch-8 decode goes from 81.5 to 201.0 tok/s (2.47×).Overlap with #4781
Both PRs use the same plumbing change. I'm happy to rebase onto #4781 if it lands first.
Measured on the M2 Pro (gen 14) and the M4 (gen 16).
Unmeasured: M1 (gen 13), M3 (gen 15) and A-series phones, enabled by generation.
Non-affine and NAX dispatches are unchanged.
95% intervals
M2 Pro (16-core), main VS. this branch, speedup [95% interval]
[1.14, 1.15]
[1.43, 1.46]
[1.74, 1.79]
[2.88, 3.00]
[3.05, 3.09]
[3.14, 3.15]
[1.96, 1.97]
[1.91, 1.96]
[1.88, 1.95]
[1.15, 1.18]
[1.50, 1.51]
[1.84, 1.86]
[3.27, 3.28]
[3.34, 3.34]
[3.41, 3.43]
[2.07, 2.08]
[2.05, 2.06]
[2.02, 2.02]
M4 (10-core), same
[1.02, 1.03]
[1.03, 1.03]
[1.07, 1.11]
[1.23, 1.27]
[1.42, 1.47]
[1.56, 1.60]
[1.87, 1.89]
[1.82, 1.83]
[1.10, 1.13]
[1.33, 1.36]
[1.55, 1.60]
[1.81, 1.86]
[2.16, 2.22]
[1.52, 1.55]
[1.82, 1.85]
[1.92, 1.93]
Method
Chained decoder forward pass on Qwen3-4B shapes, bf16, group size 64. 10 rounds per build in separate processes, alternating. (ratio of medians with a 95% bootstrap interval). mxfp8 is the control. Details are in the script below.
Benchmark script (to reproduce)
Install main and this branch in two venvs, then: