Skip to the content.

llama.cpp GGUF Guide: Quantization Explained (Q4_K_M, IQ4_XS, Q8_0), Quality vs Size, Converting and Running Models

A complete, practical guide to the GGUF model format and llama.cpp quantization. It explains what names like Q4_K_M, Q5_K_S, IQ3_XXS, Q8_0 and MXFP4 actually mean, how many bits per weight each uses, how much quality you lose, which file to download for your RAM or VRAM, and how to convert a Hugging Face model to GGUF, build an importance matrix, quantize it and test it. It also includes two small dependency-free Python tools: a GGUF inspector that reads any .gguf file’s metadata and real bits per weight, and a size and memory calculator. It is for people running local LLMs with llama.cpp, Ollama, LM Studio, Jan or KoboldCpp, and for anyone publishing their own quantized models.

Last reviewed: December 2026, against llama.cpp 1.x and the GGUF v3 specification. Independent guide, not affiliated with the llama.cpp or ggml projects.

Table of Contents

Which GGUF file should I download?

Short answer: Q4_K_M, unless you have a reason to deviate. It is the default in Ollama’s Hugging Face integration and in llama.cpp’s -hf downloads, and it keeps quality close to the original at under a third of the 16-bit size.

Situation Pick Why
Normal use, model fits comfortably Q4_K_M Best balance; the community default
You have spare memory Q5_K_M or Q6_K Measurably closer to the original for a 15 to 35% bigger file
You want near-lossless Q8_0 Difference from 16-bit is usually within noise
The model does not quite fit IQ4_XS, then Q3_K_M / IQ3_M Smaller with modest loss, especially with an imatrix
Squeezing a big model into small memory IQ2_M, IQ2_XXS, IQ1_M Quality drops noticeably; only worth it for very large models
Model was trained or released in MXFP4 (for example gpt-oss) the publisher’s MXFP4 file Matches how the model was trained
Fine-tuning, merging or re-quantizing later BF16 or F16 Keep a full-precision master copy
Tiny model (under about 3B parameters) Q5_K_M to Q8_0 Small models lose more from aggressive quantization

Two rules that cover most decisions:

  1. A bigger model at 4 bits usually beats a smaller model at 8 bits of the same family, as long as it fits with room for context.
  2. Leave memory for the context (KV cache). A file that fills your VRAM exactly will spill to the CPU once you add a long prompt.

Size rule of thumb: file_GB ≈ parameters_in_billions × bits_per_weight / 8. A 32B model at Q4_K_M (about 4.9 bits) is about 19.6 GB. Use tools/quant_calc.py for a full table.

What GGUF is

GGUF is a single-file binary format for model weights plus everything needed to run them: architecture, hyperparameters, tokenizer, chat template and quantization details. It was created for the ggml tensor library and llama.cpp, and is now used by Ollama, LM Studio, Jan, KoboldCpp, llamafile, GPT4All and many others.

What makes it practical:

GGUF replaced the older GGML/GGMF/GGJT formats in August 2023. Current files are GGUF version 3.

Inside a GGUF file

The layout, from the official specification:

┌──────────────────────────────────────────────┐
│ magic "GGUF" (4 bytes)                       │
│ version uint32 (= 3)                         │
│ tensor_count uint64                          │
│ metadata_kv_count uint64                     │
├──────────────────────────────────────────────┤
│ metadata: key (string), value_type, value    │  general.*, <arch>.*, tokenizer.*
│   ... repeated metadata_kv_count times       │
├──────────────────────────────────────────────┤
│ tensor infos: name, n_dims, dims[], type,    │
│   offset   ... repeated tensor_count times   │
├──────────────────────────────────────────────┤
│ padding to general.alignment (default 32)    │
├──────────────────────────────────────────────┤
│ tensor data (each tensor aligned)            │  the bulk of the file
└──────────────────────────────────────────────┘

Values are little-endian by default. Strings are a uint64 length followed by UTF-8 bytes. Metadata value types are uint8 to uint64, int8 to int64, float32, float64, bool, string and (nested) arrays.

Metadata keys you will see

