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
| Concept | What to understand |
|---|---|
| Scale & zero-point | Mapping float range to integer range |
| Per-channel quant | Each output channel has own scale — better for weight quantization |
| Calibration data | Representative inputs to measure activation ranges |
| Accuracy-vs-compression tradeoff | INT4 = 8× compression, INT8 = 4× compression |
Files
| File | Purpose |
|---|---|
lab.py | Stubs with TODO markers |
solution.py | Complete working implementation |
test_lab.py | pytest suite |
requirements.txt | Dependencies |
Run
pip install -r requirements.txt
python lab.py
pytest test_lab.py -v