Simple Algorithm
Deep Learning · Emergence · 28 min

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 w\mathbf w: δL=g⊤δw+12δw⊤Hδw+O(∥δw∥3)\delta\loss=\mathbf g^\top\delta\mathbf w+\tfrac12\delta\mathbf w^\top H\delta\mathbf w+\order{\norm{\delta\mathbf w}^3}. At a minimum the gradient g\mathbf g vanishes, so the cost of a change is governed by the Hessian HH. Removing weight qq means δwq=−wq\delta w_q=-w_q. Magnitude pruning implicitly assumes H∝IH\propto I, so the cost is wq2w_q^2 up to a constant; the classic second-order methods keep more of HH.

DerivationOptimal Brain Surgeon (Hassibi & Stork, 1993)
  1. min⁡δw 12 δw⊤H δwsubject toeq⊤δw+wq=0\min_{\delta\mathbf w}\ \tfrac12\,\delta\mathbf w^\top H\,\delta\mathbf w\qquad\text{subject to}\qquad\mathbf e_q^\top\delta\mathbf w+w_q=0

    Let all the other weights move to compensate. Find the cheapest change δw\delta\mathbf w that zeroes weight qq:

  2. L=12 δw⊤H δw+λ(eq⊤δw+wq)⟹H δw+λeq=0⟹δw=−λH−1eq\mathcal L=\tfrac12\,\delta\mathbf w^\top H\,\delta\mathbf w+\lambda\big(\mathbf e_q^\top\delta\mathbf w+w_q\big)\quad\Longrightarrow\quad H\,\delta\mathbf w+\lambda\mathbf e_q=\mathbf 0\quad\Longrightarrow\quad\delta\mathbf w=-\lambda H^{-1}\mathbf e_q

    Add a Lagrange multiplier λ\lambda and set the gradient with respect to δw\delta\mathbf w to zero:

  3. λ=wq[H−1]qq,δw=−wq[H−1]qq H−1eq\lambda=\frac{w_q}{[H^{-1}]_{qq}},\qquad\delta\mathbf w=-\frac{w_q}{[H^{-1}]_{qq}}\,H^{-1}\mathbf e_q

    The constraint fixes the multiplier, −λ[H−1]qq+wq=0-\lambda[H^{-1}]_{qq}+w_q=0:

  4. Lq=12λ2 eq⊤H−1eq=wq22 [H−1]qqL_q=\tfrac12\lambda^2\,\mathbf e_q^\top H^{-1}\mathbf e_q=\frac{w_q^2}{2\,[H^{-1}]_{qq}}

    Substitute back. Using H−1HH−1=H−1H^{-1}HH^{-1}=H^{-1}, the cost of removing wqw_q with the best compensation is

  5. Since Hqq[H−1]qq≥1H_{qq}[H^{-1}]_{qq}\ge1 for positive definite HH (by the Schur complement), Lq≤sqL_q\le s_q: compensation never hurts, and it helps most when weight qq's input is correlated with others. OBS prunes the weight with the smallest LqL_q, applies δw\delta\mathbf w, updates H−1H^{-1} and repeats. A full Hessian has N2N^2 entries, which confined OBS to small networks; Quantization in Depth derives the same update with a nonzero target, the basis of GPTQ.

Check your understanding

Two weights w=(0.2, 1.0)\mathbf w=(0.2,\ 1.0) have local Hessian H=(2112)H=\begin{pmatrix}2&1\\1&2\end{pmatrix}. Optimal Brain Surgeon removes w1w_1. What does it do to w2w_2, and what does the removal cost?

  1. It leaves w2=1.0w_2=1.0, at a cost of 12H11w12=0.04\tfrac12H_{11}w_1^2=0.04
  2. It sets w2=0.9w_2=0.9, at a cost of 0.030.03
  3. It sets w2=1.1w_2=1.1, at a cost of w12/(2[H−1]11)=0.03w_1^2/(2[H^{-1}]_{11})=0.03
  4. It sets w2=1.2w_2=1.2, at no cost
Show the answer

C. It sets w2=1.1w_2=1.1, at a cost of w12/(2[H−1]11)=0.03w_1^2/(2[H^{-1}]_{11})=0.03

H−1=13(2−1−12)H^{-1}=\tfrac13\begin{pmatrix}2&-1\\-1&2\end{pmatrix}, so δw=−0.22/3(23,−13)=(−0.2, +0.1)\delta\mathbf w=-\frac{0.2}{2/3}\big(\tfrac23,-\tfrac13\big)=(-0.2,\ +0.1) and w2w_2 becomes 1.11.1. The cost is 0.04/(4/3)=0.030.04/(4/3)=0.03, a quarter less than Optimal Brain Damage's 0.040.04; with uncorrelated inputs (HH 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 w\mathbf w of a weight matrix and calibration inputs X∈Rdin×nX\in\R^{d_{\text{in}}\times n} (one token per column), the error ∥(w−w^)⊤X∥2\norm{(\mathbf w-\hat{\mathbf w})^\top X}^2 has H=2XX⊤H=2XX^\top, the same for every row:

  • OBS on this HH gives SparseGPT's criterion wj2/[H−1]jjw_j^2/[H^{-1}]_{jj}, with updates of the remaining weights in each row (Frantar & Alistarh, 2023).
  • OBD on it, Hjj=2∥Xj,:∥2H_{jj}=2\norm{X_{j,:}}^2, gives the saliency wj2∥Xj,:∥2w_j^2\norm{X_{j,:}}^2, whose square root is Wanda's score ∣Wij∣ ∥Xj,:∥2\abs{W_{ij}}\,\norm{X_{j,:}}_2 (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 Δt\Delta t steps it masks the smallest-magnitude weights, raising the sparsity from sis_i to a target sfs_f over nn pruning steps on a cubic schedule: fast while the network is redundant, slowly as it approaches the target. Masked weights stop receiving updates.

st=sf+(si−sf)(1−t−t0n Δt)3,t∈{t0, t0+Δt, …, t0+nΔt}s_t=s_f+(s_i-s_f)\Big(1-\frac{t-t_0}{n\,\Delta t}\Big)^3,\qquad t\in\{t_0,\ t_0+\Delta t,\ \dots,\ t_0+n\Delta t\}
Across CNNs, stacked LSTMs and sequence-to-sequence models, large-sparse networks beat small-dense ones with the same number of nonzero weights, reaching up to 10 times fewer nonzeros with little loss. From their Penn Treebank language models they concluded that the best sparse model of a given size comes from pruning a dense model 5 to 10 times larger, rather than a much larger one by 20 times or more.

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:

Sij(T)=−αS∑t<T(∂L∂Wij)(t)Wij(t)S_{ij}^{(T)}=-\alpha_S\sum_{t<T}\Big(\frac{\partial\loss}{\partial W_{ij}}\Big)^{(t)}W_{ij}^{(t)}
SijS_{ij} grows when the gradient step increases ∣Wij∣\abs{W_{ij}}, a positive weight being pushed up or a negative one down. The mask keeps the top-scored weights, and the scores are trained through it with the straight-through estimator. On pretrained language models it beat magnitude pruning at high sparsity, and combined with distillation it kept accuracy with only 3% of the weights.
One-shot method for LLMsScore of weight WijW_{ij}Updates other weights?Reported result
Magnitude∣Wij∣\abs{W_{ij}}noon OPT-175B, accuracy held only to about 10% sparsity and collapsed beyond 30% (Frantar & Alistarh, 2023)
SparseGPT (Frantar & Alistarh, 2023)Wij2/[H−1]jjW_{ij}^2/[H^{-1}]_{jj}, chosen adaptively in blocksyes, OBS-style, row by rowOPT-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)∣Wij∣ ∥Xj,:∥2\abs{W_{ij}}\,\norm{X_{j,:}}_2, compared within each output rownocompetitive with SparseGPT on LLaMA models, with a score up to 300 times faster to compute
All three prune after training, with no retraining and at most a few hundred calibration sequences. SparseGPT found larger models more compressible: at a fixed sparsity they lose less accuracy relative to the dense model.

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.
2:4 storage per group of four:  2b+2⋅2 bits⟹b=16: 3664 (44% saved),b=8: 2032 (37.5% saved)\text{2:4 storage per group of four: }\ 2b+2\cdot2\ \text{bits}\quad\Longrightarrow\quad b=16:\ \tfrac{36}{64}\ (44\%\text{ saved}),\qquad b=8:\ \tfrac{20}{32}\ (37.5\%\text{ saved})
For bb-bit values. The metadata costs 12.5% of the kept values' bits at 16 bits and 25% at 8 bits, which is why the saving is less than half.

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

text
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.

Predict before you look

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 kk rounds a fraction 0.8k0.8^k remains: 0.810≈0.1070.8^{10}\approx0.107 and 0.811≈0.0860.8^{11}\approx0.086, 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.

DerivationWhy a logarithm: one sample versus a subset sum
  1. w∗x=σ(w∗x)−σ(−w∗x)w^*x=\sigma(w^*x)-\sigma(-w^*x)

    Each target weight w∗w^* is simulated by a path through two random layers; the identity a=σ(a)−σ(−a)a=\sigma(a)-\sigma(-a) 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 [−1,1][-1,1].

  2. Pr⁡[no sample within ϵ]=(1−ϵ)n≤δ⟸n≥ln⁡(1/δ)ϵ\Pr[\text{no sample within }\epsilon]=(1-\epsilon)^n\le\delta\quad\Longleftarrow\quad n\ge\frac{\ln(1/\delta)}{\epsilon}

    Keeping one weight (Malach et al.'s route): a single U[−1,1]U[-1,1] sample lands within ϵ\epsilon of w∗w^* with probability ϵ\epsilon (for ∣w∗∣≤1−ϵ\abs{w^*}\le1-\epsilon), so with nn samples the chance of a miss is (1−ϵ)n≤e−ϵn(1-\epsilon)^n\le e^{-\epsilon n}, and n≈ln⁡(1/δ)/ϵn\approx\ln(1/\delta)/\epsilon samples are needed: width polynomial in 1/ϵ1/\epsilon.

  3. n=O(log⁡(1/ϵ)) ⟹ ∀w∗∈[−1,1]  ∃S⊆[n]: ∣w∗−∑i∈SXi∣≤ϵn=\order{\log(1/\epsilon)}\ \Longrightarrow\ \forall w^*\in[-1,1]\ \ \exists S\subseteq[n]:\ \Big\lvert w^*-\sum_{i\in S}X_i\Big\rvert\le\epsilon

    Keeping a subset (Pensia et al.'s route): pruning may keep several weights that feed the same output and add up. nn samples have 2n2^n subset sums, and a result of Lueker (1998) on random subset-sum problems guarantees that O(log⁡(1/ϵ))\order{\log(1/\epsilon)} samples from a distribution containing U[−1,1]U[-1,1] suffice for every target in [−1,1][-1,1] to lie within ϵ\epsilon of some subset sum, with high probability. A union bound over all weights of all layers turns log⁡(1/ϵ)\log(1/\epsilon) into log⁡(dl/min⁡{ϵ,δ})\log(dl/\min\{\epsilon,\delta\}).

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 qq costs 12Hqqwq2\tfrac12H_{qq}w_q^2 without compensation (Optimal Brain Damage) and wq2/(2[H−1]qq)w_q^2/(2[H^{-1}]_{qq}) with the optimal compensating update δw=−wq[H−1]qqH−1eq\delta\mathbf w=-\frac{w_q}{[H^{-1}]_{qq}}H^{-1}\mathbf e_q (Optimal Brain Surgeon); magnitude pruning assumes H∝IH\propto I.
  • Applied to a layer's output error, with H=2XX⊤H=2XX^\top, OBS becomes SparseGPT and the diagonal approximation becomes Wanda's ∣Wij∣∥Xj,:∥\abs{W_{ij}}\norm{X_{j,:}}; 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.

Question 1

What distinguishes Optimal Brain Surgeon from Optimal Brain Damage?

  1. OBS uses the full inverse Hessian to move the remaining weights so as to compensate, with cost wq2/(2[H−1]qq)w_q^2/(2[H^{-1}]_{qq}); OBD keeps only the diagonal and moves nothing, with cost 12Hqqwq2\tfrac12H_{qq}w_q^2
  2. OBS uses first derivatives, OBD second derivatives
  3. OBS prunes neurons, OBD prunes individual weights
  4. 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 wq2/(2[H−1]qq)w_q^2/(2[H^{-1}]_{qq}); OBD keeps only the diagonal and moves nothing, with cost 12Hqqwq2\tfrac12H_{qq}w_q^2

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 Hqq[H−1]qq≥1H_{qq}[H^{-1}]_{qq}\ge1; the price is the inverse of a Hessian with N2N^2 entries.

Question 2

Wanda prunes weight WijW_{ij} of a language model by the score ∣Wij∣⋅∥Xj,:∥2\abs{W_{ij}}\cdot\norm{X_{j,:}}_2. Why include the input norm?

  1. To make the score independent of the calibration data
  2. 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
  3. Because it makes the pruned weights' gradients zero
  4. 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 WijW_{ij} is WijW_{ij} times input jj, so its size scales with ∣Wij∣ ∥Xj,:∥\abs{W_{ij}}\,\norm{X_{j,:}}: the square root of Optimal Brain Damage's saliency for the layer-wise Hessian 2XX⊤2XX^\top.

Question 3

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?

  1. Rewinding to epoch 5 uses a larger learning rate
  2. The subnetwork rewound to epoch 5 has more weights
  3. 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
  4. 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).