Shrink Ray
A brain stores every wire strength as a long, precise number: 32 bits each. Phones, watches and web pages want models that are small and fast. The shrink ray rounds every number onto a short ruler with only a few marks. Fewer marks = fewer bits = tinier model. But round too hard and the brain gets confused.
First I'm training a small brain (648 wires and 49 extra numbers) to tell the two spiral arms apart. Watch the map on the left fill in. Then point the shrink ray at it!
Training steps: 0
Full-size brain (32-bit)
Shrunk brain
Shading is the brain's guess for every spot. When the shrunk map gets blotchy and dots turn red-ringed, rounding has broken the brain.
The wires and the ruler
Challenges
What just happened?
- The brain learned with long, exact numbers. The shrink ray rounds each one to the nearest mark on a ruler. With b bits the ruler has about 2b marks.
- 8 bits (256 marks) is so fine that the brain barely notices, and it's 3 times smaller. That's why so many phone and web models use 8-bit numbers.
- At 2 bits there are only 3 or 4 marks. Most wires get squashed to the same few values and the spiral falls apart.
- A ruler per row fits each row's own range, so small wires don't all get rounded to zero. It costs a few extra bytes for the extra rulers.
- Practising while shrunk (QAT) lets the brain move its wires to spots that survive rounding, and wins back a lot of the lost accuracy.
How it works
- Train a 2 → 24 → 24 → 1 brain on the spiral using normal 32-bit numbers.
- For each layer (or each row) find the biggest wire. Space the ruler marks evenly so the end marks reach it.
- Store each wire as just the number of its nearest mark (a small whole number), plus one scale number per ruler.
- To use the brain, multiply the mark numbers back by the scale and run it as usual.
- QAT: train a bit more, rounding in the forward pass but nudging the hidden exact numbers as if rounding weren't there.
For grown-ups: what's really going on
This is uniform affine quantisation of a 697-parameter MLP (tanh hidden layers, sigmoid output, Adam, full batch, 300 training points, 600 test points). Symmetric: s = max|w| / (2b−1 − 1), q = clamp(round(w / s), −(2b−1−1), 2b−1−1), ŵ = s·q. Asymmetric: s = (max − min) / (2b − 1), zero-point z = round(−min / s), ŵ = s·(q − z).
- PTQ vs QAT. Post-training quantisation just rounds a trained model. Quantisation-aware training fine-tunes with fake-quantised weights in the forward pass and the straight-through estimator (∂ŵ/∂w ≈ 1) in the backward pass, on float "shadow" weights. Here: 150 Adam steps at lr 0.005.
- Granularity. Per-channel scales (one per output row) fit each row's range and lower the rounding error; they're standard for conv/linear weights in int8 toolchains. Activations here use a fixed [−1, 1] range (tanh), so no calibration is needed; real PTQ calibrates activation ranges on sample data.
- Size counts packed b-bit weights, 32-bit biases (int8 schemes usually keep int32 biases) and one fp32 scale (+1 byte zero-point) per group. "16-bit" here is int16, not fp16/bf16. Chip time is a made-up cost model, only for the shape of the trade-off.
- In practice. ONNX Runtime and PyTorch export int8 models (dynamic or static quantisation, QDQ graphs). The Live AI Lab downloads
q8ONNX models for exactly this reason, and Mood Racer showed that the 8-bit version's scores differ slightly from full precision. LLMs go further: 4-bit weight-only methods like GPTQ and AWQ, and formats like NF4. - Measured in Node (seed 3/5, 1500 steps): float ≈ 99.7%; 8-bit any scheme ≈ 99.7%; 3-bit per-tensor symmetric ≈ 92% → about 99% after QAT; 2-bit per-tensor ≈ 28–33% (worse than guessing: the boundary flips), per-channel 2-bit 80–99%.
Reading: Jacob et al., "Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference" (2018, arXiv:1712.05877).