Skip to content
datarekha

What is GGUF, and what does a quantization tier like Q4_K_M mean?

The short answer

GGUF is a single-file format for packaging an LLM's weights, tokenizer data, and metadata for local inference. The Q4 K M tier is a mixed-precision quantization recipe that stores most weights at roughly four bits each, reducing memory substantially while preserving more quality than a uniformly quantized four-bit format.

How to think about it

GGUF is a binary, single-file format for packaging an LLM’s weights and inference metadata; Q4_K_M is a quantization recipe inside that file that represents most weights with roughly four bits while keeping selected tensors at higher precision. GGUF makes local loading convenient, and Q4_K_M makes the model small enough for ordinary hardware, but neither one guarantees a particular speed or quality level.

Why GGUF exists

Imagine running an 8B-parameter instruct model on a laptop with 16 GB of RAM. A normal FP16 copy of the weights alone needs about 16 GB in decimal units. The operating system, runtime, tokenizer, context window, and application need memory too. The model may fail to load, or the computer may start swapping so aggressively that generating one sentence feels like waiting for a committee.

A training checkpoint is often designed around Python code, a particular model library, and several separate files. That is useful during training. It is awkward for a local inference program that simply needs to load tensors and generate tokens.

GGUF, originally short for GPT-Generated Unified Format, packages the model data into a format designed for inference. A GGUF file can contain:

  • the weight tensors and their shapes
  • architecture and hyperparameter metadata
  • vocabulary and tokenizer information
  • special-token definitions
  • a chat template when the converter includes one
  • the quantization type used for each tensor

A runtime such as llama.cpp can inspect that metadata, allocate the right tensor types, and load the model without reconstructing a Python training pipeline. GGUF also supports memory mapping, so the operating system can map file regions into memory instead of forcing the loader to copy the entire file immediately. Exact behaviour depends on the runtime and hardware, but the format is built around this efficient loading pattern.

The important distinction is that GGUF is a container format, not an inference engine. It does not generate text by itself. The runtime supplies the kernels, sampling logic, hardware support, and conversation handling. Ollama, LM Studio, and other local tools commonly use llama.cpp-compatible GGUF models, but the file still needs a compatible loader.

Reading Q4_K_M

The name has three useful parts:

  • Q4 means a nominal four-bit quantization level.
  • K means the weights use a K-quant scheme with grouped blocks and shared quantization parameters.
  • M means a medium mixed-precision recipe, not a medium-sized model.

Start with the Q4. In FP16, every weight takes 16 bits, or 2 bytes. Quantization replaces a floating-point value with a small integer code plus enough information to reconstruct an approximation later. Four bits provide 16 possible codes for each quantized value.

The runtime does not use one scale for the entire model. It divides weights into blocks. For a block, it stores a compact set of codes and parameters such as a scale and offset. During inference, it reconstructs an approximation along the lines of:

weight_i ≈ scale × code_i + offset

The exact equation differs between quantization types, but the idea is stable: many weights share a small amount of metadata. That is why the nominal bit count is not the complete file-size calculation. Scales, offsets, alignment, metadata, and higher-precision tensors all consume space.

The K schemes improve on older simple formats by using more structured blocks and better scale handling. They generally preserve quality better than an older format such as Q4_0 at a similar size. This is not magic; the extra block metadata gives the quantizer more useful information about the local range of the weights.

The M variant goes one step further. In the common llama.cpp quantization recipes, most tensors use Q4_K, while selected attention and feed-forward tensors use a higher-precision K format, commonly Q6_K. Those tensors are more sensitive to quantization error for many model architectures. Spending extra bits there often buys better output quality for a modest increase in file size.

So the useful translation is:

Q4_K_M means “mostly four-bit K-quantized weights, with a medium mixed-precision allocation.”

It does not mean exactly four bits for every weight, and it does not mean the model has fewer parameters.

A concrete size calculation

Suppose the local support assistant uses an 8B-parameter model.

FP16:  8,000,000,000 × 16 ÷ 8 = 16,000,000,000 bytes
Q4:    8,000,000,000 × 4  ÷ 8 =  4,000,000,000 bytes

