16 — Scale & Optimize

Model Compression#

OptimizationStatistical 1 min read
◆ The PatternPruning, distillation, and the lottery ticket hypothesis

Pruning removes unimportant weights (structured or unstructured). Knowledge distillation trains a small "student" model to mimic a large "teacher." The lottery ticket hypothesis suggests sparse subnetworks within large models can match full performance — if you find the right ticket.

Compression Ratio = Original Size / Compressed Size
A 4× compression ratio means your model is 75% smaller — faster only if the hardware and runtime exploit the compression.
// Interactive — pruning vs accuracy tradeoff
Sparsity %50%
Accuracy—
Pattern bridge: Model compression is feature selection applied to weights — remove what's redundant to keep what matters. In markets, signal-to-noise filtering does the same: strip the noise, keep the signal.
Worked example

Prune 80% of a layer’s weights, keeping the largest fifth, and measure how much its output changes. If the weights are all of similar size, the output error is 59% — there is nothing small to remove. If a few weights are large and most near zero, the error is 11%. Compression works when a model is redundant, and how redundant it is has to be measured, not assumed.

Where it misleads
  • Output error is not task accuracy; fine-tune after pruning and evaluate on the real task.
  • Unstructured sparsity rarely speeds up standard hardware; structured pruning (whole channels or heads) or distillation usually pays off more.
  • Compressed models can lose accuracy unevenly, hurting rare classes most.
In code
rng = np.random.default_rng(4)
x = rng.normal(0, 1, (1_000, 256))                 # a batch of inputs

def prune_error(W, keep=0.20):                     # keep the largest 20% of weights by size
    cut = np.quantile(np.abs(W), 1 - keep)
    Wp = np.where(np.abs(W) >= cut, W, 0)
    return np.linalg.norm(x @ Wp - x @ W) / np.linalg.norm(x @ W)

even = prune_error(rng.normal(0, 1, (256, 256)))            # weights all of similar size
peaked = prune_error(rng.standard_t(1.5, (256, 256)))       # a few large weights and many near zero
Python, in your browser — edit the code and run it again

Assumes import numpy as np and import pandas as pd. Each snippet carries its own example numbers; the comments say which are made up or simulated.

Sources
  • S. Han, H. Mao & W. J. Dally, “Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman Coding”, ICLR, 2016
  • G. Hinton, O. Vinyals & J. Dean, “Distilling the Knowledge in a Neural Network”, arXiv:1503.02531, 2015
  • J. Frankle & M. Carbin, “The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks”, ICLR, 2019

Last reviewed October 2026 · How this site checks its content · Report a mistake

Linked from 1
← Previous
Orchestration & Scheduling
Open in the full reader, with the topic sidebar