Lab 01 — PTQ Pipeline

Phase: 03 — Quantization & Model Compression | Difficulty: ⭐⭐⭐⭐☆ | Time: 2–3 hours

Post-Training Quantization (PTQ) converts a trained FP32 model to INT8/INT4 without retraining.

What you build

  • Symmetric and asymmetric per-tensor/per-channel quantization
  • Calibration-based scale/zero-point computation
  • Full PTQ pipeline for a linear model
  • Accuracy evaluation: cosine similarity and relative error

Key concepts

ConceptWhat to understand
Scale & zero-pointMapping float range to integer range
Per-channel quantEach output channel has own scale — better for weight quantization
Calibration dataRepresentative inputs to measure activation ranges
Accuracy-vs-compression tradeoffINT4 = 8× compression, INT8 = 4× compression

Files

FilePurpose
lab.pyStubs with TODO markers
solution.pyComplete working implementation
test_lab.pypytest suite
requirements.txtDependencies

Run

pip install -r requirements.txt
python lab.py
pytest test_lab.py -v