Repository navigation
Speed up QMM & QMV - #4781
Open
XXXXRT666 wants to merge 5 commits into
Open
Speed up QMM & QMV#4781XXXXRT666 wants to merge 5 commits into
XXXXRT666 wants to merge 5 commits into
Conversation
This branch has not been deployed
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.
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