Pruning, quantization, distillation and latency
What it is
Pruning removes individual weights, channels, heads, or entire structures; structured pruning is usually more likely to produce real hardware speedups than merely sparse tensors. Quantization stores and computes values with fewer bits, either after training or with quantization-aware training that teaches the model to tolerate rounding. Distillation trains a smaller student to match a teacher's soft outputs or intermediate representations, transferring useful dark knowledge beyond hard labels. Compression targets memory, latency, throughput, energy, or cost—not an abstract parameter count alone.
Why it matters
A smaller checkpoint can still be slow if kernels are unsupported or runtime is dominated by sequence length and memory movement. Benchmark the deployed path on representative inputs, hardware, batch sizes, and concurrency—not a synthetic single request. Quality evaluation should include calibration, rare slices, output format compliance, and task-specific human judgments where a headline accuracy number hides unacceptable regressions.
In the real world: Making a model small and fast enough to run on a phone or answer in milliseconds.
Visual example
Deep learningCompression transforms a trained model, then checks quality and runtime on the real serving path.
import torch
baseline = torch.load('model_fp32.pt', map_location='cpu')
size_mb = sum(p.numel() * p.element_size() for p in baseline.values()) / 1e6
print(f'checkpoint: {size_mb:.1f} MB')
# Compression is only real if this improves on the deployed path.
latency_p50, latency_p99 = benchmark(model, representative_requests)Reporting accuracy after compression without testing calibration, rare slices, output quality, and latency. Compression can preserve a headline metric while breaking the cases that matter.