Repository navigation
Tune quant dispatch - #2031
Merged
Merged
Tune quant dispatch#2031
Conversation
Member
Author
|
For Mistral 7B batched we get a nice speedup on M2 Ultra especially at small batch sizes:
Benchmark: import time
import mlx.core as mx
from mlx_lm import load
model, _ = load("mlx-community/mistral-7B-Instruct-v0.3-4bit")
for batch_size in [6, 8, 10]:
prompt = mx.array([[0] * batch_size])
for _ in range(10):
mx.async_eval(model(prompt))
tic = time.time()
for _ in range(10):
mx.async_eval(model(prompt))
toc = time.time()
ms = 1000 * (toc - tic) / 10
print(f"{ms:.3f}") |
angeloskath
approved these changes
Apr 1, 2025
angeloskath
left a comment
Member
There was a problem hiding this comment.
This looks great! I doubt that the limits transfer from qmv_fast to qmv and qmv_quad but I think these are also rare enough that it wouldn't matter too much.
Member
Author
|
It's true I didn't tune for those at all. I just checked |
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.
Tune quant dispatch conditions to qmv vs qmm.
The optimal is both machine and matrix size dependent unfortunately so this is only an approximation. It's conservative in that we continue to route to the qmm unless it's pretty clear that there is a speedup to be had.
In the plots below:
Here's a benchmark comparing the two at size = 4096 on a few machines:
Another benchmark for just M2 Ultra for 3 different sized matrices:
Same benchmark on M3 Max: