Foundation reference

Pruning: Removing Unnecessary Weights

Pruning removes weights from a trained network, often followed by retraining. By pruning and retraining, Han et al. (2015) reduced AlexNet from 61 million to 6.7 million parameters with no loss of ImageNet accuracy.

A newer notebook covers this concept. This older page keeps its summary, math and sources.

Concept 64 of 100EfficiencyStudy phase 6
Key equation
Wpruned=W⊙M,Mij=1[∣Wij∣>θ]W_{\text{pruned}} = W \odot M, \quad M_{ij} = \mathbf{1}[|W_{ij}| > \theta]
Reading map and next steps

Study guide

Where to start

Concept 64 of 100PruningEfficiency · Study phase 6: Modern efficiency & inference
Question

Why is a weight's magnitude only a proxy for its importance, and how do second-order criteria such as Optimal Brain Surgeon use curvature to choose better (Hassibi & Stork, 1992)?

How to study this pagePredict · Check · Generalize · Continue
PredictSay what you expect.

Before you use the demo in the newer notebook, say what you expect to change.

CheckCheck against the math and the papers.

Compare what the notebook demo shows with the key equation here and with the papers cited below.

GeneralizeName what stays the same.

Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.

ContinueContinue in the newer notebook.

The newer notebook covers the same concept and has an interactive demo.

Why It Matters for Modern Models

  • Pruning removes weights from a trained network, often followed by retraining. By pruning and retraining, Han et al. (2015) reduced AlexNet from 61 million to 6.7 million parameters with no loss of ImageNet accuracy.
  • SparseGPT prunes the 175- and 176-billion-parameter OPT and BLOOM language models in one shot, without retraining, reaching 60% unstructured sparsity with a negligible increase in perplexity (Frantar & Alistarh, 2023).
  • The lottery ticket hypothesis asks whether the small network could have been trained from the start: the winning tickets Frankle & Carbin (2019) found were less than 10% to 20% of the size of the original fully connected and convolutional networks for MNIST and CIFAR-10.
  • Speed-ups depend on the pattern of zeros: removing whole neurons or heads shrinks dense matrices, while scattered zeros need sparse kernels or hardware support, such as the 2:4 pattern on NVIDIA Ampere GPUs (Mishra et al., 2021).

Questions to Think About

  • Why does removing 90% of the weights at scattered positions often give little speed-up on a GPU, while removing whole neurons, heads or 2:4 blocks does?
  • Why does pruning a little at a time, with retraining in between, usually reach higher sparsity than pruning once (Han et al., 2015), and how does SparseGPT manage without retraining?

Interactive Demo

The interactive demo for this concept is in the newer notebook.

Open the notebook demo

Core Math

If you prefer intuition first, try the demo in the newer notebook, then come back for the math.

Key Equation
Wpruned=W⊙M,Mij=1[∣Wij∣>θ]W_{\text{pruned}} = W \odot M, \quad M_{ij} = \mathbf{1}[|W_{ij}| > \theta]

Magnitude pruning removes the weights with the smallest absolute values, using a mask MM:

Wpruned=W⊙M,Mij=1[∣Wij∣>θ]W_{\text{pruned}} = W \odot M, \quad M_{ij} = \mathbf{1}\big[|W_{ij}| > \theta\big]

Structured pruning removes whole neurons, channels or attention heads, which leaves smaller dense matrices:

Wpruned=W[:,keep]W_{\text{pruned}} = W[:, \text{keep}]

Second-order criteria estimate how much the loss rises when weight qq is removed, using the Hessian HH of the loss at a trained minimum. Optimal Brain Damage uses only the diagonal of HH (LeCun, Denker & Solla, 1989):

δLq≈12 Hqq wq2\delta L_q \approx \tfrac{1}{2}\, H_{qq}\, w_q^2

When HH is positive definite, Optimal Brain Surgeon uses its inverse and also adjusts the remaining weights to compensate (Hassibi & Stork, 1992):

δLq≈wq22 [H−1]qq\delta L_q \approx \frac{w_q^2}{2\, [H^{-1}]_{qq}}

Lottery tickets. Frankle & Carbin (2019) found that a dense, randomly initialized network contains sparse subnetworks that, trained in isolation from the same initial weights W0W_0, reach test accuracy comparable to the full network in a similar number of steps:

∃ M: acc(train(W0⊙M))≈acc(train(W0))\exists\, M: \ \text{acc}\big(\text{train}(W_0 \odot M)\big) \approx \text{acc}\big(\text{train}(W_0)\big)

Key Papers

The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks

Frankle & Carbin2019ICLR
Read paper →

SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot

Frantar & Alistarh2023ICML
Read paper →

Learning both Weights and Connections for Efficient Neural Networks

Han et al.2015NeurIPS
Read paper →

Optimal Brain Damage

LeCun, Denker & Solla1989NeurIPS
Read paper →

Second order derivatives for network pruning: Optimal Brain Surgeon

Hassibi & Stork1992NeurIPS
Read paper →

Accelerating Sparse Deep Neural Networks

Mishra et al.2021arXiv
Read paper →

Connections

Where to go next

A newer notebook covers Pruning, with an interactive demo.

Continue in the newer notebook