Key Example Meaning
general.architecture llama, qwen3, gemma3 Which model code to run; prefixes the architecture keys below
general.name Qwen3 8B Human-readable name
general.file_type 15 Overall quant mix (15 = MOSTLY_Q4_K_M)
general.quantization_version 2 Version of the quantization scheme
general.alignment 32 Data alignment in bytes (default 32 if absent)
<arch>.context_length 40960 Trained context length
<arch>.block_count 36 Number of transformer layers
<arch>.embedding_length 4096 Hidden size
<arch>.attention.head_count / head_count_kv 32 / 8 Query heads / key-value heads (grouped-query attention)
<arch>.rope.freq_base 1000000.0 RoPE base frequency
<arch>.expert_count / expert_used_count 128 / 8 Mixture-of-Experts layout
tokenizer.ggml.model gpt2, llama Tokenizer family
tokenizer.ggml.tokens array of strings Vocabulary
tokenizer.chat_template Jinja template How chat messages become a prompt

File naming convention: the spec recommends <BaseName>-<SizeLabel>-<FineTune>-<Version>-<Encoding>-<Shard>.gguf, for example Mixtral-8x7B-v0.1-Q2_K.gguf or Grok-100B-v1.0-Q4_0-00003-of-00009.gguf. Multimodal projector files start with mmproj-. In practice many repos use simpler names like Model-Name-Q4_K_M.gguf.

Ways to inspect a file

python tools/gguf_inspect.py model.gguf          # this repo: summary, real bits per weight, KV cache size
pip install gguf && gguf-dump model.gguf          # the official gguf Python package

On Hugging Face, every GGUF file has a built-in viewer (click the file in “Files and versions”) showing metadata and each tensor’s type and shape.

How quantization works

Neural network weights are stored as 16-bit numbers in most released models. Quantization stores them with fewer bits by grouping weights into blocks and storing, per block, small integers plus one or more scale factors.

Example: Q8_0 (the simplest)

block of 32 weights:  w1 ... w32 (float)
scale  d = max(|w|) / 127                     stored as fp16 (2 bytes)
quants q_i = round(w_i / d)                   stored as int8 (32 bytes)
decode     w_i ≈ d × q_i
size       34 bytes / 32 weights = 8.5 bits per weight

Example: Q4_0: 32 weights as 4-bit integers (16 bytes) plus one fp16 scale (2 bytes) = 18 bytes, 4.5 bits per weight. Q4_1 adds a per-block minimum (offset): 20 bytes, 5.0 bits.

k-quants (Q2_K … Q6_K) use super-blocks of 256 weights split into sub-blocks of 16 or 32. Each sub-block has its own scale (and for some types a minimum), and those scales are themselves quantized to 4 to 8 bits with one fp16 super-scale. This spends bits on scales more efficiently than the older types:

k-quant Layout Bits per weight (pure)
Q2_K 16 sub-blocks of 16, 4-bit scales and mins 2.625
Q3_K 16 sub-blocks of 16, 6-bit scales 3.4375
Q4_K 8 sub-blocks of 32, 6-bit scales and mins 4.5
Q5_K 8 sub-blocks of 32, 6-bit scales and mins 5.5
Q6_K 16 sub-blocks of 16, 8-bit scales 6.5625

i-quants (IQ1_S … IQ4_XS) also use 256-weight super-blocks but map groups of weights to points on carefully designed grids (lattices) or non-linear value tables, which gives better quality at very low bit counts. They are designed to be used with an importance matrix.

Ternary types (TQ1_0, TQ2_0) store weights as -1, 0 or +1, for models trained that way (BitNet-style). They are not a good target for ordinary models.

Microscaling floating point (MXFP4, and the newer NVFP4) store 4-bit floating-point values with a shared scale per block. Some recent models (for example OpenAI’s gpt-oss) were trained with MXFP4 weights, so a GGUF in MXFP4 is effectively the original precision for those tensors.

Why files are “mixes”: Q4_K_M is not every tensor at Q4_K. llama-quantize keeps sensitive tensors (some attention value and feed-forward down projections, embeddings, the output layer) at higher precision such as Q6_K, and 1-D tensors (norms, biases) at F32. That is why a “4-bit” Q4_K_M file averages about 4.9 bits per weight.

Reading quant names

Q4_K_M
│ │ └─ mix size: S (small), M (medium), L (large) — how many tensors get a higher-precision type
│ └─── K = k-quant family (super-blocks with quantized scales)
└───── base bits per weight for most tensors

IQ3_XXS
│ │  └─ size within the family: XXS < XS < S < M (bigger = more bits, better quality)
│ └──── base bits
└────── i-quant family (grid/non-linear codebooks, best with an imatrix)

