Pruning, Sparsity & Lottery Tickets
Magnitude and second-order pruning, sparsity hardware can use, and subnetworks that train from the start.
Han and colleagues deleted 89% of AlexNet's weights without losing accuracy, provided they retrained what was left. Then why train the big network at all? Train the small one from scratch and it usually does worse. Frankle and Carbin found the catch: the small network trains well if its surviving weights start from the exact values they had at initialization. This lesson derives which weights can go, asks which zeros hardware can use, and follows the lottery ticket hypothesis from small networks to proofs about random ones.
What you’ll learn
- Derive the saliencies of Optimal Brain Damage and Optimal Brain Surgeon, including the surgeon's compensating update, and connect them to magnitude pruning, SparseGPT and Wanda.
- Describe gradual magnitude pruning, movement pruning for fine-tuning, and one-shot pruning of large language models.
- Explain which sparsity patterns hardware can exploit, with the storage and speed arithmetic of 2:4 sparsity.
- State the lottery ticket hypothesis and its refinements (rewinding, stability to SGD noise) and the strong version with its logarithmic overparameterization bound.
- Explain why pruning at initialization falls short, and why comparing pruning methods has been hard.
Which weights can go
Expand the training loss around trained weights : . At a minimum the gradient vanishes, so the cost of a change is governed by the Hessian . Removing weight means . Magnitude pruning implicitly assumes , so the cost is up to a constant; the classic second-order methods keep more of .
Let all the other weights move to compensate. Find the cheapest change that zeroes weight :
Add a Lagrange multiplier and set the gradient with respect to to zero:
The constraint fixes the multiplier, :
Substitute back. Using , the cost of removing with the best compensation is
Since for positive definite (by the Schur complement), : compensation never hurts, and it helps most when weight 's input is correlated with others. OBS prunes the weight with the smallest , applies , updates and repeats. A full Hessian has entries, which confined OBS to small networks; Quantization in Depth derives the same update with a nonzero target, the basis of GPTQ.
Two weights have local Hessian . Optimal Brain Surgeon removes . What does it do to , and what does the removal cost?
- It leaves , at a cost of
- It sets , at a cost of
- It sets , at a cost of
- It sets , at no cost
Show the answer
C. It sets , at a cost of
, so and becomes . The cost is , a quarter less than Optimal Brain Damage's ; with uncorrelated inputs ( diagonal) the two would agree.
The layer-wise version. For large language models the network's Hessian is out of reach, but each linear layer's output error is a quadratic whose Hessian is small and exact. For a row of a weight matrix and calibration inputs (one token per column), the error has , the same for every row:
- OBS on this gives SparseGPT's criterion , with updates of the remaining weights in each row (Frantar & Alistarh, 2023).
- OBD on it, , gives the saliency , whose square root is Wanda's score (Sun, Liu, Bair & Kolter, 2024): weight magnitude times input norm, with no weight update. Its input factor matters because a few input dimensions carry outlier features (Quantization in Depth), so small weights reading them are not small in effect.
Pruning during training, fine-tuning and in one shot
Gradual magnitude pruning (Zhu & Gupta, 2017) builds sparsity into training. Every steps it masks the smallest-magnitude weights, raising the sparsity from to a target over pruning steps on a cubic schedule: fast while the network is redundant, slowly as it approaches the target. Masked weights stop receiving updates.
Movement pruning (Sanh, Wolf & Rush, 2020) targets fine-tuning, where magnitude says little: fine-tuned weights stay close to their pretrained values, so the magnitude ranking is fixed before fine-tuning starts. It learns a score for every weight from the first-order signal, keeping weights that move away from zero:
| One-shot method for LLMs | Score of weight | Updates other weights? | Reported result |
|---|---|---|---|
| Magnitude | no | on OPT-175B, accuracy held only to about 10% sparsity and collapsed beyond 30% (Frantar & Alistarh, 2023) | |
| SparseGPT (Frantar & Alistarh, 2023) | , chosen adaptively in blocks | yes, OBS-style, row by row | OPT-175B and BLOOM-176B at 50–60% unstructured sparsity in under 4.5 hours, with a negligible rise in perplexity at 60%; 2:4 and 4:8 patterns too, and combinable with 4-bit quantization |
| Wanda (Sun et al., 2024) | , compared within each output row | no | competitive with SparseGPT on LLaMA models, with a score up to 300 times faster to compute |
Sparsity that hardware can use
A zero saves time only if the hardware can skip it. Three patterns, in decreasing freedom:
- Unstructured. Any weight may be zero, which gives the best accuracy at a given sparsity. But every kept value needs its position stored: with a compressed sparse row format and 8-bit values, a column index of 16 bits or more triples the storage per value (Mishra et al., 2021). Gathers from irregular positions starve the matrix units, so on GPUs speedups generally need high sparsity and specialized kernels.
- N:M. NVIDIA's sparse tensor cores accept a weight operand in which every group of 4 consecutive values has at most 2 nonzeros. They store the 2 values and a 2-bit position for each, and do half the multiply-adds, for up to twice the dense math rate; large matrix products come close to 2×. The recipe of Mishra et al. (2021) is to train densely, keep the 2 largest weights of every 4, and retrain with the original optimizer and schedule, which preserved accuracy across a wide range of vision and language networks.
- Structured. Removing whole filters with their feature maps (Li et al., 2017), attention heads (Michel, Levy & Neubig, 2019) or layers (Reading the Residual Stream) leaves a smaller dense network that is fast everywhere, at the largest accuracy cost per parameter removed.
Structured pruning has a twist. Liu et al. (2019) found that for every state-of-the-art structured pruning method they examined, training the pruned architecture from a random initialization matched or beat fine-tuning the inherited weights. If so, structured pruning mostly searches for a good small architecture, and the trained weights it keeps are not the point. For unstructured pruning, Han et al. (2015) had found the opposite: retraining from the surviving weights beat reinitializing the pruned layers. Which starting values a sparse network needs is the question behind the lottery ticket hypothesis.
The lottery ticket hypothesis
ITERATIVE-MAGNITUDE-PRUNING(rate p = 20%, rounds R, rewind step k)
initialize theta_0; train to step k, giving theta_k (k = 0 in the original paper)
m = all ones
repeat R times:
train m * theta from theta_k to the end of training, giving theta_T
set m to 0 for the p% of surviving weights with the smallest |theta_T|
return the subnetwork m * theta_k (rewound, not the trained values)Each round trains, prunes and rewinds the survivors to their early values. The control experiments keep the mask but redraw the initial values, or keep random masks of the same sparsity.
On fully connected and convolutional networks for MNIST and CIFAR-10 (LeNet and small VGG-style networks), iterative pruning found winning tickets less than 10–20% of the original size; down to that size they learned faster and reached higher test accuracy than the dense network. Randomly reinitialized, the same subnetworks trained more slowly and lost accuracy: the initial values mattered, not just the structure. For deeper networks (VGG-19, and a 20-layer ResNet that the paper calls ResNet-18) the procedure worked only with lower learning rates or learning-rate warmup.
Each round of iterative pruning removes 20% of the weights that remain. After how many rounds are fewer than 10% of the original weights left?
Show the answer
11 rounds
After rounds a fraction remains: and , so 11 rounds. Each round is a full training run, which is why finding tickets this way costs about ten times a normal training run and why cheaper ways of finding them are sought.
At scale. Frankle, Dziugaite, Roy and Carbin (2020) introduced instability analysis: train two copies from the same starting point under different SGD noise (data order, augmentation), and measure the rise in error along the straight line between the two results. A network is stable if there is no barrier, that is, if training lands in one linearly connected region whatever the noise (linear mode connectivity, studied in Mode Connectivity & Permutation Symmetry).
- Unpruned networks were unstable at initialization, except the smallest, and became stable early in training: after 3% of training for ResNet-20 on CIFAR-10, and at epoch 18 of 90 for ResNet-50 on ImageNet.
- With 30% of its weights kept and the survivors rewound to initialization, ResNet-50 reached 73.7% against the dense 76.1%, hardly better than random pruning (73.1%) or random reinitialization (73.4%).
- Rewound instead to epoch 5 (5.5% of training), the same procedure gave stable subnetworks that matched full accuracy. Across their networks, the pruned subnetworks matched full accuracy only when they were stable.
So at scale, tickets exist not at initialization but a little way into training. Related ablations by Zhou, Lan, Liu and Yosinski (2019) found that keeping only the signs of the initial weights is enough for the rewound subnetwork to train, and that some masks alone, applied to an untrained random network, give accuracy far above chance (86% on MNIST, 41% on CIFAR-10): "supermasks". In pretrained BERT, Chen et al. (2020) found matching subnetworks at 40% to 90% sparsity directly at the pretrained weights.
Tickets without training
Supermasks suggest something stronger: pruning alone, with no training at all, might find good networks. Ramanujan et al. (2020) learned a score per weight of a randomly initialized network, kept the top-scoring weights and never changed their values, and found inside a random Wide ResNet-50 a subnetwork smaller than a ResNet-34 that matched a trained ResNet-34 on ImageNet. This strong lottery ticket hypothesis has been proved.
Each target weight is simulated by a path through two random layers; the identity lets positive and negative parts travel through separate ReLU units, which is why depth doubles. The question becomes how many random weights are needed to approximate one number in .
Keeping one weight (Malach et al.'s route): a single sample lands within of with probability (for ), so with samples the chance of a miss is , and samples are needed: width polynomial in .
Keeping a subset (Pensia et al.'s route): pruning may keep several weights that feed the same output and add up. samples have subset sums, and a result of Lueker (1998) on random subset-sum problems guarantees that samples from a distribution containing suffice for every target in to lie within of some subset sum, with high probability. A union bound over all weights of all layers turns into .
The theorem is existential: finding the subset is a hard combinatorial problem in general, and nothing in it says that gradient-based score learning finds such masks.
Pruning at initialization. If tickets exist at initialization, can a cheap criterion find them before any training? SNIP (Lee, Ajanthan & Torr, 2019), GraSP (Wang, Zhang & Grosse, 2020) and SynFlow (Tanaka et al., 2020) score weights by gradient-based sensitivity at initialization. Frankle, Dziugaite, Roy and Carbin (2021) found that all of them beat random pruning but stayed below magnitude pruning after training. Worse, randomly shuffling which weights each method prunes within each layer, or redrawing the initial values, preserved or even improved their accuracy: the methods were really choosing how much to prune per layer, not which weights.
The state of the field. Blalock, Gonzalez Ortiz, Frankle and Guttag (2020) aggregated the results of 81 pruning papers and pruned hundreds of models themselves. Their clearest finding was the lack of standardized benchmarks and metrics, severe enough that it was hard to compare techniques with one another or to tell how much the field had progressed in three decades. They released ShrinkBench, an open framework for controlled comparisons, and the lesson of Benchmarking Deep Learning Fairly applies with full force.
Key takeaways
- At a trained minimum, removing weight costs without compensation (Optimal Brain Damage) and with the optimal compensating update (Optimal Brain Surgeon); magnitude pruning assumes .
- Applied to a layer's output error, with , OBS becomes SparseGPT and the diagonal approximation becomes Wanda's ; both prune the largest open language models to about half their weights in one shot.
- Only structured and N:M patterns speed up dense hardware. 2:4 sparsity stores two values and two 2-bit positions per group of four (36 bits instead of 64 at 16 bits) and doubles the peak math rate; for structured pruning, training the pruned architecture from scratch often does as well as keeping the weights.
- Iterative magnitude pruning with rewinding finds sparse subnetworks that train in isolation to full accuracy: from initialization in small networks, and from a point early in training, once the subnetwork is stable to SGD noise, in large ones. Random reinitialization and pruning at initialization do not find them.
- Strong lottery tickets exist: a random network twice as deep and only logarithmically wider contains, with high probability, a subnetwork approximating any target network without training, and logarithmic overparameterization is essentially optimal at constant depth.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What distinguishes Optimal Brain Surgeon from Optimal Brain Damage?
- OBS uses the full inverse Hessian to move the remaining weights so as to compensate, with cost ; OBD keeps only the diagonal and moves nothing, with cost
- OBS uses first derivatives, OBD second derivatives
- OBS prunes neurons, OBD prunes individual weights
- OBS always prunes the largest weights first
Show the answer
A. OBS uses the full inverse Hessian to move the remaining weights so as to compensate, with cost ; OBD keeps only the diagonal and moves nothing, with cost
Both rest on the same quadratic model of the loss at a minimum. The surgeon solves the constrained problem exactly, so its cost is never larger than OBD's, since ; the price is the inverse of a Hessian with entries.
Wanda prunes weight of a language model by the score . Why include the input norm?
- To make the score independent of the calibration data
- Because a weight reading a high-magnitude input feature affects the output far more than its size suggests, and large language models have a few such outlier features
- Because it makes the pruned weights' gradients zero
- To make the sparsity pattern 2:4
Show the answer
B. Because a weight reading a high-magnitude input feature affects the output far more than its size suggests, and large language models have a few such outlier features
The layer's output error from deleting is times input , so its size scales with : the square root of Optimal Brain Damage's saliency for the layer-wise Hessian .
For ResNet-50 on ImageNet with 30% of the weights kept, magnitude pruning with the surviving weights rewound to initialization did not find a matching subnetwork, but rewinding them to epoch 5 of 90 did. What did Frankle et al. (2020) find distinguishes the two?
- Rewinding to epoch 5 uses a larger learning rate
- The subnetwork rewound to epoch 5 has more weights
- At epoch 5 the sparse subnetwork has become stable to SGD noise: copies trained with different data orders end in the same linearly connected minimum
- At initialization the weights are too small to prune
Show the answer
C. At epoch 5 the sparse subnetwork has become stable to SGD noise: copies trained with different data orders end in the same linearly connected minimum
Instability analysis trains two copies from the same starting point with different SGD noise and measures the error barrier on the straight line between the results. Across their networks, IMP subnetworks matched full accuracy exactly when they were stable in this sense, which for large networks happens early in training, not at initialization.
Further reading
- Y. LeCun, J. S. Denker & S. A. Solla, "Optimal brain damage," Advances in Neural Information Processing Systems 2 (1990).
- B. Hassibi & D. G. Stork, "Second order derivatives for network pruning: Optimal brain surgeon," Advances in Neural Information Processing Systems 5 (1993).
- J. Frankle & M. Carbin, "The lottery ticket hypothesis: Finding sparse, trainable neural networks," ICLR (2019).
- J. Frankle, G. K. Dziugaite, D. M. Roy & M. Carbin, "Linear mode connectivity and the lottery ticket hypothesis," ICML (2020).
- T. Hoefler, D. Alistarh, T. Ben-Nun, N. Dryden & A. Peste, "Sparsity in deep learning: Pruning and growth for efficient inference and training in neural networks," Journal of Machine Learning Research 22 (2021).