Lesson 8 · Phase 3 · The Model, DemystifiedFree preview lesson

GGUF Quantization: 4GB → 1GB

The scale-and-round math that shrinks a model 4x with barely a quality dent: compute the scale, quantize the block to int4, dequantize on the fly. Do the arithmetic yourself on a real weight matrix.

This lesson's full video is free to watch on the homepage watch it now and see this exact math done on the whiteboard.

What you'll learn

  • Compute block scales and quantized int values by hand
  • Understand Q4 / Q8 trade-offs in the GGUF format
  • Shrink a checkpoint 4x and know exactly what you lost

The whole idea in three lines

scale = max(block) / 15          # 15 = biggest value 4 bits can hold
q     = round(weight / scale)    # quantize: FP16 -> int4   (this is what gets stored)
w'    = q * scale                # dequantize on the fly at inference time

Weights are grouped into small blocks. Each block stores one FP16 scale plus one tiny integer per weight. 16 bits per weight becomes 4 — a 4GB model becomes roughly 1GB, and the reconstruction error is bounded by half a scale step per weight.

Quantization playground

One block of eight real weights. Every number below — scale, ints, dequantized values, errors — is computed live from the formulas above. Shuffle the block, flip Q4 ↔ Q8, and watch what you lose.

max(block) = 0.6scale = max / 15 = 0.040000

One FP16 scale is stored per block; every weight in the block shares it.

weight (FP16)round(w / scale)stored int4dequantized (q × scale)error
0.12003.000330.1200+0.0000
0.450011.25011110.4400-0.0100
0.30007.500880.3200+0.0200
0.600015.00015150.6000+0.0000
0.05001.250110.0400-0.0100
0.24006.000660.2400+0.0000
0.510012.75013130.5200+0.0100
0.33008.250880.3200-0.0100

4 bits

per weight, instead of 16 — a 4x shrink

0.0200

worst error in this block

0.0075

mean absolute error

Flip between Q4 and Q8 and watch the error column: Q8 has 17x more levels to snap to, so its errors are tiny — but the file is twice the size. Choosing a quant is choosing where you sit on that trade-off.

Why this matters for agents

GGUF is the file format that packages these quantized blocks (plus the tokenizer and metadata) into a single file that llama.cpp can memory-map and run on a CPU. It is the reason Gemma 4 E4B — 8B parameters — fits in about 5GB of RAM on the free Colab T4 that powers every agent in this course. No quantization, no local agents. In the next lesson you'll meet the tool that serves these GGUF files with one command: Ollama.