Q8_0 / Q4_0 / Q5_1
│   └─ legacy type: _0 = scale only, _1 = scale + minimum
└───── bits

UD-Q4_K_XL   publisher-specific label (here Unsloth "Dynamic"), a custom per-tensor mix;
             not a llama-quantize preset, but the file is a normal GGUF

Other labels you may see on Hugging Face: F16 / BF16 (unquantized 16-bit), F32, imat or i1- (made with an imatrix), and -00001-of-00003.gguf (split shards; load the first one).

Complete quant type reference

The presets accepted by llama-quantize. Sizes and perplexity changes are the figures llama.cpp prints in its own help text, measured on Llama-3-8B (or Mistral-7B for F16/BF16), and the average bits per weight comes from the measured table in the quantize README for Llama-3.1-8B.

Preset Family Avg bits/weight (8B file) 8B file size Perplexity change vs 16-bit (8B) Use it for
F32 float 32 26 GB (7B) reference almost never
F16 float 16.0 14.0 GB (7B) +0.0020 master copy, conversion source
BF16 float 16.0 14.0 GB (7B) -0.0050 master copy (preferred for models trained in bf16)
Q8_0 legacy 8.50 7.96 GB +0.0026 near-lossless, when memory allows
Q6_K k-quant 6.56 6.14 GB +0.0217 very high quality
Q5_K_M k-quant mix 5.70 5.33 GB +0.0569 high quality, a common “safe” choice
Q5_K_S k-quant mix 5.57 5.21 GB +0.1049 slightly smaller Q5
Q5_1 / Q5_0 legacy   5.65 / 5.21 GB +0.1062 / +0.1316 superseded by Q5_K
Q4_K_M k-quant mix 4.89 4.58 GB +0.1754 default recommendation
Q4_K_S k-quant mix 4.67 4.37 GB +0.2689 a bit smaller than Q4_K_M
IQ4_NL i-quant 4.68     4-bit non-linear; good on some ARM/CPU paths
IQ4_XS i-quant 4.46     smaller than Q4_K_S with similar quality (use an imatrix)
Q4_1 / Q4_0 legacy   4.78 / 4.34 GB +0.4511 / +0.4685 old; Q4_0 still used for some CPU/ARM fast paths
MXFP4_MOE microscaling       MoE models released in MXFP4
Q3_K_L k-quant mix 4.30 4.03 GB +0.5562 when Q4 does not fit
Q3_K_M k-quant mix 4.00 3.74 GB +0.6569  
IQ3_M i-quant mix 3.76     better than Q3_K_S at similar size
Q3_K_S k-quant mix 3.64 3.41 GB +1.6321 noticeable loss
IQ3_S i-quant 3.66      
IQ3_XS i-quant 3.50      
IQ3_XXS i-quant 3.25     big models in small memory
Q2_K k-quant mix 3.16 2.96 GB +3.5199 large loss on small models
Q2_K_S k-quant mix 2.97 2.96 GB +3.1836  
IQ2_M i-quant mix 2.93     70B+ models on limited hardware
IQ2_S / IQ2_XS / IQ2_XXS i-quant 2.74 / 2.59 / 2.38     very large models only
IQ1_M / IQ1_S i-quant 2.15 / 2.00     experiments with huge (100B+) models
TQ2_0 / TQ1_0 ternary 2.06 / 1.69 (nominal)     models trained ternary
COPY none       copy tensors without quantizing (re-shard, edit metadata)

The “avg bits/weight” for i-quants and low-bit k-quants is higher than their nominal value because the mix keeps some tensors at higher precision; on bigger models the average gets closer to the nominal value. Q4_K, Q3_K and Q5_K are accepted as aliases for the _M variants. Recent builds also list experimental Q1_0 and Q2_0 types.

Perplexity changes are for one 8B model on one text corpus. Use them to rank types, not to predict exact quality on your task.

Quality vs size: what you actually lose

What the numbers say (from the table above, Llama-3-8B): going from 16-bit to Q8_0 changes perplexity by about 0.003, Q6_K by 0.02, Q5_K_M by 0.06, Q4_K_M by 0.18, Q3_K_M by 0.66 and Q2_K by 3.5. The curve is flat down to about 5 bits, bends around 4 bits, and drops steeply below 3 bits.

Practical guidance

Things that change the picture

