Skip to content

[Metal] Add 2, 3, 5 and 6 bits to affine qmv_mma - #4860

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
XXXXRT666:metal-affine-qmv-mma-bits
Nov 21, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
XXXXRT666:metal-affine-qmv-mma-bits

Conversation

@XXXXRT666

Copy link
Copy Markdown
Contributor

[Metal] Add 2, 3, 5 and 6 bits to affine qmv_mma

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: Benchmarking, Testing

Follow up to #4787. affine_qmv_mma now reads 2, 3, 5 and 6 bits, not only 4 and 8. On gen 15+ it is used from N * K = 2^20

Performance

Measured on M4, bf16, group size 64. Speedup of qmv_mma over the route of main for the same shape, > 1 is faster.

N * K below 2^21, geomean over 2, 3, 4, 5, 6 and 8 bits (range over bits):

N x K N * K M=4 M=5 M=6 M=8
512 x 512 2^18 0.93 (0.90-0.97) 0.97 (0.96-1.00) 1.03 (1.01-1.05) 1.15 (1.11-1.21)
512 x 1024 2^19 0.98 (0.90-1.05) 1.04 (0.99-1.09) 1.11 (1.09-1.12) 1.30 (1.25-1.39)
1024 x 1024 2^20 1.05 (0.99-1.11) 1.16 (1.12-1.20) 1.26 (1.21-1.32) 1.47 (1.32-1.66)
512 x 2048 2^20 1.01 (0.96-1.06) 1.12 (1.05-1.16) 1.22 (1.11-1.29) 1.47 (1.28-1.60)
1024 x 2048 2^21 1.03 (0.97-1.08) 1.11 (1.02-1.18) 1.18 (1.05-1.28) 1.41 (1.21-1.72)

2^20 is the smallest N * K that is not slower at 4 rows. 2^18 and 2^19 are faster from 6 rows, but slower at 4 and 5 rows.

New bits at large shapes (M = 4 to 6 from 8 rounds, M = 8 to 16 from 3 rounds):

N x K bits M=4 M=5 M=6 M=8 M=12 M=16
4096 x 4096 2 1.07 1.27 1.44 2.07 1.70 1.82
3 1.10 1.24 1.37 1.99 1.67 1.78
5 1.03 1.13 1.30 1.66 1.59 1.74
6 0.94 1.01 1.12 1.48 1.64 1.77
2560 x 9728 2 1.06 1.25 1.43 1.83 1.62 1.84
3 1.04 1.24 1.41 1.97 1.63 1.80
5 0.98 1.15 1.29 1.73 1.65 1.80
6 0.97 1.00 1.15 1.54 1.66 1.79

@zcbenz
zcbenz force-pushed the metal-affine-qmv-mma-bits branch from 326ff27 to 5e56ca9 Compare November 21, 2026 07:30
@zcbenz
zcbenz merged commit 6d38ff9 into ml-explore:main Nov 21, 2026
24 checks passed
rcfa pushed a commit to cubiculum-ai/mlx that referenced this pull request Nov 26, 2026
osaurus-ai/mlx also keeps the fork's exact F32 q6 rows (exact_q6_f32_rows) on the single-row
kernels, whose reduction order they depend on.
(cherry picked from commit 6d38ff9)
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