Foundations to Frontier
Tests
E. Deep Learning › E19 Continual, Multi-Task and Transfer Learning

Pruning: Magnitude, Structured and the Lottery Ticket Hypothesis

Pruning removes weights or whole units from a trained network to make it smaller and faster. Unstructured magnitude pruning deletes the smallest individual weights, giving sparse matrices. Structured pruning removes entire neurons, channels or heads, so ordinary dense hardware speeds up. The lottery ticket hypothesis (Frankle and Carbin, 2019) claims dense networks contain sparse subnetworks that train well from their original initialisation. This page covers pruning criteria, one-shot versus iterative pruning, fine-tuning, structured pruning and the lottery-ticket debate. In the exercises you build magnitude masks and neuron scores, then prune a 20 → 128 → 3 network (dense accuracy 0.814). At 90% sparsity, magnitude pruning kept 0.625 against 0.395 for random pruning, and 100 fine-tuning steps restored 0.748. Keeping 32 of 128 neurons matched the dense network (0.813). A lottery ticket at 90% did not beat a random re-initialisation of the same mask (0.757 against 0.773): a null result in all three seeds.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Cutting the weights a network doesn’t need

Trained networks have many weights close to zero that barely affect the output. Pruning deletes them, like trimming a bush. You can delete individual weights (fine-grained, but needs special sparse hardware to run faster) or whole neurons (coarser, but the network simply becomes smaller). After pruning, a short retraining usually recovers most of the lost accuracy. The demo shows how little of the total weight magnitude the smallest weights carry.

Transfer and efficiency lab
Keeping the largest 100 of 200 weights retains 78% of Σ|w| and 92% of Σw². Small weights carry little, which is why magnitude pruning works.
Why engineers care

Pruned networks need less memory, energy and time, which matters on embedded processors in drones, satellites and automotive ECUs, and for serving large models cheaply.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Magnitude pruning removes…
  2. 2. Removing whole neurons is called…
  3. 3. After pruning, accuracy is usually recovered by…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Unstructured magnitude pruning: remove the weights with the smallest |w|, per layer or with one global threshold. Sparsity s leaves (1 − s)·n weights (2944 at 90% → 294).
  • Criteria beyond magnitude:
    • Optimal Brain Damage and Optimal Brain Surgeon use second-order saliency ½ H_ii w_i²;
    • movement pruning (for fine-tuning) removes weights moving towards zero;
    • SNIP prunes at initialisation by gradient sensitivity.
  • Iterative pruning: prune a fraction p of the remaining weights per round and retrain. After k rounds the sparsity is 1 − (1 − p)^k; ten rounds of 20% give 89%.
  • Structured pruning: remove neurons, channels or heads by norms or importance scores. Both adjacent matrices shrink, so FLOPs fall proportionally on dense hardware (32 of 128 neurons saves 75%).
  • Storage: CSR uses nnz·(value + index) + (rows + 1)·index bytes. It only beats dense storage at high sparsity.
  • Lottery tickets: train, prune, rewind the surviving weights to their initial (or early-training) values, and retrain. A “winning ticket” is a subnetwork that matches the dense accuracy.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Ten rounds of 20% iterative pruning give sparsity:
  2. 2. Structured pruning speeds up…
  3. 3. Lottery tickets rewind surviving weights to…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Pruning in code

Exercise 1.

  • Build a magnitude mask.
  • Score neurons for structured pruning.
  • Measure sparsity.

Practice.

  • torch.nn.utils.prune supports per-layer and global magnitude, random and structured pruning. Tools such as Torch-Pruning, the Intel Neural Compressor and NVIDIA’s ASP (2:4 sparsity) provide structured and hardware-aware pruning.
  • Prune per layer, or normalise before a global threshold, because layers have different weight scales.
  • Fine-tune after pruning, and use gradual schedules for high sparsity.
  • Real speed-ups need structured or hardware-supported (2:4) sparsity; measure latency, not just parameter count.
import torch.nn.utils.prune as prune
for m in model.modules():
    if isinstance(m, nn.Linear): prune.l1_unstructured(m, name="weight", amount=0.9)   # per layer
prune.ln_structured(model.fc1, name="weight", amount=0.75, n=2, dim=0)                 # remove 75% of neurons
🐍 Exercise 1: masks, neuron scores and sparsity
Build a magnitude mask, score neurons by weight norms and measure sparsity.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A global threshold across layers risks…
  2. 2. NVIDIA's hardware-supported sparsity pattern:
  3. 3. Speed-ups should be checked by…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why magnitude works. For a trained network near a minimum, removing weight w_i raises the loss by about ½ H_ii w_i² (Optimal Brain Damage). If curvatures are similar, the smallest weights cost least. Overparameterised networks have many redundant directions, so much can be removed.

