- Model size — 4-bit quantization cuts weights from 4 bytes to 0.5 bytes per element.
- Memory bandwidth — the GPU or CPU dequantizes weights on the fly during matrix multiplication.
- Load time — smaller files load faster from disk.
Quantization types
ggml’s quantization types are defined inggml_type. The naming convention is:
Qprefix — classic block quantizationKsuffix — “k-quant” (improved quantization with multiple scales per block)IQprefix — “i-quant” (importance-aware quantization, requires an importance matrix)
Legacy Q-types (Q4_0, Q4_1, Q5_0, Q5_1, Q8_0)
Legacy Q-types (Q4_0, Q4_1, Q5_0, Q5_1, Q8_0)
The original ggml quantization formats. Each block stores a shared scale (and optionally a minimum) for a fixed number of elements.
K-quants (Q2_K … Q8_K)
K-quants (Q2_K … Q8_K)
K-quants use a hierarchy of super-blocks and sub-blocks with multiple scales, giving significantly better accuracy at the same bit-width.
The
_S (small) and _M (medium) suffixes used in llama.cpp refer to mixed-precision strategies built on top of these types, not separate ggml_type values.I-quants (IQ1_S, IQ2_XXS, IQ3_S, IQ4_NL, …)
I-quants (IQ1_S, IQ2_XXS, IQ3_S, IQ4_NL, …)
I-quants use non-uniform (importance-weighted) quantization grids. They achieve better perplexity than equivalent k-quants at the same bit-width, but require an importance matrix during quantization.
Checking whether a type is quantized
Quantizing data with ggml_quantize_chunk
ggml_quantize_chunk is the primary entry point for converting F32 data to a quantized format:
dst.
Example: quantize a weight matrix
Initialization and cleanup
ggml_quantize_chunk calls ggml_quantize_init internally. If you need explicit control over when quantization tables are loaded:
Importance matrices (imatrix)
An importance matrix calibrates which weight values have the most impact on model outputs. Providing one during quantization allows the quantizer to allocate more precision to high-importance values. The imatrix has shape[n_per_row] — one importance score per column of the weight matrix:
Mixed precision
In a typical LLM deployment:ggml_mul_mat handles dequantization internally: the left-hand operand can be any quantized type while the right-hand operand is typically F16 or F32.
