Skip to content

Fix OOB access in qmv - #1577

Merged
barronalex merged 2 commits into
mainfrom
qmv-fix
Nov 8, 2024
Merged

barronalex merged 2 commits into
mainfrom
qmv-fix

Conversation

@barronalex

@barronalex barronalex commented Nov 8, 2024 •

Copy link
Copy Markdown
Contributor

This was breaking quantized generation with SmolLM2-135M-Instruct specifically with group size 32.

No clear difference in performance before and after (tested with group size 64 which still worked on main).

Before:

Prompt: 38 tokens, 629.657 tokens-per-sec
Generation: 574 tokens, 261.939 tokens-per-sec
Peak memory: 0.164 GB

After:

Prompt: 38 tokens, 630.536 tokens-per-sec
Generation: 574 tokens, 262.050 tokens-per-sec
Peak memory: 0.164 GB

Comment thread mlx/backend/metal/kernels/quantized.h Resolved

@angeloskath angeloskath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Tracking these down is really hard!

I left a comment I think it would make it a bit clearer and probably result in the same exact perf as your fix.

Also not certain looking at the benchmark but that is with 32 group size on SmolLM? Cause other sizes may not route to this kernel and could route to the qmv_fast_impl...

Comment thread mlx/backend/metal/kernels/quantized.h Resolved
@barronalex

Copy link
Copy Markdown
Contributor Author

No worries! Totally agree with the comment -- I updated it.

The benchmark is with group size 64 since that worked with main. The qmv size is (192, 576) so it should never go to qmv_fast (also I don't think group size affects the routing at the moment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants