Repository navigation
CUDA: BF16 x F32 one-column mul_mat for sm_100 - #503
Open
danielhanchen wants to merge 3 commits into
Open
danielhanchen wants to merge 3 commits into
danielhanchen wants to merge 3 commits into
Conversation
Decode (one src1 column) of BF16 weights went through MMVF, which runs one block per row sized for the fewest 4-byte loads per thread: K = 256 rows (128 threads x one load, 8192 blocks of 512 bytes) and its weight loads waited for the PDL sync. The new kernel splits a row over 32/64/128 threads with 16-byte loads, packs several rows per block, issues the weight loads before the PDL wait, and sums the exact F64 products in F64, so the result is the dot product rounded once to F32 (independent of the split). Taken for one src1 column, contiguous 2D operands, K % 8 == 0, K <= 8192, cc 10.0 (sm_103 and consumer GPUs have a much lower FP64 rate and keep MMVF). Kill switch: GGML_CUDA_DISABLE_MMV_BF16_F32.
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. |
Use the mmq_few_is_constant test (view root in a weights buffer, not GGML_TENSOR_FLAG_PARAM), since the optimizer step writes trainable weights.
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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 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
Faster CUDA decode for BF16 weight tensors on B200 / GB200 (sm_100). On Qwen4-35B-A3B GGUFs that keep the small hyper-connection,
ssm_beta_alphaand attention tensors in BF16, tg128 goes from 0.92-0.96x to 1.035-1.038x of the equivalent all-Q8_0 file. Outputs stay the same: the batched path is bit-identical, and decode matches an exact reference.unslothai/llama.cpp prebuilt = upstream ggml-org aged
b####+scripts/unsloth/pr-set.jsonpins, merged in order. This PR is a pin: upstreamb13019(7f6ead1) plus this one change, based onbase/upstream-7f6ead10d. It is not inpr-set.jsonyet.Cause
A BF16 matmul with one src1 column goes through MMVF, which is slow for these shapes:
hc_*_upis K=256 x N=8192. MMVF launches 8192 blocks of 128 threads, and each thread makes one 4-byte load. That costs about 10 us per call, 80 calls per token. The same tensor in Q8_0 runs in about 8 us through MMVQ.hc_*_down_injectis K=8192 x N=260. It gets only 260 blocks, and each thread makes 16 sequential 4-byte loads.On a Q6_K_XL-style file this adds about +257 us of kernel time per token.
Change
New kernel
mul_mat_vec_bf16_f32(ggml/src/ggml-cuda/mmv-bf16-f32.cu), dispatched fromggml_cuda_mul_matahead of MMVF:mmq_few_is_constant).GGML_CUDA_DISABLE_MMV_BF16_F32=1.test-backend-ops: new one-column BF16 MUL_MAT cases covering short, long, odd-N and K=8192 shapes.Results (B200, exclusive,
llama-bench -t 12, 3 alternating rounds x 3 repeats, medians of 9)Ratio vs the equivalent all-Q8_0 file (same kernel, measured on an earlier upstream base; the gate-scope check below is on this branch):
test-backend-ops perf, exclusive):hc_up8192 x 256 is 9.55 -> 3.22 us, 2048 x 512 is 3.66 -> 1.85 us.hc_up,hc_down_inject,ssm_beta_alphaand the attention projections.Correctness
llama-perplexity, batch 2048, 20 chunks, patched build vs its kill switch): PPL string-equal, mean KLD 0, same top token 100% on three files. Prompt processing never takes the one-column path.test-backend-opson B200 (this branch): MUL_MAT 2927/2927 (three runs), MUL_MAT_ID 1104/1104, the new BF16 one-column cases all pass; with the kill switch MUL_MAT is also 2927/2927.Recheck on head 91b4f59 (B200)
test-backend-ops -o MUL_MAT: 2927/2927 with and without the kill switch (base 2877/2877);MUL_MAT_ID1104/1104. Negative control: skipping the write of the last row fails 28 of the 185 one-column BF16 cases.-ub 512) head vs base mean KLD 0, same top 100%; decode (-ub 1) kill switch vs base KLD 0; head vs base PPL 21.7323 vs 21.7324, same top 100%. nsys showsmul_mat_vec_bf16_f32in the decode trace.llama-bench -t 12on that file: tg128 732.4 / 735.0 / 732.7 / 723.8 (base) vs 828.4 / 838.2 / 840.1 / 828.7 (head), about 1.14x; pp512 within noise (busy host).Pin set
llama_pinset.py simwith this PR appended topr-set.json: on the aged baseb13019all 51 pins merge additively,pin_contractandmerge_checkspass. Onb13024this PR still merges additively; common : add --moe-cache-mib auto to size the MoE expert cache from the fit #251 and Host-weight prefetch in the scheduler, faster MoE cache prompt and decode, cache seeding under llama-server #268 are refused there with or without it.Not tested
b13019it currently fails with or without this PR (GGML_OP_COUNT != 102; two other pins each add one op and both bump the count from 101 to 102), which is also why the 12-05 nightly failed.pr-set.json,feature-checks.json) is a follow-up once this is reviewed.