TL;DR
A trained network usually has far more weights than it needs. Pruning finds the weights that matter least, sets them to exactly zero, and then trains the remaining weights for a little longer so they can make up the lost ability. Done well, the network keeps almost all of its accuracy with a large share of its weights gone.
The common recipe is simple: train, remove, fine-tune, and repeat if you want more removal. Most of the work is in deciding which weights to remove.
Where you'll see it: shrinking language models and image classifiers so they fit on phones, and cutting the cost of inference on servers where the model runs millions of times a day.
Intuition
A garden with too many plants
Picture a garden planted so densely that every plant gets a little sunlight and none of them thrive. If you pull out the weakest third, the rest grow into the space. A large neural network is similar. Many connections were useful during training, but many others carry almost no signal once the network has settled. Pruning is the gardener's step: find the weak connections, remove them, and let the strong ones adjust.
The reason this works at all is that training is noisy and over-parameterised. A network with many more weights than it strictly needs can fit the training data in many different ways, and most of those ways contain a lot of redundancy. Pruning exploits that redundancy. It does not try to discover a new, smaller model from scratch. It starts from a big model that already learned something and trims it, then runs a short round of Fine-Tuning so the remaining weights can compensate.
Why small weights are a rough guide
The simplest rule is to call a weight unimportant when its absolute value is small. A weight near zero multiplies its input by almost nothing, so removing it changes the output a little. The picture below shows why this is a useful but imperfect heuristic. If the weights of one layer are roughly bell-shaped around zero, a threshold on removes the middle of the bell and keeps the tails.
- weight density, σ = 0.3
The plot shows a bell centred at zero, which is typical for trained weights. The markers at mark a threshold. Everything between them is removed. Those are the numbers a magnitude threshold would cut.
flowchart LR
A["Train dense network"] --> B["Score each weight (for example by magnitude)"]
B --> C["Set lowest scoring weights to zero"]
C --> D["Fine-tune remaining weights"]
D --> E{"Enough sparsity?"}
E -- "no, prune more" --> B
E -- "yes" --> F["Ship sparse model"]
The math
Pruning as a constrained problem
Let be the vector of all weights in a trained network, and let be the training loss. Pruning asks for a mask that keeps at most weights, and then minimises the loss over the kept weights:
Here is the entrywise product, so a weight with mask value 0 is forced to zero. The term counts the nonzero entries of , which is the number of kept weights. The sparsity is the fraction removed: . A sparsity of 0.9 means ninety percent of the weights are zero.
Searching over all masks is hopeless, because there are of them. Pruning methods are therefore heuristics that pick a mask one step at a time.
Magnitude pruning
The most common heuristic keeps the weights with the largest . Sort the absolute values, pick the cutoff that leaves exactly of them above it, and set
It costs one sort per layer and no extra training signal. Its weakness is that it ignores the loss entirely. A small weight that sits on a very sensitive direction of the loss can matter more than a large weight on a flat direction.
Saliency from curvature
A better score comes from a second-order Taylor expansion of the loss. Write the change in loss when weight is set to zero, so , where is the unit vector for weight . Then
Here is the gradient and is the Hessian, the matrix of second derivatives. A trained network sits near a minimum, so . Keeping only the diagonal entry of gives the saliency
This is the score used in Optimal Brain Damage, proposed by LeCun, Denker and Solla in 1990. It removes the weights with the smallest . Weights with a large are the ones the loss cares about most.
Structured versus unstructured
Everything above removes individual weights, which is unstructured pruning. The mask is irregular, so a dense matrix multiply still does all the work on zeros unless the hardware or library has a sparse kernel. Structured pruning removes whole rows, columns, filters or attention heads. The result is a smaller dense matrix, so the speedup shows up on ordinary hardware. The price is that structured removal is coarser and usually costs more accuracy for the same number of parameters removed.
Worked examples
Start with a layer whose weights are
- The absolute values are .
- We want to keep weights, which is sparsity .
- Sorted from largest to smallest, the absolute values are .
- The top three are , and , so the threshold is .
- Zero out everything below in absolute value. Those are , and .
- The pruned layer is .
Interpretation: half the weights are gone, and the three that survived are the three with the largest magnitude. Nothing in this calculation looked at the loss, so the result is only as good as the assumption that size tracks importance.
Two weights in the same layer have the following values, where is the diagonal Hessian entry.
| Weight | Saliency | ||
|---|---|---|---|
| A | |||
| B |
- By magnitude, weight B () is four times larger than weight A (), so magnitude pruning keeps B and removes A.
- By saliency, weight A scores and weight B scores .
- So saliency keeps A and removes B.
Interpretation: weight B is large but sits in a flat region of the loss, so the network barely notices if it goes. Weight A is small but sits where the loss is steep, and removing it would hurt. Real pruning methods approximate the Hessian diagonal because computing the full Hessian for a large network is far too expensive.
A realistic case is a dense layer with weights stored as 32-bit floats. That is bytes, about 4 MB. Prune it to 90% sparsity and weights remain. In a dense format the file is still 4 MB, because the zeros are stored. In a compressed sparse format each surviving weight also needs an index of roughly 4 bytes, so the file is about MB plus a small amount of row bookkeeping. The memory saving is real only if you use a sparse format, and the speed saving is real only if the kernel exploits the sparsity. This is why structured pruning is popular when the goal is latency on ordinary hardware.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Heavy pruning in one step | Accuracy collapses and fine-tuning cannot recover it | Prune gradually over several rounds, with fine-tuning between them |
| Target runs on a standard GPU or CPU with dense kernels | Unstructured zeros give almost no speedup | Structured pruning of channels or heads, or a sparse kernel |
| Very small model | Little redundancy, so each removal costs more | Consider quantization or a smaller architecture instead |
| Model used on new data after pruning | Pruned for one data distribution, weak on another | Re-evaluate on the new data and fine-tune on a representative set |
| Pruning by magnitude alone | Removes sensitive weights that happen to be small | Use a loss-aware score such as saliency, or gradient-based importance |
Pruning is not the only way to shrink a model. Quantization stores the same weights in fewer bits, and distillation trains a small model to copy a large one. These methods combine well. A common pipeline prunes, then quantizes, then fine-tunes. For the wider family, see Model Compression.
History
Early work on removing network connections came in the late 1980s and early 1990s. LeCun, Denker and Solla's Optimal Brain Damage (1990) used the Hessian-based saliency described above. Hassibi and Stork's Optimal Brain Surgeon (1993) refined it with a fuller use of second-order information. These methods were principled but needed expensive curvature estimates, so they were hard to use on large networks.
Interest came back in the mid-2010s, when networks grew very large. Han, Pool, Tran and Dally (2015) showed that simple magnitude pruning, followed by retraining, could remove most of the connections in AlexNet with little loss of accuracy. Their follow-up, Deep Compression, combined pruning with quantization and weight sharing. Frankle and Carbin's Lottery Ticket Hypothesis (2018) later suggested that pruned networks contain small subnetworks that can train well from their original initialization, which changed how researchers think about why pruning works. The exact compression ratios in these papers are worth checking against the papers themselves.
Check yourself
QuestionA layer has weights (0.3, -0.9, 0.1, 0.6). You prune 50% by magnitude. Which weights survive?Show answer
Keep the two largest absolute values, which are and . The survivors are and . The weights and are set to zero. Magnitude ignores the loss, so this is the answer the rule gives, not a guarantee about accuracy.
QuestionA weight has and diagonal Hessian entry . Another has and . Compute both saliencies and say which one a saliency method removes first.Show answer
For the first, . For the second, . The method removes the first weight, because its saliency is smaller, even though it is three times larger in magnitude.
QuestionWhy is a 90% sparse weight matrix not automatically 10 times faster on a GPU?Show answer
GPUs are fast at dense matrix multiplication because they operate on contiguous blocks. Scattered zeros still occupy positions in the matrix, so a standard dense kernel multiplies by them and does the same amount of work. The speedup needs either a sparse kernel that skips zeros, which adds indexing overhead, or structured pruning that removes whole rows or channels so the remaining matrix is smaller and dense.
QuestionYou prune a model to 80% sparsity in one step and its accuracy drops from 92% to 40%. Describe a schedule that would likely do better and explain why.Show answer
Prune gradually. Remove a modest fraction, fine-tune for a while so the remaining weights readjust, then prune again, and repeat until the target sparsity is reached. Each round lets the network move into a new working state before the next removal, so the damage per step stays small. The final fine-tuning round then recovers most of the remaining accuracy.
Sources
- Han, Pool, Tran, Dally, Learning both Weights and Connections for Efficient Neural Networks (2015): https://arxiv.org/abs/1506.02626
- Han, Mao, Dally, Deep Compression (2015): https://arxiv.org/abs/1510.00149
- Frankle and Carbin, The Lottery Ticket Hypothesis (2018): https://arxiv.org/abs/1803.03635