Fine-tuning and iterative pruning. One-shot pruning moves the network off its minimum. Retraining lets the remaining weights compensate. Iterative pruning takes smaller steps and reaches higher sparsity at equal accuracy.

The lottery-ticket debate. Frankle and Carbin found winning tickets in small networks with iterative pruning and rewinding to initialisation. Later work needed rewinding to early training for large networks. Liu et al. found that for structured pruning, training the pruned architecture from scratch is often as good, so the architecture, not the inherited weights, can be what matters. Results depend on scale, learning rate and pruning schedule.

📝 Quick check (Level 3)
0/3 answered
  1. 1. OBD's saliency of weight i:
  2. 2. Large networks need rewinding to…
  3. 3. Liu et al. found pruned architectures trained from scratch are…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How much can be pruned, and does the lottery ticket hold at small scale?

History.

  • Y. LeCun, J. Denker and S. Solla, “Optimal brain damage” (NeurIPS 1989).
  • S. Han, J. Pool, J. Tran and W. Dally, “Learning both weights and connections” (NeurIPS 2015).
  • J. Frankle and M. Carbin, “The lottery ticket hypothesis” (ICLR 2019).
  • Z. Liu et al., “Rethinking the value of network pruning” (ICLR 2019).

Exercise 2.

  • Task: 3-class classification from tanh features of x ∈ ℝ²⁰, with 600 training examples.
  • Network: a 20 → 128 → 3 ReLU network (2944 weights), Adam for 300 steps. Dense test accuracy 0.814.
  • Comparisons:
    • one-shot layer-wise magnitude pruning against random pruning;
    • 100 fine-tuning steps after pruning;
    • structured pruning (keep 32 neurons) against unstructured pruning at the same 75% sparsity;
    • a lottery ticket at 90% (mask from the trained network, weights rewound to initialisation, retrained 300 steps) against a random re-initialisation with the same mask.
sparsity magnitude (one-shot) random (one-shot)
50% 0.806 0.711
80% 0.698 0.503
90% 0.625 0.395
95% 0.529 0.316
98% 0.537 0.326
after pruning accuracy
90% + 100 fine-tuning steps 0.748
98% + 100 fine-tuning steps 0.603
structured: 32 of 128 neurons, fine-tuned 0.813
unstructured 75%, fine-tuned 0.809
lottery ticket 90% (rewound) 0.757
same mask, random re-initialisation 0.773
  • Magnitude beats random: at 90% sparsity, 0.625 against 0.395. Half the weights cost almost nothing (0.806 against 0.814).
  • Fine-tuning recovers a lot: 0.625 → 0.748 at 90%.
  • Structured pruning loses nothing here: this task needs few features, so a 32-neuron network is enough and runs 4× faster on dense hardware.
  • Lottery ticket: null result. Rewinding the winning mask to its original initialisation gave no advantage over random re-initialisation.
seed lottery ticket random re-initialisation
0 0.757 0.773
1 0.798 0.802
2 0.777 0.779

This agrees with reports that one-shot tickets in small, easy settings carry no special initialisation; Frankle and Carbin used iterative pruning.

  • A mistake I made first: with a single global magnitude threshold, the output layer (weights √(20/128) ≈ 0.4× smaller at initialisation) was deleted entirely at 80% sparsity, and the network collapsed to one class. Per-layer pruning fixed it.
  • Seeds: one-shot magnitude beat random at 50–95% in every seed, but at 98% seed 2 gave magnitude 0.297 against random 0.399.
🐍 Exercise 2 (research): how much can be pruned, and does the lottery ticket hold at small scale?
Prune a trained MLP by magnitude and at random, fine-tune, compare structured and unstructured pruning, and test a lottery ticket against random re-initialisation.

Pruning in AI, robotics and aerospace

  • Embedded vision: channel-pruned CNNs on drone and automotive processors.
  • Language models: structured and 2:4-sparse LLMs (SparseGPT, Wanda) for cheaper serving.
  • Space hardware: smaller networks fit radiation-tolerant FPGAs with limited resources.
  • Design lesson: prune per layer, fine-tune, prefer structured pruning when you need real speed, and measure latency.

References

  1. Y. LeCun, J. S. Denker and S. A. Solla (1989). “Optimal brain damage.” NeurIPS.
  2. S. Han, J. Pool, J. Tran and W. Dally (2015). “Learning both weights and connections for efficient neural networks.” NeurIPS.
  3. J. Frankle and M. Carbin (2019). “The lottery ticket hypothesis: finding sparse, trainable neural networks.” Proc. ICLR.
  4. Z. Liu, M. Sun, T. Zhou, G. Huang and T. Darrell (2019). “Rethinking the value of network pruning.” Proc. ICLR.