Fix non transposed affine qmm dispatch logic - #4392
Open
RohanGautam wants to merge 1 commit into
Open
Conversation
RohanGautam
marked this pull request as ready for review
August 25, 2026 07:39
Collaborator
|
Looks good to me! We probably have the same issue in Regarding mlx-lm, ml-explore/mlx-lm#1781 proposed to add a prefill size as an argument, so it is more controllable now! |
nastya236
self-requested a review
August 25, 2026 22:01
nastya236
approved these changes
Aug 25, 2026
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.
The path for using the non-transposed NAX
qmmkernel was unreachable in the current implementation (because of the conditionif (has_nax_kernel && transpose && (K % 64 == 0) ...- lets only the transposed case through).We needed to add some more conditions:
benchmarks
The benchmarks are run with
mlx_lmlinked to the different mlx versions. The non-transposed path is exercised for large prefills (when chunked), for the quantized kv cache computations. We usemlx_lm.generate(notbenchmark, to use the kv cache quantisation options) . The command run ismlx_lm.generate --model <model> -p - --ignore-chat-template --max-tokens 8 --temp 0 --kv-bits 4 --quantized-kv-start 0 < <file withprompt of desired size>.txtThe 4096 one has no changes because of
mlx-lmusing N-1 tokens instead of N tokens. There is only one quantised kv cache to attend over, and this is the wrong size for the non-transposed qmm to kick in (it does not have a ragged-K variant). The last chunk for all others also go through the normal path, just the middle ones don't and are sped up with this PR. This boundary effect can be seen below, and is perhaps something to address in mlx-lm down the line.