Factor Effect
Model size Larger models tolerate quantization much better. A 70B model at 3 bits often beats a 13B at 8 bits; a 1B model at 3 bits may be unusable.
Mixture-of-Experts Large MoE models also tolerate low bits well, and publishers often keep shared or attention tensors at higher precision.
Task Coding, math and tool calling are more sensitive than chat or summarization.
imatrix Improves low-bit quants (especially i-quants and Q2/Q3) noticeably; small benefit at 5 bits and above.
Calibration data An imatrix made from data similar to your use (chat, code, a language) helps more than generic text.
Long context Errors compound over long generations; test with prompts as long as your real ones.

How to decide for your use case: download two candidates (for example Q4_K_M and Q6_K), run 20 of your real prompts through both, and compare. If you cannot tell them apart, keep the smaller one.

Speed differences between quant types

Token generation on most hardware is limited by memory bandwidth, so smaller files generate faster: speed scales roughly with 1 / file size. In llama.cpp’s own 8B measurements on a GPU, generation went from about 29 tokens/s at F16 to 51 at Q8_0 and 72 at Q4_K_M.

Other effects:

Measure, do not guess:

llama-bench -m model-Q4_K_M.gguf -m model-IQ4_XS.gguf -m model-Q5_K_M.gguf

Importance matrix (imatrix)

An importance matrix records, for each weight column, how strongly it is activated on sample text. During quantization, llama-quantize uses it to spend precision where it matters, minimizing error on important weights.

# 1. compute an imatrix from calibration text using a high-precision model
llama-imatrix -m model-BF16.gguf -f calibration.txt -o imatrix.gguf -ngl 99

# 2. quantize with it
llama-quantize --imatrix imatrix.gguf model-BF16.gguf model-IQ4_XS.gguf IQ4_XS

Notes:

Convert and quantize a model yourself

Do this when a model has no GGUF yet, when you fine-tuned your own, or when you want a custom mix. For one-off conversions without any setup, the GGUF-my-repo Space on Hugging Face does conversion and quantization in the browser.

1. Get llama.cpp and its Python requirements

git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cmake -B build && cmake --build build --config Release -j     # builds llama-quantize, llama-imatrix, ...

The conversion script needs the model’s Python-side support in transformers; for very new architectures you may need pip install -U transformers.

2. Convert Hugging Face weights to a 16-bit GGUF

# from a local folder (downloaded with `hf download <repo> --local-dir ./my-model`)
python convert_hf_to_gguf.py ./my-model --outfile my-model-BF16.gguf --outtype bf16

# or straight from the Hub
python convert_hf_to_gguf.py --remote google/gemma-3-1b-it --outfile gemma-3-1b-it-BF16.gguf --outtype bf16

--outtype accepts f32, f16, bf16, q8_0 and auto. Convert to 16-bit first, then quantize; quantizing from an already quantized file loses extra quality.

3. Quantize

./build/bin/llama-quantize my-model-BF16.gguf my-model-Q4_K_M.gguf Q4_K_M
./build/bin/llama-quantize --imatrix imatrix.gguf my-model-BF16.gguf my-model-IQ3_M.gguf IQ3_M

The third argument is a preset name from the reference table. An optional fourth argument sets the thread count.

4. Multimodal models (vision or audio)

The language model and its encoder/projector are separate files. Convert the projector with --mmproj, usually keeping it at high precision:

python convert_hf_to_gguf.py --remote google/gemma-3-4b-it --mmproj --outtype q8_0 --outfile mmproj-gemma-3-4b-it-Q8_0.gguf
llama-cli -m gemma-3-4b-it-Q4_K_M.gguf --mmproj mmproj-gemma-3-4b-it-Q8_0.gguf --image photo.jpg -p "Describe this image"

5. LoRA adapters

python convert_lora_to_gguf.py ./my-lora-adapter --base ./base-model --outfile my-lora-F16.gguf
llama-server -m base-model-Q4_K_M.gguf --lora my-lora-F16.gguf

Or merge the adapter into the base weights in Python first (for example with PEFT’s merge_and_unload()), then convert the merged model normally.

6. Test and publish

llama-cli -m my-model-Q4_K_M.gguf -p "Hello"                         # smoke test, including the chat template
llama-perplexity -m my-model-Q4_K_M.gguf -f wiki.test.raw             # optional quality check
hf upload <your-user>/my-model-GGUF ./my-model-Q4_K_M.gguf            # publish with the hf CLI

In the model card, list the source model, the llama.cpp version, the presets, and whether an imatrix was used and with what data.

Advanced quantization options

