ML Systems Lab Open interactive version →
Advanced 29 min read quantisationINT8model compressionefficiency

Quantisation & Model Efficiency

INT8 vs FP16, quantisation-aware training vs PTQ, calibration, accuracy tradeoff

Fine-tuning (LoRA or otherwise) answered how to adapt a trained model cheaply. This module answers a different question: how to make that trained model small and fast enough to actually run. A trained model stores every weight as a float32 number — 4 bytes each. GPT-2's 117 million weights take 468 MB just sitting there. On a phone, that is often too big to load and too slow to run. The obvious question: do we really need 4 bytes of precision per weight, or can we get away with less?

We can get away with a lot less. Store each weight as an 8-bit integer instead — 1 byte — and the file shrinks 4× to 117 MB. Better still, most CPUs have special hardware for 8-bit integer math (the same circuitry that makes video and audio codecs fast), so the model also runs 2–4× faster. For a phone, that is often the difference between "can't run this" and "runs smoothly."


How do you turn a float into an 8-bit integer?

An 8-bit integer can only be one of 256 values. So you take the actual range of the weights — say [−0.5, 0.5] — and chop it into 256 evenly spaced buckets. Each weight is rounded to its nearest bucket: `x_int = round((x_float − min) / scale)`, where `scale = (max − min) / 255` — this maps the range's low end to integer 0 and its high end to 255, the full span of an unsigned 8-bit integer. Two nearby floats that land in the same bucket become the same integer. That rounding is the price you pay — a small error per weight.

The catch is *outliers.* If 99.9% of weights sit in [−0.5, 0.5] but one weight is 5.0, the range must stretch to cover it — and now your 256 buckets are spread across a huge span, wasting almost all of them and leaving the common weights with almost no precision. Handling outliers well is the whole game in quantization.


The key move: calibrate on real data

Weights are fixed after training, so their range is known exactly. But *activations* — the numbers flowing between layers — change with every input, and you can't know their range in advance. So you *calibrate*: run 100–1000 real, representative inputs through the model, watch the actual activation ranges at each layer, and set the scale factors from what you see. This is post-training quantization (PTQ) — no retraining, done in minutes. With good calibration, INT8 typically loses under 1% accuracy. Skip calibration — guess the ranges instead of measuring them — and accuracy collapses silently, with no error in the logs. That silent failure is the single most common quantization mistake.


When PTQ isn't enough

Push down to 4-bit and PTQ starts dropping 2–5% accuracy — too many weights crammed into too few buckets. Two fixes. Smarter PTQ (GPTQ, AWQ) protects the weights that matter most and nudges the rest to compensate for rounding, reaching 4-bit at under 1% loss. Or quantization-aware training (QAT): simulate the rounding *during* training so the model learns to place its weights where they round cleanly. QAT recovers the most accuracy but costs a full retraining run — so you reach for it only when 4-bit-and-below quality is critical.

Key points

Takeaway

Quantization is a calibration problem: the scale factors that map float ranges to integers are only valid for the distribution they were calibrated on — skip calibration or shift the production distribution and the accuracy drop will be silent, with no error and no obvious cause.

Recap

Check your understanding

Q1. INT8 quantization reduces a weight from float32 (32 bits) to int8 (8 bits). What is the compression ratio, and what information is lost? Select the TWO correct statements.

Q2. Post-training quantization (PTQ) vs quantization-aware training (QAT): when do you use each, and what is the typical accuracy difference?

Q3. Why are activations harder to quantize than weights in a neural network?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →