Dev.to AI 🤖 Ai 👁 0 📖 2 min read

Set a GGUF size budget with llama.cpp quantization

If a local model almost fits on your GPU, choosing a GGUF quant by its label can be frustrating. The same preset produces different average bits per weight across architectures, and file size still leaves out runtime mem

If a local model almost fits on your GPU, choosing a GGUF quant by its label can be frustrating. The same preset produces different average bits per weight across architectures, and file size still leaves out runtime memory.

A new llama.cpp option lets you set a file-size budget and choose a mix of tensor quantization types to fit it. Here's what the budget controls, what it costs to compute, and what to measure before deployment.

llama.cpp release b12669 adds another option to llama-quantize: specify a target file size or average bits per weight and let it choose a mix of tensor quantization types. It's useful when you have a specific storage budget or want a controlled size comparison between models.

How the budget is allocated

The implementation pull request describes sampling rows from each eligible tensor, estimating quantization error across candidate types, and choosing a mix under the overall budget. A tensor that loses more from compression can get more bits; another can get fewer. The optimizer uses an importance matrix with activation statistics, so generating a suitable imatrix.gguf is part of the preparation.

The release's quantization guide gives this example for a size target:

./llama-quantize --target-size 1.5g --state-file my-state-file.dat --imatrix imatrix.gguf input-model-f32.gguf output-model.gguf

For comparisons at an average bit budget, use --target-bpw instead. The state file saves the expensive target computations, letting a later run reuse them. The guide also documents --target-exclude for excluding quantization types; that option prevents writing a state checkpoint. Explicit tensor-type overrides stay fixed and count against the budget, and an impossible remaining budget causes quantization to fail.

What the numbers do and don't say

The pull request reports 238 tests across 34 models: 195 wins, 26 ties, 16 losses and one unavailable result against standard quantization, using Kullback-Leibler divergence as the comparison metric. The authors count wins and ties as 93% of tests. One model, mamba-2.8b-hf, lost at every listed setting. These are the contributors' results for their test setup, not a promise that every application will improve.

The optimizer estimates tensor error; it doesn't directly optimize your application score. The PR also says the initial optimization can take five to ten times longer than standard quantization. Keeping the state file is worthwhile if you intend to try multiple targets, but the extra preparation may not pay off for a one-off model.

Leave room beyond the GGUF

A file-size target is a disk budget, not a guarantee that inference fits in the same amount of VRAM. Runtime allocations, including the KV cache and compute buffers, need space too; context length and offloading choices affect the result. Pick a target below available memory, run the actual workload, and measure peak use before increasing it.

For a fair comparison, keep the source model, evaluation prompts, context settings and runtime version fixed. Compare the resulting file size and task quality with an existing quant, then check throughput and memory on the hardware that will serve it. A lower divergence score is useful evidence, but it won't tell you whether your coding assistant still passes its tests.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.