Skip to content

CUDA: 2 rows per block for single-column MMVQ on Turing (stacked on #491) - #512

Open
danielhanchen wants to merge 3 commits into
pin-mmvq-wprfrom
pin-mmvq-turing-2rows-491
Open

danielhanchen wants to merge 3 commits into
pin-mmvq-wprfrom
pin-mmvq-turing-2rows-491

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Summary

The unslothai/llama.cpp prebuilt is an aged upstream b#### tag plus the pins listed in scripts/unsloth/pr-set.json, merged in order. This pin is stacked on #491 (pin-mmvq-wpr, head e6e34ffd3c2, itself on upstream b12966 9a811bab3c4): it reuses #491's rows-per-block override of mul_mat_vec_q, since both change the kernel's template parameters. In pr-set.json it 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_q launch 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

Evidence

Check Result
Speed (measured on our fork, same change) +1-2% decode on T4
nvcc 13.1 compile of mmvq.cu for sm_75 + sm_100a, on #491 clean (0 errors, 0 warnings)
git merge with #505 (pin-mmvq-rdna4, also on #491) clean (#505 merged first, then this pin, on b13023 + master pr-set + candidates)
#491 head + #505 + this pin (38c5c945b), merged in that order clean, no conflict markers; nvcc 13.1 -Werror all-warnings -Xcompiler -Werror compile of mmvq.cu for 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 own cuda_fp4.hpp
RTX 2080 Ti (sm_75-only build), the launch-helper move alone (1863f92f647 vs + the move) test-backend-ops MUL_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 neutral
RTX 2080 Ti (sm_75-only build), pin-set tree + #505 (6fbee1af383) vs pin-set tree + this pin (38c5c945b72), only mmvq.cu differs test-backend-ops MUL_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
Engagement, nsys on a Qwen3-0.6B Q4_0 tg run the single-column launches switch from mul_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 ns
tg128, 3 rounds x 3 reps, median Qwen3-0.6B Q4_0 472.4 -> 476.8 t/s (+0.9%), Qwen3-0.6B Q4_K_M 465.2 -> 469.9 (+1.0%), Llama-3.2-1B Q4_K_M 455.8 -> 457.8 (+0.4%); every pin sample is above every base sample
Pin set sim (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 pins every pin merges (git or additive); merge_checks clean; pin_contract: all pins intact once #491 is listed at its current head e6e34ffd3c2 (the copy listed it at 131d93897cd, whose comment-trimmed line arrives through #505 / #512, a listing artifact). CUDA mmvq.cu / mmvf.cu / mmid-gemm.cu / fusion.cu compile on the merged tree (sm_75 + sm_100a)
Pin set sim (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 pins every pin merges (git or additive); merge_checks clean; pin_contract: all pins intact once #491 is listed at its current head e6e34ffd3c2 (the copy listed it at 131d93897cd, whose comment-trimmed line arrives through #505 / #512, a listing artifact). CUDA mmvq.cu / mmvf.cu / mmid-gemm.cu / fusion.cu compile on the merged tree (sm_75 + sm_100a)

Not proven

  • Only Turing device code changes; other architectures compile the extra template instance but never launch it.

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).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T09:02:09.854988Z 38c5c94 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen danielhanchen self-assigned this Dec 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 38c5c945b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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 branch has not been deployed

No deployments
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.

1 participant