Skip to main content
For LLM inference the dominant cost is not floating-point compute — it is memory bandwidth. A 7B-parameter model stored as F32 occupies ~28 GB. Moving that data from DRAM to compute cores is the primary bottleneck on every platform. Quantization maps 32-bit floats to smaller integer representations, reducing:
  • 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.
Activations (the intermediate tensors produced during inference) are typically kept at F16 or F32 to preserve accuracy.

Quantization types

ggml’s quantization types are defined in ggml_type. The naming convention is:
  • Q prefix — classic block quantization
  • K suffix — “k-quant” (improved quantization with multiple scales per block)
  • IQ prefix — “i-quant” (importance-aware quantization, requires an importance matrix)
The original ggml quantization formats. Each block stores a shared scale (and optionally a minimum) for a fixed number of elements.
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 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:
The function returns the number of bytes written to dst.
Some quantization types (all IQ types) require a non-NULL imatrix. Call ggml_quantize_requires_imatrix(type) to check before passing NULL.

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:
Both functions are thread-safe.

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:
In practice, imatrices are computed by running a calibration dataset through the unquantized model and collecting activation statistics.

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.

Type traits

You can inspect quantization properties at runtime: