Repository navigation
[Metal] Add staged fp_qmm_t_nax with splitk and affine_qmv_nax kernels - #4781
Conversation
b78d303 to
ccd10cc
Compare
|
Drafted by my Claude Opus 5.5 (xhigh effort) agent, reviewed by me. M5 Ultra data point (6-bit affine), in case it helps We tried this branch (
At M=8–16 a call now costs 1.03–1.09× the M=1 call. Outputs matched an fp32 dequantized reference within bf16 rounding. End to end, Qwen3.8-27B (MLX 6-bit) with DFlash 2 speculative decoding through mlx-dspark 0.20.3, greedy, 256 new tokens: a round with a 16-row verify went from about 82 ms to 39 ms. Decode went from 121 to 192 tok/s on a code prompt, 107 to 176 on math, 94 to 150 on GSM8K and 83 to 100 on chat (plain decode is 38 tok/s). Output stayed identical to plain greedy decoding except at floating-point near-ties. One gap remains on the Ultra: M=2–5 still uses Thanks for the PR. |
zcbenz
left a comment
There was a problem hiding this comment.
Thanks a lot for finishing the missing parts!
ccd10cc to
b196c32
Compare
Co-authored-by: Cheng <[email protected]> osaurus-ai/mlx does not have the affine qmv_nax kernels (ml-explore#4781), so affine stays off this path on NAX GPUs. Affine qmv_mma also needs scales and biases of the input type: the fork's mixed bf16/f16 metadata path stays on qmv. The instantiations follow this fork's kernel names. (cherry picked from commit ba8c005)
osaurus-ai/mlx takes the non-NAX part only. The 4-bit affine_qmv_nax rows need ml-explore#4781. (cherry picked from commit 8f578df)
Few-row and mid-row
quantized_matmulon GPUs with NAX is slower than it has to be. The FP formats will not take the NAX split-K route. Affine has noqmv_naxfor 6–16 rows.Over 36 projection shapes from 8 models and 5 formats, measured against upstream on three GPUs:
Fix #4720
Changes
fp_qmm_t_nax_splitkkernel.qmm_t_nax. Adapted from [Metal] Add staged affine_qmm_t_nax kernels with split-k #4682qmv_naxfor narrower FP shapes. The NAX limit for N and K goes from 2048 to 1024. nvfp4 keeps 2048 becauseqmv_wideis faster there.qmm_nax_k_partitionscaps the grid atmin(256, 6 × cores × max(K, 2048) / 2048)threadgroups, so long K can still split on small GPUs.affine_qmv_naxfor 6–16 rows. Adapted fromfp_qmv_nax.Dispatch changes
qmv_wideor non-NAXqmm_t_splitkqmv_wideor split-Kqmv_naxqmv_wide/ split-K /qmvaffine_qmv_naxPerformance
Measured on M5 Pro (16 core), M5 Max (40 core) and M6 (12 core), macOS 27.0.1
Shapes: q/o, k/v, gate/up, down for Qwen3-0.6B, Llama-3.2-1B, Llama-3.2-3B, Qwen3-4B, Qwen3-8B / Llama-3-8B, Qwen3-14B, Qwen3-32B and Llama-3-70B (35 shapes), plus a 4096 × 151936 LM head. That is 5,400 pairs in total.
Speedup by M
M5 Pro
M5 Max
M6
Speedup per model (M = 6–32, five quant formats)
Count of cases (M = 6–256, 1,620 per GPU)
Per-shape times, Qwen3-8B / Llama-3-8B and LM head (µs, upstream → branch)
M5 Pro
M5 Max
M6