Model Compression

compress

Quantization

Post-Training Quantization (PTQ)

Convert a trained FP32 model to INT8 without retraining. Calibrate scale factors using a representative dataset (100–1000 samples). Fast, but accuracy can drop 1–5% on sensitive tasks.

Key Features
  • No retraining required
  • Calibration dataset: 100–1000 samples
  • Weight + activation quantization
  • Dynamic (weights only) or static (both)
  • TFLite converter, ONNX quantize tool
Similar Technologies
Quantization-aware trainingMixed-precision PTQGPTQ (LLMs)
Quantization-Aware Training (QAT)

Insert fake-quantization nodes during training so the model learns to tolerate integer rounding. Typically recovers 1–3% accuracy versus PTQ. Required when PTQ accuracy is unacceptable.

Key Features
  • Fake-quant ops simulate INT8 rounding
  • Straight-through estimator for gradients
  • TF: tf.quantization.quantize_and_dequantize
  • PyTorch: torch.ao.quantization FX API
  • Best accuracy at given bit-width
Similar Technologies
PTQ with longer calibrationMixed-precisionLearned step size (LSQ)
Weight-Only Quantization

Quantize only the weight tensors, keeping activations in FP. Reduces model size for storage and transfer. Useful when activation ranges are highly dynamic (e.g., audio processing).

Key Features
  • INT4/INT8 weights, FP32 activations
  • No calibration dataset needed
  • Dequantize weights at runtime
  • Less speedup than full INT8
  • Good for memory-limited Flash, not RAM
Similar Technologies
Full INT8 quantizationMixed-precisionSparse quantization
Binary & Ternary Networks

Extreme quantization: weights and activations restricted to {-1, +1} (binary) or {-1, 0, +1} (ternary). Replace MACs with XNOR + popcount. 32× smaller, 58× faster on capable hardware, but significant accuracy cost.

Key Features
  • XNOR-Net, BinaryNet architectures
  • popcount replaces multiply-accumulate
  • Typical accuracy gap: 5–15% vs FP32
  • Effective for keyword spotting tasks
  • Custom CMSIS kernels or Larq library
Similar Technologies
INT4 quantizationStructured pruningDistillation to INT8
table_chart

Quantization Schemes Compared

SchemeBitsSize vs FP32Accuracy DropMCU SupportBest For
FP32321× (baseline)NonePoor (no FPU on most MCUs)Training, reference
FP16162× smallerNegligibleLimited (Cortex-M33 FPU)Edge servers
INT884× smaller0.5–2%Excellent (CMSIS-NN)General TinyML
INT448× smaller2–5%Good (custom kernels)Very constrained MCUs
Binary (BNN)132× smaller5–15%Possible (XNOR ops)Ultra-tiny classifiers
Mixed-precision4–84–8× smallerMinimalGoodSensitive layer protection
content_cut

Pruning

Unstructured (Weight) Pruning

Zero out individual weights below a magnitude threshold. Creates a sparse weight tensor. Size reduction requires sparse storage formats; actual speedup requires sparse compute support (rare on MCUs).

Key Features
  • Magnitude-based: remove small weights
  • Iterative pruning + fine-tuning
  • Lottery ticket hypothesis
  • CSR/CSC sparse formats for storage
  • Limited MCU speedup without sparse HW
Similar Technologies
Structured pruningQuantizationNAS-based architecture reduction
Structured (Channel/Filter) Pruning

Remove entire filters, channels, or attention heads. Produces a smaller dense model — no sparse compute required. Can directly reduce RAM and latency on any MCU without special hardware support.

Key Features
  • L1-norm filter ranking
  • Activation-based importance scores
  • Remove whole output channels
  • Dense model — standard runtime
  • 20–50% channel removal with ~2% accuracy loss
Similar Technologies
Unstructured pruningKnowledge distillationArchitecture search
school

Knowledge Distillation

Knowledge Distillation Basics

Train a small student model to mimic the soft output probabilities of a large teacher model, not just the hard labels. The teacher's probability distribution carries richer signal about class relationships.

Key Features
  • Soft targets: teacher's probability vector
  • Temperature T softens distributions
  • Loss = α·CE(student, hard) + β·KL(student, teacher)
  • Student can be 10–100× smaller than teacher
  • No teacher needed at inference time
Similar Technologies
PTQQATStructured pruning
Feature & Intermediate Distillation

Distill intermediate layer activations (feature maps, attention maps) in addition to logits. Helps the student learn internal representations. Important when student and teacher differ strongly in architecture.

Key Features
  • FitNets: match intermediate feature maps
  • Attention Transfer: match attention maps
  • RKD: relational knowledge distillation
  • Requires projection layers when channels differ
  • Stronger than logit-only for TinyML
Similar Technologies
Logit-only distillationData augmentationLabel smoothing
account_tree
StepTechniqueToolExpected GainNotes
1Architecture choiceMobileNet, MCUNet, DS-CNN10–100× vs ResNet baselineStart small, not compressed large
2Quantization-aware trainingTF QAT, PyTorch FX4× size, minimal accuracy lossFake-quant during training
3Structured pruningTF Model Optimization, torch.nn.utils.prune2–5× FLOP reductionAfter QAT, before export
4Knowledge distillationCustom training loopRecover 1–3% accuracyOptional; helps after aggressive pruning
5Convert to runtime formatTFLite converter, microTVM compileFurther kernel fusionValidate accuracy post-conversion
6On-device profilingTFLite Micro benchmark, Edge Impulse profilerConfirm RAM/Flash/latencyAlways measure on real hardware