The FP16 weights therefore take about 16 GB in decimal units, or roughly 14.9 GiB, before runtime memory. The theoretical four-bit calculation gives 4 GB. A real Q4_K_M file for an 8B-class model is usually closer to roughly 4 to 5 GB because of scales, mixed-precision tensors, metadata, and the model’s vocabulary structures.

That difference is practical. On a 16 GB laptop, FP16 leaves almost no room for anything else. Q4_K_M leaves enough room for the operating system and a local runtime, so the model can run instead of becoming an expensive desktop wallpaper.

The file is not the whole memory budget. During generation, the runtime also maintains a KV cache, which stores attention keys and values for tokens already processed. The cache grows with context length and with the number of simultaneous requests. For an 8B architecture with 32 layers, 8 key-value heads, and 128-wide heads, an FP16 KV cache is roughly 0.5 GiB at 4,096 tokens and about 1 GiB at 8,192 tokens. The exact number depends on the architecture and cache precision. Quantizing the model weights does not make this cache disappear.

The senior-level nuance

Q4_K_M is a strong default, not a law of nature.

It often works well on CPUs because the runtime reads substantially fewer bytes from memory. On a GPU, the smaller model may fit entirely in VRAM and avoid slow CPU-to-GPU transfers. But dequantization has a cost, and a highly optimized GPU serving engine may process FP16 or another native format more efficiently, especially with large batches. A smaller file does not automatically mean lower latency.

Quality is also model- and task-dependent. A large instruction model may look nearly unchanged at Q4_K_M on ordinary chat prompts. A small model, code generator, mathematical reasoner, or strict JSON producer may show errors earlier. Quantization error can turn a valid function into code with a missing delimiter, or make a model repeat a phrase instead of completing the answer.

A practical selection rule is:

  • Use FP16 or BF16 when you have the memory and quality is the priority.
  • Use Q8_0 when you want a file much smaller than FP16 with output usually very close to it.
  • Use Q6_K or Q5_K_M when coding, reasoning, or structured output justifies spending more memory.
  • Start with Q4_K_M when local memory is constrained and you need a sensible quality-to-size balance.
  • Treat Q3 and Q2 variants as hardware compromises, not automatic bargains.

For a real deployment, I would test the same model at two or three tiers on a fixed set of prompts covering the actual workload. I would record peak RAM or VRAM, time to first token, generation throughput, and task quality. A quantization that saves 2 GB but causes a support bot to invent ticket numbers is not a successful optimization.

A common failure mode

The first symptom of overly aggressive quantization is often not a loading error. The model loads, but answers become repetitive, code becomes syntactically unreliable, or structured output stops following the requested schema. Compare the same prompts with Q4_K_M and Q6_K or Q8_0 using the same model and sampling settings.

Do not blame every bad response on quantization. A base model used with an instruct chat template, a missing chat template, or a tokenizer mismatch can produce the same symptoms. Confirm the model family, tokenizer, and conversation template before changing tiers.

What they’ll ask next

Is Q4_K_M exactly four bits per weight?
No. Four bits describes the nominal payload for most quantized values. Scales, offsets, block metadata, alignment, and higher-precision tensors raise the effective size, so the real file is larger than the simple parameter-count calculation.

Does Q4_K_M quantize the KV cache or the activations too?
Usually, the name describes the stored model weight tensors. The runtime may offer separate settings for KV-cache or activation precision. Those settings are independent and should not be inferred from the GGUF filename.

What is the difference between Q4_K_M and Q4_0?
Q4_0 is an older, simpler four-bit format. Q4_K_M uses K-quant blocks and a mixed-precision allocation, so it normally preserves more quality at a similar size. The actual winner still depends on the model, backend, and workload, so benchmark rather than trusting the label blindly.

Say this in the interview: GGUF is the inference-oriented single-file container, while Q4_K_M is a mostly four-bit mixed-precision weight encoding that makes local inference practical with a controlled quality trade-off.

Learn it properly GGUF & running LLMs locally

Keep practising

All NLP & LLMs questions

Explore further