Skip to content
C.W.K.
Stream
Lesson 03 of 06 · published

GGUF and the Quantization Ladder

~14 min · gguf, quantization, llama-cpp, tradeoffs

Level 0Kindling
0 XP0/32 lessons0/10 achievements
0/100 XP to next level100 XP to go0% complete

Two formats, two jobs

Safetensors is the format of storage and training frameworks; GGUF is the format of local inference runtimes. It rose with llama.cpp-style engines: one file that bundles architecture metadata, tokenizer, and quantized tensors so a single loader on a laptop can run models that would not fit in RAM at full precision. If safetensors is the archival master, GGUF is the portable copy — and confusing the two roles is where most fidelity mistakes enter an archive.

A GGUF file is self-describing: it carries its own metadata KV block (architecture, context parameters, general alignment) plus the tensor data. Quantized tensors are stored in block schemes rather than plain dtype arrays — the famous Q4_K_M style rungs — where groups of weights share computed scale factors. That is the mechanism of the size savings: fewer effective bits per weight, with correction terms engineered to spend the saved budget where it hurts least.

Reading the ladder honestly

The rungs are not marketing; they are real engineering trade points between size and fidelity:

  • F16/BF16 (16-bit) — the reference; when the master itself is 16-bit, this rung is the master. A downcast from an FP32 master trims the low bits, which is exactly why lesson 04 counts downcasts as derivatives.
  • Q8_0 (≈8.5-bit effective) — very close to the reference in output quality; roughly half the size. The conservative rung.
  • Q6_K — the pragmatic sweet spot many runtimes recommend; small quality concession for meaningful size savings.
  • Q5_K_M / Q4_K_M — the workhorse rungs of local inference; visible but usually acceptable degradation, big size wins, fits models onto ordinary hardware.
  • Q3 and below, and the tiny -S variants — specialist territory; quality costs become case-by-case and task-dependent.

Two honest caveats. First, degradation is task-shaped: a quantized model can hold up fine on casual chat and lose measurable ability on edge-case reasoning, code, or minority languages — benchmark your actual workload, not vibes. Second, rungs do not compose: converting a Q4 file to Q8 does not restore anything; you get a bigger container for already-lost information. The ladder's information flows downhill only.

GGUF is a derivative format by design. Its purpose is fitting inference onto constrained hardware. An archive keeps GGUFs the way a kitchen keeps pre-cut firewood — labeled, placed by the stove, and never mistaken for the tree.

Inspecting a GGUF without running it

Like safetensors, GGUF is inspectable without loading: the header and metadata are readable, and the tensor inventory (with quantization types per tensor) is right there. Runtimes ship inspector commands for exactly this — use one before trusting a file, and note what precision the file actually carries versus what its filename claims.

Code

Inspect a GGUF's metadata and tensor inventory·bash
# The gguf package (PyPI; the llama.cpp project's own Python tooling)
# reads GGUF metadata without executing anything:
pip install gguf
python3 - <<'EOF'
from gguf import GGUFReader
r = GGUFReader("model-Q4_K_M.gguf")
for name, field in r.fields.items():
    print(f"{name:32} {field.types}")
EOF

# What to read off the dump:
#   general.architecture      — which engine family expects it
#   *.context_length          — claimed context window
#   tokenizer fields          — bundled tokenizer (it is self-contained)
#   per-tensor quant types     — mixed quantization is common:
#                               e.g. Q4_K for most weights, Q6_K or
#                               higher for attention-sensitive tensors
#
# The size sanity check that catches mislabeled files:
#   params × bits/8 ≈ file size. A "Q4_K_M" of a 7B model at
#   ~4.1 GB is plausible; the same file at 14 GB is not Q4.

External links

Exercise

Find (or download) one GGUF you use. Dump its metadata and answer: which architecture and context does it claim, what is the per-tensor quantization mix, and does the size sanity check (params × bits/8 ≈ file size) hold? Then write the one-line shelf label you would give it in an archive that also holds the full-precision master.
Hint
The size check needs the parameter count — the metadata or the model's card supplies it. For the shelf label, the key word is 'derivative of <master> for <runtime/device>'.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.