Foundations to Frontier
Tests
F. NLP and Large Language Models › F8 Inference and Serving

Quantization: GPTQ, AWQ, GGUF, fp8

Quantisation stores weights (and sometimes activations and the KV cache) in fewer bits: 8-bit integers or FP8 for near-lossless serving, 4 bits or fewer to fit large models on small GPUs and laptops. Because decoding is memory-bound, smaller weights also mean faster generation. The difficulty is that LLM activations have a few outlier channels, so a weight's error matters much more on some inputs than others. AWQ rescales the weights on salient channels before rounding. GPTQ quantises weights one at a time and corrects the remaining ones for the error, using the inverse Hessian. GGUF (llama.cpp) uses simple block-wise formats suited to CPUs. This page covers the formats, the methods and the trade-offs. In the exercises you implement symmetric quantisation and storage costs. You then quantise a 256 × 256 layer with LLM-like activations (correlated, with 20× outlier channels). Relative output error: int8 0.7%, FP8 2.6%, 4-bit round-to-nearest 10.9% (groups of 64), AWQ 6.1%, GPTQ 3.6%. At 3 bits, GPTQ (8.4%) beat 4-bit rounding.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Storing numbers with fewer digits

A model’s weights are normally stored with 16 bits each. Quantisation rounds them to 8, 4 or even 3 bits, like storing prices to the nearest pound instead of the penny. The model shrinks by 2–5× and runs faster, but rounding adds small errors. Clever methods decide which weights matter most and round more carefully there, or adjust other weights to cancel the errors. This is how 70-billion-parameter models run on a single GPU or a laptop.

LLM lab
7B-class model (32 layers, 32 query heads of 128 dims, fp16) at 8192 tokens: full multi-head KV cache 4.00 GiB; with 8 KV heads (grouped-query attention) 1.00 GiB per sequence.
Why engineers care

Quantisation decides whether a model fits on given hardware, such as an onboard computer or a single workstation GPU; 8-bit is usually safe, while 4-bit needs a calibrated method and an accuracy check on the target task.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Quantisation reduces…
  2. 2. A 16-bit model quantised to 4 bits is about ___ smaller:
  3. 3. Quantisation adds…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Uniform quantisation: q = round(w/s), w ≈ s·q; symmetric (zero at 0) or asymmetric with a zero point. Granularity: per tensor, per output channel, or per group of 32–128 weights (one scale per group, adding 16/g bits per weight).
  • Weight-only vs weight-and-activation: weight-only (W4A16) speeds up memory-bound decoding; W8A8 and FP8 also use faster low-precision matrix units.
  • FP8 (E4M3, E5M2): floating point with 3 or 2 mantissa bits; per-tensor or per-channel scaling; near-lossless for inference and used in training on recent GPUs.
  • Outliers: a few activation channels are 10–100× larger; errors in the weights they multiply dominate the output error. LLM.int8() keeps them in 16 bits; SmoothQuant moves scale from activations to weights.
  • AWQ: scale salient input channels of W up by s (and activations down) before rounding, choosing s = mean|x|^α on calibration data.
  • GPTQ: quantise one input row at a time; update the remaining rows to compensate, weighted by H⁻¹ with H = XᵀX from calibration data.
  • GGUF / llama.cpp: file format with block quantisation types (Q8_0, Q4_K_M, Q5_K…) for CPU and Apple-silicon inference.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Group-wise int4 with group 64 costs about ___ bits per weight:
  2. 2. AWQ protects…
  3. 3. GPTQ compensates errors using…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Quantisation in practice

Exercise 1.

  • Quantise a vector symmetrically and recover the scale.
  • Dequantise codes.
  • Compute bits per weight including group scales.

Practice.

  • Serving: vLLM and TGI load GPTQ, AWQ and FP8 checkpoints; bitsandbytes gives quick 8-bit and 4-bit (NF4) loading in transformers.
  • Local: llama.cpp and Ollama use GGUF files (Q4_K_M is a common default).
  • Calibrate on a few hundred samples resembling the deployment data.
  • Always evaluate the quantised model on the target task; 4-bit often loses 1–3 points on reasoning benchmarks, more for small models.
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
q = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype="bfloat16")
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-Instruct", quantization_config=q)
# vLLM: LLM("TheBloke/...-AWQ", quantization="awq")  or  LLM(model_id, quantization="fp8")
# llama.cpp: llama-quantize model-f16.gguf model-q4_k_m.gguf Q4_K_M
🐍 Exercise 1: symmetric quantisation
Implement symmetric quantisation, dequantisation and bits per weight with group scales.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Format used by llama.cpp:
  2. 2. Quick 4-bit loading in transformers:
  3. 3. Before deploying a 4-bit model…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