Option What it does
--imatrix FILE Use an importance matrix
--output-tensor-type TYPE Type for output.weight (the final projection)
--token-embedding-type TYPE Type for the token embeddings
--tensor-type PATTERN=TYPE Per-tensor override with regex support, e.g. --tensor-type attn_v=q6_k --tensor-type ffn_down=q5_k
--leave-output-tensor Keep output.weight unquantized
--pure Disable the k-quant mix; every tensor gets the same type
--allow-requantize Allow quantizing an already-quantized file (quality warning)
--keep-split Write output in the same shards as the input
--target-bpw N / --target-size SIZE Let llama-quantize pick per-tensor types to hit an average bits-per-weight or a file size
--prune-layers 20,21 Remove layers (experimental model surgery)
--override-kv KEY=TYPE:VALUE Edit metadata in the output, e.g. general.name=str:"My Model"
--dry-run Show what would happen without writing a file

Custom mixes are how publishers make “dynamic” or “XL” variants: they upgrade the tensors most sensitive to quantization (often attention, the first and last layers, or shared experts in MoE models) and push the rest lower.

Splitting and merging big files:

llama-gguf-split --split-max-size 40G model-Q4_K_M.gguf model-Q4_K_M         # writes -00001-of-0000N.gguf shards
llama-gguf-split --merge model-Q4_K_M-00001-of-00003.gguf model-Q4_K_M.gguf

Runtimes load split models when you point them at the first shard, so merging is rarely needed.

Measure quality: perplexity and KL divergence

Perplexity (PPL) measures how well the model predicts a test text; lower is better. It is useful for comparing quantizations of the same model on the same text, not for comparing different models.

llama-perplexity -m model-Q4_K_M.gguf -f wiki.test.raw -ngl 99

KL divergence (KLD) compares the quantized model’s full next-token probability distributions with the 16-bit model’s. It is more sensitive than perplexity and is the preferred metric among people who publish quants.

# 1. save reference logits from the 16-bit model (large file: tens of GB for a full test set)
llama-perplexity -m model-BF16.gguf -f test.txt --kl-divergence-base logits.kld
# 2. compare a quantized model against them
llama-perplexity -m model-Q4_K_M.gguf --kl-divergence-base logits.kld --kl-divergence

The KLD run also reports how often the top token matches the original (“same top p”), a very intuitive number. In the llama.cpp perplexity README, a Q4_K_M quant of Llama-3-8B matches the original top token about 92% of the time, and Q6_K about 98%.

Run GGUF models

Runtime Command or method
llama.cpp CLI llama-cli -m model.gguf or llama-cli -hf user/repo:Q4_K_M
llama.cpp server llama-server -m model.gguf -c 16384 --port 8080 (OpenAI-compatible API plus a web chat)
Ollama (from Hugging Face) ollama run hf.co/user/repo:Q4_K_M
Ollama (local file) Modelfile with FROM ./model.gguf, then ollama create my-model -f Modelfile
LM Studio Search and download in the app, or drop GGUF files into its models folder
Python llama-cpp-python: Llama(model_path="model.gguf") or Llama.from_pretrained(repo_id=..., filename="*Q4_K_M.gguf")
Jan, KoboldCpp, llamafile Load the GGUF in the app

Useful llama.cpp runtime flags:

Flag Purpose
-c N Context size (0 = the model’s trained maximum, which can use a lot of memory)
-ngl N\|auto\|all GPU layers (default auto)
-fa on\|off\|auto Flash attention (default auto)
-ctk / -ctv TYPE KV cache quantization (next section)
-cmoe Keep MoE expert weights in CPU RAM, attention on GPU
--mmproj FILE Multimodal projector

KV cache quantization

The context (KV cache) can take as much memory as the weights for long prompts. llama.cpp and Ollama can store it at lower precision:

Setting Bytes per value Memory vs f16 Notes
f16 (default) 2 100%  
q8_0 1.0625 53% Very small quality impact; good default when memory is tight
q4_0 0.5625 28% Noticeable on long-context recall for some models
llama-server -m model.gguf -c 32768 -ctk q8_0 -ctv q8_0
OLLAMA_KV_CACHE_TYPE=q8_0 ollama serve

KV cache size per sequence: 2 × layers × kv_heads × head_dim × tokens × bytes_per_value. For a Llama-3-8B-style model (32 layers, 8 KV heads, head dim 128) that is 128 KiB per token at f16, about 4.3 GB at 32K tokens. tools/gguf_inspect.py prints this for any file.

Finding good GGUFs on Hugging Face

Browse all GGUF repos with the GGUF library filter. Well-known publishers of GGUF conversions:

Publisher Notes
ggml-org Official llama.cpp organization; reference conversions used in docs
bartowski Wide coverage, imatrix quants, clear file tables
unsloth Includes “UD” dynamic mixes and fixes for chat templates
lmstudio-community Conversions curated for LM Studio
mradermacher Very wide coverage, including imatrix (i1) repos

Also check the original model publisher: many now release official GGUFs.

Checklist before downloading

GGUF vs other formats

Format / method Typical runtimes Bits Hardware focus Notes
GGUF (k-quants, i-quants) llama.cpp, Ollama, LM Studio, Jan, KoboldCpp 1.5 to 16 CPU, Apple Silicon, consumer GPUs, mixed CPU+GPU Single file, best for local and partial offload
safetensors (16-bit) transformers, vLLM, SGLang 16 GPUs Original weights; the usual source for conversion
MLX mlx-lm, LM Studio, Ollama on Macs 3 to 8, 16 Apple Silicon Fastest option on Macs in many cases
GPTQ vLLM, transformers (GPTQModel) 2 to 8 NVIDIA/AMD GPUs Calibration-based, GPU serving
AWQ vLLM, SGLang, transformers 4 GPUs Activation-aware; the original AutoAWQ repo is archived, newer tooling includes llm-compressor
EXL2 / EXL3 ExLlamaV3 (and V2) fractional bits NVIDIA GPUs Fine-grained bitrates, fast on single NVIDIA GPUs
bitsandbytes (NF4, int8) transformers 4, 8 NVIDIA and others Quantizes on load; popular for QLoRA fine-tuning
FP8 / FP4 (NVFP4, MXFP4) vLLM, SGLang, TensorRT-LLM, llama.cpp 4, 8 Recent data-center and consumer GPUs Hardware-native low precision

Rule of thumb: GGUF for local and mixed CPU/GPU, MLX on Macs, GPTQ/AWQ/FP8 for GPU serving with vLLM or SGLang, EXL for single NVIDIA GPU speed, bitsandbytes for fine-tuning.

Tools in this repo

Both tools are single Python files with no dependencies (Python 3.9+).

tools/gguf_inspect.py

Reads only the header of a GGUF file (fast even for 100 GB files) and prints what you usually want to know:

$ python tools/gguf_inspect.py Qwen3-8B-Q4_K_M.gguf
Qwen3 8B  (qwen3, GGUF v3)
  file type      MOSTLY_Q4_K_M
  parameters     8.19 B
  file size      4.68 GiB  (4.906 bits per weight)
  context        40960  layers 36  heads 32/8 (q/kv)
  KV cache (f16) 144.00 KiB per token, 1.13 GiB at 8K, 4.50 GiB at 32K
  weights by type:
    Q4_K      ...
    Q6_K      ...
    F32       ...

(Illustrative output; numbers depend on the file.) Options: --all prints every metadata key (long arrays such as the vocabulary are summarized), --json prints a machine-readable summary.

How it computes things: parameters are the sum of tensor element counts; bits per weight is the exact tensor data size (from each tensor’s type, block size and bytes per block) divided by parameters; KV cache uses block_count, head_count_kv and the head dimension from the metadata. It was cross-checked against the official gguf Python package’s reader on files written by the official writer.

tools/quant_calc.py

Estimates file size and total memory for any parameter count at every preset, optionally including the KV cache:

$ python tools/quant_calc.py --params 8 --layers 32 --kv-heads 8 --ctx 32768
8B parameters, KV cache 4.29 GB (32768 tokens, f16)
type         bpw   file GB  total GB
IQ1_S       2.00      2.00      7.30
...
Q4_K_M      4.89      4.89     10.19
...
Q8_0        8.50      8.50     13.79
F16        16.00     16.00     21.29

Tests

python -m unittest discover -s tests -v

The tests build small synthetic GGUF files byte by byte and check parsing, parameter counts, bits per weight, KV cache math, error handling for non-GGUF and truncated files, and the block-size table against the known bits per weight of each type.

Troubleshooting

