Quantization Fundamentals
Volume IV, Chapter 18 — Part I. Number representation, uniform and non-uniform quantization, quantization error analysis, affine mapping INT8, and post-training vs. quantization-aware training theory.
Prerequisites
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- Number Representation
- Uniform Quantization
- Quantization Error Analysis
- Affine Quantization Mapping
- Per-Tensor vs. Per-Channel Quantization
- Post-Training vs. Quantization-Aware Training
- Weight vs. Activation Quantization
- Worked Examples
- Connection to the Broader Curriculum
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- Define uniform quantization with scale and zero-point .
- Derive affine mapping and dequantization .
- Bound quantization error for uniform quantizers.
- Compare PTQ vs. QAT theoretically.
- Explain why per-channel quantization preserves accuracy for weight matrices.
Prerequisites
- Matrix Operations — linear layers
- Backpropagation — gradient flow in QAT
Notation
- — Full-precision and quantized values
- — Scale and zero-point
- — Bit width (INT8, INT4, etc.)
- — Quantization rounding operator
- — Quantization error
Core Intuition
Neural networks use FP32/FP16 weights — 32 or 16 bits per parameter. Quantization maps weights and activations to low-bit integers (INT8, INT4), reducing memory and enabling faster integer arithmetic.
A 70B model in FP16: 140 GB. INT4: ~35 GB — runnable on consumer GPUs. Combined with LoRA (QLoRA) and Flash Attention, quantization is essential for deployment.
Series context. Volume IV, Chapter 18 (Quantization).
Quantization Fundamentals (Inference)
Number Representation
Definition 1 (Floating Point). FP16: 1 sign + 5 exponent + 10 mantissa bits. Dynamic range via exponent.
Definition 2 (Fixed Point / Integer). INT8: values in . Fixed scale.
Proposition 1. INT8 has 4× fewer bits than FP32 → 4× memory reduction (ignoring overhead).
Uniform Quantization
Definition 3 (Uniform Quantizer). Map real to integer :
where is scale, is zero-point, is bit-width.
Definition 4 (Symmetric Quantization). , .
Quantization Error Analysis
Theorem 1 (Uniform Quantization Error). For round-to-nearest uniform quantization:
Proof. Rounding error bounded by half quantization bin width.
Proposition 2 (MSE Error). For uniformly distributed in bin: .
Corollary 1. Smaller scale (more bits or narrower range) → lower error.
Affine Quantization Mapping
Definition 5 (Scale and Zero-Point). For asymmetric INT8:
Maps , exactly.
Proposition 3 (Quantized Matmul). Integer matrix multiply with rescaling:
Enables INT8 GEMM on hardware accelerators.
Per-Tensor vs. Per-Channel Quantization
Definition 6 (Per-Channel). Separate per output channel of weight matrix .
Proposition 4. Per-channel preserves accuracy for weights with heterogeneous magnitude distributions across channels — critical for Self-Attention projection matrices.
Post-Training vs. Quantization-Aware Training
Definition 7 (PTQ). Quantize after training using calibration data to estimate .
Definition 8 (QAT). Simulate quantization during training with straight-through estimator (STE):
Proposition 5. QAT allows model to adapt to quantization noise; PTQ is faster but lower accuracy at low bit-widths.
Weight vs. Activation Quantization
- Weights — Static (known at load) — Outlier channels
- Activations — Dynamic (runtime) — Range varies per input
Definition 9 (Weight-Only Quantization). Quantize to INT4; activations remain FP16 — used in GPTQ, AWQ for LLMs.
Worked Examples
Example 1: INT8 Mapping
, : , , .
Example 2: Memory
7B params × 4 bits = 3.5 GB vs. 14 GB FP16.
Connection to the Broader Curriculum
- LoRA — QLoRA
- Flash Attention — composable
- Data Parallelism — distributed quantized inference
- Linear Regression — quantization error as noise
Common Pitfalls and Misconceptions
Pitfall 1: INT8 always 4× faster (depends on hardware/kernel).
Pitfall 2: Ignoring outliers in activation ranges.
Pitfall 3: PTQ sufficient for INT4 (often needs QAT or advanced PTQ).
Pitfall 4: Quantizing KV Cache separately from weights.
Research Perspective
GPTQ (Frantar et al., 2022). AWQ (Lin et al., 2023). FP8 training (NVIDIA H100). LLM.int8() mixed precision.
Summary of Takeaways
- Quantize —
- Dequantize —
- Error bound —
- PTQ vs QAT — Calibration vs. STE training
Next: Data Parallelism
Exercises
Exercise 1. Derive (4) for asymmetric INT8.
Exercise 2. Prove error bound (3).
Exercise 3. Compute memory for 70B model at INT4 vs FP16.
Exercise 4. Why per-channel for weights?
Exercise 5. STE gradient justification.
Exercise 6. Quantized matmul (5) derivation.
Exercise 7. Outlier effect on scale .
Exercise 8. QLoRA: compose LoRA + INT4.