llama.cpp v1.1.0 (26 November 2026) picks per-tensor quant types to hit a file size. How it works, the imatrix it needs, and bits-per-weight math for 8 GiB.
What shipped on 26 November 2026
llama.cpp v1.1.0 was published on 26 November 2026. Among many model and server changes, it adds two options to llama-quantize: --target-bpw, a bits-per-weight target, and --target-size, a file-size target in bytes, KiB, MiB, GiB or TiB. Instead of applying one named recipe such as Q4_K_M, the quantizer chooses a quantization type for each tensor so the whole file lands on the requested budget at the lowest estimated error. The work is PR 15550, merged on 23 November.
This matters for anyone fitting a model onto a fixed GPU. Named recipes come in coarse steps, so a model often ends up either too large to fit with the context you need or noticeably smaller than the memory available. This guide explains how the option works, from the PR and the source at the v1.1.0 tag, then does the arithmetic for a worked example. All sizing below is calculation, not measurement, except where a real file is read. No quantization was run for this guide.
How it chooses types
The PR describes four stages, and the code in src/llama-quant.cpp at v1.1.0 matches them:
- Error estimation. For each tensor it quantizes a sample of rows into each candidate type, dequantizes them back and measures the error, weighting the rows by an importance matrix. The candidate list in the source has 21 entries, from IQ1_S through Q8_0 plus F16 and BF16.
- Pareto pruning. For each tensor it drops types that cost more bytes without reducing error enough.
- Allocation. Lagrangian relaxation spreads the bit budget across tensors, giving more bits where they reduce error most.
- State file. With
--state-file, the expensive measurements are saved, so an interrupted run can resume and later runs with other targets are fast.
Three constraints come straight from the source. An imatrix is mandatory: without one, the quantizer stops with "--target-bpw/--target-size require an imatrix but none was provided". The two targets cannot be used together. And --target-exclude removes types from consideration, for example a type your runtime's GPU backend handles slowly. The PR is candid about the limits: the process is 5 to 10 times slower than standard quantization, and the error it minimises is a per-tensor proxy, not perplexity or output divergence, so there is no guarantee it finds the best mix. Its own evaluation reports matching or better KL divergence than standard recipes in 93 percent of 238 tests across 34 models; that is the PR author's measurement, not one reproduced here.
Bits per weight, from the block layouts
Every ggml quantization type stores weights in blocks with a fixed size. Bits per weight is the block's byte size times 8, divided by the number of weights in it. From ggml-common.h at v1.1.0:
| Type | Weights per block | Bytes per block | Bits per weight |
|---|---|---|---|
| Q2_K | 256 | 84 | 2.625 |
| Q3_K | 256 | 110 | 3.4375 |
| IQ4_XS | 256 | 136 | 4.25 |
| Q4_K | 256 | 144 | 4.5 |
| Q5_K | 256 | 176 | 5.5 |
| Q6_K | 256 | 210 | 6.5625 |
| Q8_0 | 32 | 34 | 8.5 |
| F16 | 1 | 2 | 16 |
Named recipes mix these types, so their average is not the headline number. Reading the tensor table of a real file shows it. The qwen2.5 1.5b model in a local Ollama store is labelled MOSTLY_Q4_K_M in its metadata. Its tensors are 1,112,014,848 weights in Q4_K, 431,554,560 in Q6_K and 144,896 in F32, for an average of 5.08 bits per weight. The smaller qwen2.5 0.5b-instruct file, also Q4_K_M, averages 6.35. Its tensor table explains why: the model's hidden size is 896, which is not a multiple of the 256-weight K-quant block, so the quantizer falls back to other types for tensors whose rows have 896 columns. Only 52 million weights ended up in Q4_K, 252 million in Q5_0, and 138 million, mostly the embedding table, in Q8_0. The fallback rule is tensor_type_fallback in src/llama-quant.cpp. This is exactly the inconsistency the PR mentions: the same recipe gives different effective sizes on different models.
Worked example: a 7B model on an 8 GiB GPU
The shape is Qwen2.5-7B-Instruct, from its published config.json: hidden size 3,584, 28 layers, 28 attention heads, 4 key-value heads, intermediate size 18,944, vocabulary 152,064 and untied embeddings. Counting the weight matrices gives 7,615,283,200 weights: 545 million each for the embedding and output tables, 822 million in attention and 5.70 billion in the feed-forward layers.
The GPU has 8 GiB. Assume a 32,768-token context with an F16 KV cache and 1 GiB for the runtime, compute buffers and fragmentation. The overhead figure is an assumption; measure your own runtime's.
kv_bytes = 2 * layers * kv_heads * head_dim * ctx * bytes_per_element
# = 2 * 28 * 4 * 128 * 32768 * 2 = 1,879,048,192 bytes = 1.75 GiB
weight_budget = 8 GiB - 1.75 GiB - 1.0 GiB = 5.25 GiB
target_bpw = weight_budget * 8 / 7,615,283,200 = 5.92Uniform types land on either side of the budget. All weights at Q5_K would take 4.88 GiB, leaving 0.37 GiB unused. All at Q6_K would take 5.82 GiB, which does not fit. A two-type split hits the target exactly with about 40 percent of the weights at Q6_K and the rest at Q5_K. That split is only arithmetic. --target-size does the useful version: it decides which tensors deserve the extra bits, from measured error, rather than splitting by count. In practice you would pass a target slightly under the budget, such as --target-size 5.2g, because the file also contains the tokenizer and metadata, and the runtime may add buffers that grow with context.
The context length is the lever people forget. Halving the context to 16,384 tokens frees 0.875 GiB of KV cache, which raises the weight budget to about 6.1 GiB and the target to about 6.9 bits per weight, enough for a mostly Q6_K model. Quantizing the KV cache to 8 bits frees a similar amount. Decide the context you need first, then size the weights.
A run, step by step
- Start from a high-precision GGUF (F16 or BF16) converted from the original weights.
- Generate an importance matrix with
llama-imatrixon text that resembles your workload. The PR says the target options need an imatrix with activation statistics, generated by commit 0504396 or later, and refuse to run without one. - Run
llama-quantize --imatrix model.imatrix --target-size 5.2g --state-file model.state model-f16.gguf model-target.gguf. Keep the state file if you will try other sizes. - Read the output file's tensor table to confirm the size and see the chosen mix. The companion
budget.py mix FILE.ggufprints the type shares and the average bits per weight. - Evaluate before deploying, with the tools llama.cpp ships, such as
llama-perplexitywith its KL-divergence mode against the F16 model, and with task evaluations that match your use.
Failure modes
- Budgeting the file to the full VRAM. Weights are not the only allocation. KV cache, compute buffers and multiple parallel sequences all need memory, and they grow with context and batch size.
- An unrepresentative imatrix. The error estimates weight rows by the imatrix. Calibration text unlike your workload steers the bits to the wrong tensors.
- Comparing models by recipe name. As the two Ollama files show, Q4_K_M can mean 5.08 or 6.35 bits per weight. Compare by size or by measured bits per weight.
- Assuming speed follows size. Some types are slower than others on a given backend. Exclude slow types with
--target-excludeand benchmark tokens per second after quantizing.
Verification
The companion example llama_target_size_budget reproduces every number in the worked example and asserts the bits-per-weight table, the parameter count of the shape, the linear growth of the KV cache with context, the two-type split and the self-consistency of the recorded real-file mix. Its mix command reads any GGUF header, so you can check what a --target-size run actually produced. Treat the arithmetic as a starting point, then confirm the fit by loading the model with your real context length and watching memory use.