ggml: add Q2_0 quantization support (CPU)#24448
Conversation
|
Ran the CPU correctness checks for this
Both built clean from this branch (CPU backend, No issues found on the CPU side. |
|
Just so you are prepared, our current workload means this will take some time to get reviewed, and #22836 is first in the quant queue. :) |
|
@CISC, sounds good, thanks for the heads up. |
Hard to say unfortunately, new quants in particular are hard to allocate reviewer/time for. No point in updating enums until conflicts are merged. |
max-krasnyansky
left a comment
There was a problem hiding this comment.
This looks very clean to me.
Very similar to Q4_0 in terms of the overall integration (kernels, blocks, etc).
I'm interested in adding this to ggml-hexagon since it maps pretty well.
Unfortunately, the compute would have to be done in FP16 (HMX) and INT8 (HVX) but the memory footprint reduction will definitely help speed things up.
@khosravipasha Please rebase with the latest master and I'll approve the workflow to kick the CI
dc7c932 to
4b7044d
Compare
|
@max-krasnyansky For now if you want to try with one of the uploaded models use the Nice, |
Block size 32 would be the most ideal for |
|
Seems there is some conflicts now, will resolve them. @max-krasnyansky Main issue with group size 32 will have large overhead will become 2.5 bpw. |
4b7044d to
ed93eda
Compare
|
Fixed two merge conflicts |
|
We need this PR ! |
Sounds good. I can work with 64 and 128 too. |
Overview
This PR adds Q2_0 support for CPU. Main motivation is to support Ternary Bonsai models (1.7B, 4B, 8B) and upcoming models. This PR is CPU only (ARM NEON + generic scalar fallback).
This completes the Q1_0, Q2_0, Q4_0, Q8_0 family.
We have the x86, Metal, CUDA, and Vulkan backends ready to submit later.
Notes
Format: Each group of 64 weights shares one fp16 scale
d; weights are packed at 2 bits each withmapping of
{0,1,2,3} => {-1,0,+1,+2} * dOur models natively support group size 128; however, it was requested to do group size 64 for the official Q2_0 format (see discussion #22019), so this PR uses 64.
We plan to also maintain a sibling group-128 variant (
PQ2_0) in our fork since the0.125 extra bpw becomes significant on larger models. If you have a cleaner way to do this, please let us know. For future release we will pack the models into both Q2_0 and PQ2_0 formats.
Why not use TQ1_0 / TQ2_0? They support group size 256, our models are group size 128, and also cpu-only and harder to accelerate on Metal/CUDA, etc. More info in: discussion #22019
Speed/Correctness Summary
-t 8,-ngl 0).More details and raw outputs in appendix.
Additional Info
Model Repos:
Links + Evals
More info on the models and working demos can be found below:
Each repo has three gguf variants:
Q2_0_g64.gguf: the new group-64 format this PR adds. The_g64suffix is forconvenience; it will be renamed to plain
Q2_0once these PRs merge. Use this file with this PR.Q2_0.gguf: the old Q2_0 from our fork (group 128); predates the group-64 changeand does not load with this PR. Will be deleted/renamed once this PR merges.
PQ2_0.gguf: the sibling format with group size 128 we keep maintaining in our fork (fork-only,not part of this PR).
Testing
Tested on Mac M4 Pro, 48 GB. Two CPU routes: ARM NEON and Generic Scalar Fallback
(generic built by steering ggml to the portable path:
GGML_SYSTEM_ARCH=UNKNOWN, NEONarch/arm/quants.cnot compiled).Pack to Q2_0 (from F16 GGUF)
Speed Benchmarks Details
ARM NEON
Generic Scalar Fallback (1.7B, small
-p 16 -n 8)KL Kernel Accuracy Test Details (Q2_0 g64 vs F16, packed vs unpacked)
ARM NEON: Q2_0 g64 vs F16, by size
1.7B: full statistics (ARM NEON vs F16)
1.7B: Generic Scalar Fallback vs F16 (matches NEON)
Requirements