What error matters. The layer output is y = xW, so the damage of a weight error ΔW is ‖XΔW‖², which equals Σ ΔWᵀ H ΔW over output columns, with H = XᵀX. Errors on rows (input channels) with large activations count more; correlated activations mean errors on different rows can cancel or add.

AWQ reduces the relative rounding error on rows with large H by scaling them up before rounding (finer steps for them, coarser for others). It changes nothing else, so it is fast and robust.

GPTQ solves the problem approximately: after rounding row j it adjusts all later rows by the optimal brain surgeon update −(Δw_j/[H⁻¹]_jj)·[H⁻¹]_j,:, which minimises the added output error. When activations are correlated, later rows can absorb much of the error, so GPTQ beats rounding by a wide margin. When channels are independent (diagonal H), there is nothing to compensate with, and the update only fits calibration noise.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Output error of a weight perturbation is weighted by…
  2. 2. GPTQ's gains come from…
  3. 3. With independent activation channels, GPTQ…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How much accuracy do int8, FP8 and 4-bit methods lose on a layer with LLM-like activations?

History.

  • T. Dettmers et al., “LLM.int8()” (2022): outlier features.
  • E. Frantar et al., “GPTQ” (ICLR 2023).
  • G. Xiao et al., “SmoothQuant” (ICML 2023); J. Lin et al., “AWQ” (MLSys 2024).
  • P. Micikevicius et al., “FP8 formats for deep learning” (2022); G. Gerganov, llama.cpp and GGUF (2023).

Exercise 2.

  • Layer: 256 × 256 Gaussian weights.
  • Activations: a rank-32 correlated component plus small noise, with 4 outlier channels 20× larger. 1024 calibration and 1024 test inputs.
  • Metric: ‖X(W − Ŵ)‖ / ‖XW‖ on test inputs.
scheme bits per weight relative output error
int8 per channel 8 0.0069
FP8 E4M3 per tensor 8 0.0256
int4 per channel, round-to-nearest 4 0.1277
int4 groups of 64, round-to-nearest 4.25 0.1085
int4 g64, AWQ (α = 0.3) 4.25 0.0614
int4 g64, GPTQ without act-order 4.25 0.0390
int4 g64, GPTQ 4.25 0.0357
int3 g64, round-to-nearest 3.25 0.2547
int3 g64, GPTQ 3.25 0.0838
  • 8 bits are close to lossless: int8 per channel 0.7%. FP8 with a single per-tensor scale gave 2.6%, from its 3-bit mantissa.
  • Groups help rounding a little (12.8% → 10.9%), AWQ helps more (6.1%), GPTQ most (3.6%, a third of rounding).
  • 3-bit GPTQ beat 4-bit rounding (8.4% against 10.9%), which is why GPTQ-style methods made 3–4-bit models practical.
  • A negative result first: with independent activation channels (an earlier version of this study), GPTQ was no better than rounding on test data (12.3% against 10.9%), better only on calibration data (9.1%). Its gains depend on the correlations real LLM activations have.
  • Seeds 1 and 2: GPTQ 3.4% and 3.3%, AWQ 6.0% and 6.1%, rounding 10.5% and 10.9%.
  • Caveat: one layer, not a model; end-to-end perplexity effects also depend on how errors compound over layers.
🐍 Exercise 2 (research): how much accuracy do int8, FP8 and 4-bit methods lose on a layer with LLM-like activations?
Quantise a layer with outlier, correlated activations using int8, FP8, round-to-nearest int4/int3, AWQ and GPTQ; compare output error.

Quantisation in AI, robotics and aerospace

  • Local and edge LLMs: 4-bit GGUF models run on laptops, phones and embedded boards.
  • Datacentre serving: FP8 weights, activations and KV caches on H100/B200-class GPUs nearly double throughput.
  • Onboard autonomy: int8 quantisation (TensorRT, TFLite) is standard for vision and policy networks on Jetson-class and radiation-tolerant hardware; verify accuracy after quantisation.

References

  1. E. Frantar, S. Ashkboos, T. Hoefler and D. Alistarh (2023). “GPTQ: accurate post-training quantization for generative pre-trained transformers.” ICLR.
  2. J. Lin et al. (2024). “AWQ: activation-aware weight quantization for LLM compression and acceleration.” MLSys.
  3. T. Dettmers, M. Lewis, Y. Belkada and L. Zettlemoyer (2022). “LLM.int8(): 8-bit matrix multiplication for transformers at scale.” NeurIPS.
  4. G. Xiao et al. (2023). “SmoothQuant: accurate and efficient post-training quantization for large language models.” ICML.