Skip to content

CUDA: 4 rows per block for the MoE vector kernel on NVIDIA Turing to Ada and datacenter Blackwell - #417

Open
danielhanchen wants to merge 2 commits into
base/upstream-418fe97b5from
inkperf4-up-moe-rows-nv
Open

danielhanchen wants to merge 2 commits into
base/upstream-418fe97b5from
inkperf4-up-moe-rows-nv

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Pin for the prebuilt: upstream b12602 (418fe97) plus these two commits. Base branch base/upstream-418fe97b5.

What it changes

mul_mat_vec_q_moe (MUL_MAT_ID at 2-8 tokens: batched decode, speculative verify) takes 4 rows per block instead of 2 when the row count is a multiple of 4. That gives each warp more independent loads. Each warp still reduces each row in the same order, so the results are bit-identical.

  • The first commit enables it on datacenter Blackwell (cc 10.x): -8% kernel time for NVFP4 experts at 4 and 8 tokens on B200 (37.6 -> 34.7 us, 71.7 -> 66.9 us).
  • The second enables it on NVIDIA Turing to Ada (cc 7.5 to 8.9). Hopper (cc 9.x) is not measured and consumer Blackwell (cc 12.x) measured slightly slower, so both keep 2 rows, as do AMD and the other backends.

GGML_CUDA_DISABLE_MOE_VEC_ROWS4=1 keeps 2 rows per block everywhere. test-backend-ops: NVFP4 MUL_MAT_ID with 16 experts, 8 used, at 2/4/8 tokens, row counts divisible by 4 and not.

Evidence

B200, one exclusive card, load-gated runs, with the other decode pins: 8-sequence decode UD-Q8_K_XL 357.9 -> 379.7 tok/s (+6%); 4 sequences and UD-Q4_K_XL tie; batch 1 unchanged.

Other NVIDIA GPUs (Colab, one card each, built from b12628 plus #399 plus the decode pins). llama-batched-bench -c 4096 -npp 128 -ntg 64 -kvu, aggregate decode tok/s at 4 sequences, 3 rounds ABBA, median, 4 rows against 2 rows (the kill switch) in the same build; #399's spread over its 3 runs in brackets:

GPU (cc) file 2 rows 4 rows change
T4 (7.5) UD-IQ1_S 59.6 64.0 +7.4% [1.1%]
L4 (8.9) UD-IQ1_S 130.1 132.5 +1.8% [0.6%]
L4 (8.9) UD-Q4_K_XL 101.0 101.8 +0.8% [0.3%]
A100 (8.0) UD-IQ1_S 188.8 192.5 +2.0% [0.1%]
A100 (8.0) UD-Q4_K_XL 175.8 177.0 +0.7% [0.1%]
A100 (8.0) UD-Q8_K_XL 164.2 164.9 +0.4% [0.2%]
RTX PRO 6000 (12.0) UD-IQ1_S 387.9 385.8 -0.5% [1.1%]
RTX PRO 6000 (12.0) UD-Q4_K_XL 359.4 358.4 -0.3% [0.1%]
RTX PRO 6000 (12.0) UD-Q8_K_XL 315.3 314.6 -0.2% [0.0%]

mul_mat_vec_q_moe (MUL_MAT_ID at 2-8 tokens) takes 4 rows per block on cc 10.x
when the row count is a multiple of 4 (2 elsewhere, as before). That gives each
warp more independent loads: -8% kernel time for NVFP4 experts at 4 and 8
tokens on B200 (37.6 -> 34.7 us, 71.7 -> 66.9 us). Each warp reduces each row
in the same order, so the results are bit-identical. test-backend-ops: NVFP4
MUL_MAT_ID with 16 experts, 8 used, at 2/4/8 tokens, row counts divisible by 4
and not.

Kill switch: GGML_CUDA_DISABLE_MOE_VEC_ROWS4=1.
Each row is still reduced exactly as with 2 rows per block, so the results are bit-identical. 4-sequence decode with
4 rows vs 2 (Inkling-2-Mini): T4 +7.4% (UD-IQ1_S), A100 +2.0 / +0.7 / +0.4% and L4 +1.8 / +0.8% (UD-IQ1_S /
UD-Q4_K_XL / UD-Q8_K_XL). Batch-1 decode and prefill unchanged.

Hopper (cc 9.x) is not measured and keeps 2 rows. Consumer Blackwell (cc 12.x, RTX PRO 6000) measured 0.2-0.5% slower at
4 sequences and keeps 2 rows. GGML_CUDA_DISABLE_MOE_VEC_ROWS4=1 keeps 2 rows per block everywhere.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-11-23T02:25:54.802647Z bd47345 PR opened
ℹ️ 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.

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