Repository navigation
ggml-cpu : AVX-512 Q4_K, Q5_K, Q6_K and IQ4_XS dot products - #513
Draft
danielhanchen wants to merge 1 commit into
Draft
danielhanchen wants to merge 1 commit into
danielhanchen wants to merge 1 commit into
Conversation
On CPUs with AVX512F and AVX512BW, the Q4_K, Q5_K, Q6_K and IQ4_XS x Q8_K dot products process both 256-bit halves of the AVX2 kernels with one 512-bit maddubs / madd (vpdpwssd with AVX512_VNNI). The int32 results and the float accumulation order are those of the AVX2 kernels, so the output is bit-identical; only the instruction count drops.
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. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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
danielhanchen
marked this pull request as draft
December 6, 2026 09:38
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.
Not proposed for the prebuilt in this form (Zen 4 result below: correct and reached, but q4_K / q5_K single-column dots are 7% / 11.5% slower than the AVX2 code and nothing is faster at model level). Kept open as a draft for a rework.
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 one commit on top of upstream b12966 (9a811bab3c4) and needs no other pin. Once upstream has an equivalent change, the pin is dropped.The problem
On x86 CPUs with AVX-512, the Q4_K, Q5_K, Q6_K and IQ4_XS x Q8_K dot products still run their AVX2 kernels: two 256-bit
maddubs/maddchains per step. These four types are most of the weights of the K-quant and UD GGUFs. On x86 the CPU repack buffer already takes Q4_K weights whose row count is a multiple of 8 (theq4_K_8x8GEMV), so in a default run the Q5_K, Q6_K and IQ4_XS tensors are the ones that reach these dots; Q4_K reaches its dot with--no-repackor for tensors the repack buffer does not take.The fix
ggml/src/ggml-cpu/arch/x86/quants.c: with__AVX512F__and__AVX512BW__,ggml_vec_dot_{q4_K,q5_K,q6_K,iq4_xs}_q8_Ktake an AVX-512 form. One 512-bitmaddubs/madd(vpdpwssdwhere AVX512_VNNI is available, which gives the same int32 asmadd+add) covers both 256-bit halves of the AVX2 kernel, the two halves are folded back to the AVX2 kernel's 8 int32 lanes, and the float part is the AVX2 kernel's own. The output is bit-identical to the AVX2 kernels.Evidence
All on one Intel Xeon Platinum 8559C host (192 threads, avx512f / bw / vl / vnni), CPU-only builds of b12966 (base) and b12966 + this pin (head), same flags.
GGML_NATIVE=ON;GGML_NATIVE=OFF+GGML_AVX512=ON(adds-mavx512bw) with and withoutGGML_AVX512_VNNIquants.clibggml-cpu)ggml_vec_dot_q4_K_q8_K/q5_Kjump to the AVX-512 forms (32 / 54 zmm instructions),q6_K39 andiq4_xs51 zmm instructions inlined; base: 0ggml_get_type_traits_cpu(t)->vec_dotfor the four types, n = 256 / 512 / 2048 / 4096 / 10752, 2000 inputs each (quantized random, heavy-tailed, saturating +-1 x 127/-128, all-positive, and raw random block bytes with sane fp16 scales), 40000 results as raw float bitstest-quantize-fnstest-backend-ops -b CPU -o MUL_MAT/-o MUL_MAT_ID-ngl 0 -t 16, native builds49b92a5d3c67, gemma-3-1b-it Q4_K_M3dd1a9f996f1, granite-4.0-h-tiny Q4_K_M (hybrid MoE)739d9863a717, Qwen3.5-0.8B UD-Q4_K_XL (holds Q4_K, Q5_K, Q6_K and IQ4_XS tensors)31a09d8064062d19ea45f7bd, Qwen3.5-0.8B562f4dd48e2fllama_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)Zen 4 result (Ryzen 5 7600, AVX-512 F/BW/VL/VNNI/VBMI, pin-set tree vs + this pin)
test-quantize-fns--no-repacktest-backend-ops perf -b CPU -o MUL_MAT, A_us / B_us (above 1 = faster), single run per arm--repack 0, 6 cores, 5 roundsThe new dots are reached and correct, but on Zen 4 the q4_K and q5_K single-column dots are slower than the existing AVX2 code and nothing is faster at model level. Not proposed for the prebuilt in this form.
Not proven
llama-benchtg64 (Qwen3-0.6B Q4_K_M, Qwen3.5-0.8B UD-Q4_K_XL, 16 threads, 2 rounds) was inside the shared host's noise (base A/A spread 6 to 17%), so no speed number is claimed here. An A/B on an idle AVX-512 machine (Zen 4 / Sapphire Rapids) is still needed.