Problem Cause Fix
unknown model architecture Your llama.cpp (or the tool built on it) is older than the model Update llama.cpp / Ollama / LM Studio
invalid magic or not a GGUF file Wrong file (HTML error page, safetensors, partial download) Re-download; check size and first bytes (GGUF)
Model outputs garbage or repeats endlessly Missing or wrong chat template, or a broken conversion Use a reputable repo; check tokenizer.chat_template; update the runtime
Converter fails with a missing architecture Converter does not support this model yet Update llama.cpp; check open issues for the model
Converter needs a newer transformers New model code pip install -U transformers in the llama.cpp venv
Quantizing a quantized file is refused Protection against double quantization Start from F16/BF16; use --allow-requantize only if you accept the loss
Split model will not load Pointing at a later shard or shards in different folders Load -00001-of-0000N.gguf with all shards in one folder
Out of memory although file is smaller than VRAM KV cache and compute buffers Lower -c, quantize the KV cache, or pick a smaller quant
Very slow even on GPU Layers offloaded to CPU Check logs for offloaded layer count; smaller quant or -cmoe for MoE

FAQ

What does Q4_K_M mean? A 4-bit k-quant “medium” mix: most weights stored at 4.5 bits in super-blocks of 256 with quantized scales, with some sensitive tensors at 6 bits. On average about 4.9 bits per weight.

Q4_K_M vs Q4_K_S? _M keeps more tensors at higher precision: about 5% bigger and measurably better. Prefer _M unless every megabyte counts.

Q4_K_M vs Q5_K_M vs Q6_K vs Q8_0? Each step up is bigger and closer to the original. On an 8B model the perplexity increase over 16-bit is about 0.18, 0.06, 0.02 and 0.003 respectively.

Is IQ4_XS better than Q4_K_M? It is about 9% smaller with similar quality when made with a good imatrix. If you have the memory, Q4_K_M is the safer default; IQ4_XS is great when it is the difference between fitting and not fitting.

What is the difference between K-quants and I-quants? K-quants use per-sub-block scales in super-blocks and are fast everywhere. I-quants use grid or non-linear codebooks plus an importance matrix and give better quality at 2 to 4 bits, sometimes at lower CPU speed.

Is GGUF only for llama models? No. The name comes from the llama.cpp project, but GGUF supports many architectures: Qwen, Gemma, Mistral, Phi, DeepSeek, GLM, gpt-oss, Mamba-style models, embedding models, vision encoders and more.

Can I convert GGUF back to safetensors? You can dequantize to 16-bit, but the information lost in quantization does not come back. Keep the original weights if you plan to fine-tune.

Can I fine-tune a GGUF? Not directly in most training frameworks. Fine-tune the original safetensors model (for example with LoRA), then convert and quantize the result.

Why is my 4-bit 7B file 4.4 GB instead of 3.5 GB? Block scales add overhead (Q4_K is 4.5 bits, not 4), the mix keeps some tensors at 6 bits, and embeddings or output layers may be larger. The real average is shown by tools/gguf_inspect.py.

Does quantization make models faster? Usually yes for generation, because less data is read per token. It mainly makes models fit; speed follows from size.

What is an mmproj file? The multimodal projector (and encoder) that turns images or audio into tokens for a vision or audio model. Load it with --mmproj alongside the main GGUF.

What does “UD” mean in Unsloth’s file names? “Unsloth Dynamic”: custom per-layer quant mixes chosen by Unsloth, stored as ordinary GGUF files.

Glossary

Term Meaning
bpw Bits per weight: file data size × 8 / number of parameters
Block / super-block Group of weights sharing scale factors (32, or 256 for k- and i-quants)
Scale / min Per-block factors used to reconstruct weights from small integers
Mix A preset that assigns different types to different tensors
imatrix Importance matrix: activation statistics used to guide quantization
Perplexity exp(average negative log-likelihood) on a test text; lower is better
KL divergence How different two probability distributions are; 0 means identical
ftype general.file_type: the preset recorded in the file
mmproj Multimodal projector file for vision/audio models
Shard One part of a model split across several files
Dequantize Convert quantized weights back to floats (for compute or export)
Runtime repack Rearranging weights at load time for faster kernels on a specific CPU

Where to go next

Contributing

PRs are welcome: corrections, new quant types as llama.cpp adds them, reproducible KLD/perplexity comparisons (include the model, llama.cpp version, test text and exact commands), and improvements to the tools with tests. Keep the tools dependency-free. Every factual claim should link to the llama.cpp source, docs or a reproducible measurement.

If this guide cleared up the alphabet soup, a star helps others find it.

More free resources

Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.