← Explainer Library

Interactive Explainer

Quantization & Pruning, Side by Side

Two ways to shrink a model. Quantization reduces bit-width per weight; pruning zeroes weights out entirely. Slide both, see accuracy hold, then crack at predictable thresholds.

Step 1

The compression menu

Step 1½

Quantization, with the math you actually need

The simplest scheme — affine (asymmetric) uniform quantisation — maps a float tensor $x \in [x_{\min}, x_{\max}]$ to a $b$-bit integer:

where $s$ is the scale and $z$ the zero-point. Dequantisation: $\hat x = s \cdot (q - z)$. Round-trip error per element is uniformly distributed in $[-s/2, s/2]$, with variance $s^2 / 12$. Halving the bit-width halves $\log_2(\text{levels})$ — so each bit saves $\sim$1× memory and adds $\sim$6 dB of quantisation noise.

Two practical choices that matter more than they sound:

Step 2

Live: slide bits and sparsity

A trained 2-hidden-layer MLP on a 3-class 2-D dataset. The base weights are trained to convergence; we apply quantization (PTQ) and magnitude-pruning at inference time and report the accuracy.

size acc
Original FP32 model
Compressed model
Size-vs-accuracy curve
Weight distribution (FP32 → quantised grid; pruned → 0)
Step 3

The thresholds you should know

Step 3½

GPTQ, AWQ, SmoothQuant — the LLM quantisation family

Naively running PTQ on a 70B LLM at int4 obliterates accuracy. Three techniques restore most of it; all are post-training, all are calibration-driven (use a few hundred unlabelled prompts), and all ship in popular runtimes.

The 2026 LLM quantisation recipe. For inference: weights at int4 via AWQ or GPTQ, activations at int8 via SmoothQuant, K/V cache at int8. Total: ~4× memory reduction vs fp16 with < 1% perplexity hit on most 7B–70B chat models.
Step 4

Lottery ticket — pruning's surprise

Frankle & Carbin (2019) showed that within a dense random-initialisation network, there exists a small subnetwork (a "winning ticket") that, when trained from the same initial weights, matches or beats the dense network's accuracy. The recipe:

  1. Train dense network. Save initial weights.
  2. Prune by magnitude (e.g., bottom 80%).
  3. Reset surviving weights to their initial values.
  4. Retrain. Often hits the same accuracy as the dense network.
  5. (Iterate; "iterative magnitude pruning" finds smaller tickets.)
What it tells us. Most weights in a trained network are unused; pruning finds the useful subset. Initialization matters — random init plus pruning fails; matched init plus pruning succeeds. This is a clue to the implicit bias of SGD that mainstream theory still hasn't fully explained.
Step 5

Practical stack for shipping a small model

  1. Start big. Train the largest model your data supports; you'll compress later.
  2. Distil into a smaller architecture. See the KD article; a smaller student that imitates the teacher's softmax often beats a same-size from-scratch model.
  3. Apply structured pruning for real speed-up on commodity hardware. 25-35% drop without quality loss.
  4. QAT at int8 as the production target. Validate on a calibrated test set (see calibration).
  5. Optional: int4 with GPTQ / AWQ for big LLMs where memory is the bottleneck.
  6. Profile + iterate. Almost all "the model is too slow" complaints are actually data-pipeline / I/O problems, not the model. Always profile first.
  7. Deployment runtimes: ONNX Runtime, TensorRT-LLM, llama.cpp, MLC-LLM, Core ML, TFLite. Each ships its own quantization tools and has its own production gotchas.
Step 6

Structured sparsity that actually speeds up hardware

Unstructured 90% sparsity rarely speeds up inference on a GPU — the dense matmul kernel still runs over the zeros. Two patterns the hardware actually likes:

Step 7

Reading list