Repository navigation
CUDA: 2 rows per block for single-column MMVQ on Turing (stacked on #491) - #512
Open
danielhanchen wants to merge 3 commits into
Open
danielhanchen wants to merge 3 commits into
danielhanchen wants to merge 3 commits into
Conversation
On sm_75 device code (not Volta) a single-column mul_mat_vec_q launch takes 2 rows per block, which shares the q8_1 activation loads between the rows and keeps more weight loads in flight. A row's sum does not depend on the rows per block, so the output is unchanged. Not for Q3_K, MUL_MAT_ID or an odd number of rows. Uses the rows-per-block override of the warp-per-row launch (stacked on #491).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Dec 6, 2026
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Dec 6, 2026
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.
Summary
The unslothai/llama.cpp prebuilt is an aged upstream
b####tag plus the pins listed inscripts/unsloth/pr-set.json, merged in order. This pin is stacked on #491 (pin-mmvq-wpr, heade6e34ffd3c2, itself on upstream b129669a811bab3c4): it reuses #491's rows-per-block override ofmul_mat_vec_q, since both change the kernel's template parameters. Inpr-set.jsonit goes after #491. Once upstream has an equivalent change, the pin is dropped.The problem
On Turing (sm_75 device code) a single-column
mul_mat_vec_qlaunch takes one row per block, while the GENERIC / Pascal / RDNA1 tables already take two rows for most types. With one row per block every block loads its own copy of the q8_1 activation, and fewer weight loads are in flight per block.The fix
mmvq.cu: the single-column launch helper launches with CUDA: give each warp its own rows in short-K single-column mat-vec launches #491'sc_rpb = 2(2 rows per block, gridnrows / 2) when the device code is sm_75 (ggml_cuda_highest_compiled_arch(cc) == GGML_CUDA_CC_TURING, NVIDIA only, not Volta), the row count is even, the type is not Q3_K, and the node is not MUL_MAT_ID or a shared-expert fusion. small-K and halved-iteration launches and CUDA: give each warp its own rows in short-K single-column mat-vec launches #491's warp-per-row launch keep their own shapes.Evidence
mmvq.cufor sm_75 + sm_100a, on #49138c5c945b), merged in that order-Werror all-warnings -Xcompiler -Werrorcompile ofmmvq.cufor sm_75 / sm_80 / sm_89 / sm_120a: clean. nvcc 12.8, same archs: builds, the only warnings are 2 in CUDA 12.8's owncuda_fp4.hpp1863f92f647vs + the move)test-backend-opsMUL_MAT 3123/3123, MUL_MAT_ID 1298/1298 on both; greedy md5 identical on Qwen3-0.6B Q4_0 / Q4_K_M / Q8_0, gemma-3-1b Q4_K_M, granite-4.0-h-tiny Q4_K_M, Llama-3.2-1B Q4_K_M, Qwen3.8-27B IQ2_XXS, Inkling-2-Mini IQ1_S; tg128 unchanged (475.9 / 475.8, 469.4 / 469.3, 457.4 / 457.5 t/s): the move is neutral6fbee1af383) vs pin-set tree + this pin (38c5c945b72), onlymmvq.cudifferstest-backend-opsMUL_MAT 3123/3123, MUL_MAT_ID 1298/1298 on both; greedy md5 identical on Qwen3-0.6B Q4_0 / Q4_K_M / Q8_0, gemma-3-1b Q4_K_M, granite-4.0-h-tiny Q4_K_M, Llama-3.2-1B Q4_K_M, Qwen3.8-27B IQ2_XXS, Inkling-2-Mini IQ1_Smul_mat_vec_q<..., 0, 0, 0>to<..., 0, 2, 0>(2 rows per block) for q4_0, q4_1 and the Q6_K output head; the short-K per-warp launches (<..., 2, 2, 0>) are the same in both. Kernel average q4_0 7060 -> 5248 ns, Q6_K head 294.6 -> 219.4 us, q4_1 7649 -> 6027 nsllama_pinset.py sim, private copy, b13023, 12-06): master pr-set + open candidates #485-#503 (without #495) + #505 + #508-#513 + #516 at their current heads, 74 pinsmerge_checksclean;pin_contract: all pins intact once #491 is listed at its current heade6e34ffd3c2(the copy listed it at131d93897cd, whose comment-trimmed line arrives through #505 / #512, a listing artifact). CUDAmmvq.cu/mmvf.cu/mmid-gemm.cu/fusion.cucompile on the merged tree (sm_75 + sm_100a)llama_pinset.py sim, private copy, b13023, 12-06): master pr-set + open candidates #485-#503 (without #495) + #505 + #508-#513 + #516 at their current heads, 74 pinsmerge_checksclean;pin_contract: all pins intact once #491 is listed at its current heade6e34ffd3c2(the copy listed it at131d93897cd, whose comment-trimmed line arrives through #505 / #512, a listing artifact). CUDAmmvq.cu/mmvf.cu/mmid-gemm.cu/fusion.cucompile on the merged tree (sm_75 + sm_100a)Not proven