COE 592Lecture 4.1Full guide
Pruning and sparsity I
The whole lecture on one page, taught concept by concept. Work through the parts in order, mark each concept once you understand it, and open the slide chips when you want the original slides.
- Parts
- 6
- Concepts
- 29
- Slides
- 43
- Reading
- 174 min
Part 01: Why prune: energy, definition and formulation
Memory access dominates the energy bill of deep learning, so fewer weights means less data movement; pruning removes synapses and neurons and is posed as minimizing loss under an L0 budget, echoing synaptic pruning in the human brain.
5 concepts, slides 1-6
Why this part matters
Every model you want on an embedded board is limited first by how many weights must be moved, not by how many multiplies the chip can do. One number from this part, 640 pJ for a DRAM access against 3.1 pJ for an integer multiply, justifies the pruning, quantization and sparse-hardware lectures that follow.
This part gives you three tools. A roadmap of the pruning pipeline, which doubles as the checklist for any pruning experiment in your research. The energy argument, which is the answer to the exam question "why is memory rather than arithmetic the bottleneck?". And the formulation of pruning as constrained optimization, which is the standard way to write down what pruning optimizes and why it cannot be solved by gradient descent alone. The part closes with the biological curve that inspired the whole idea.
By the end you can
- Name the four decisions of the pruning pipeline and say which ones this lecture covers.
- Reproduce the 45 nm energy ladder and argue with numbers why DRAM traffic, not arithmetic, dominates.
- Distinguish synapse pruning from neuron pruning and state what each does to a layer's weight matrix.
- Write the pruning formulation with a less-or-equal budget, name every symbol, and explain why the L0 constraint forces heuristic criteria.
- Describe the brain's overprovision-then-prune curve and use it as motivation, not as proof, for network pruning.
Suppose you have a trained object detector that is accurate on your validation set but will not fit on the board you are targeting. Before you touch a single weight, four questions need answers, and the outline slide of this lecture is exactly that checklist. It reappears on slides 14 and 26 as a progress marker, so treat it as the map you return to as each section closes.
Pruning makes a network smaller by removing the synapses and neurons whose removal hurts performance least. That one sentence hides a sequence of design decisions. First you must formulate the problem: what exactly is being minimized, and under what budget. Then you choose the granularity, the pattern in which weights are removed, from single scattered weights up to whole channels. Then a criterion, the rule that scores which synapses or neurons are least important. Then a ratio, the target sparsity for each layer. Finally you fine-tune or retrain the pruned network so the accuracy you lost comes back.
Loss under an L0 budget
What pattern to remove
Which synapses or neurons
Sparsity per layer
Recover the accuracy
| Decision | Question the slide asks | Where it is taught |
|---|---|---|
| Formulate | What is pruning? How should we formulate pruning? | This part |
| Granularity | In what pattern should we prune the neural network? | Parts 03 and 04 |
| Criterion | What synapses or neurons should we prune? | Parts 05 and 06 |
| Ratio | What should target sparsity be for each layer? | Lecture 04-2 |
| Fine-tune or train | How should we improve performance of pruned models? | Part 02 previews it; Lecture 04-2 |
This lecture, Pruning and Sparsity I, covers the formulation, the granularity and the criteria. The ratio and the fine-tuning belong to Pruning and Sparsity II, the next lecture. The split mirrors the two pruning lectures of the MIT course the deck is built on, and it explains why the outline slide is highlighted only at the top: the yellow marker moves down as the lecture proceeds.
Recall
What are the four decisions that follow the formulation of pruning, and which of them belong to Lecture 04-2?
Take one weight of a fully connected layer. It is fetched from off-chip DRAM and multiplied by an activation. The fetch costs 640 pJ. The 32-bit integer multiply costs 3.1 pJ. Divide them: 640 / 3.1 ≈ 206. Fetching the weight costs as much energy as about two hundred multiplies. That single ratio is the reason this lecture exists.
The numbers come from Mark Horowitz's ISSCC 2014 keynote, measured for a 45 nm process at 0.9 V, and reproduced in Han et al. (2015), which the slide follows. The full ladder is worth knowing by heart, because it is the quantitative case for every compression technique in this course. Read it top to bottom as an ordering of operations by cost, and notice that the four arithmetic rows and the register file all sit below 4 pJ while the two memory rows, SRAM and DRAM, close the table at 5 pJ and 640 pJ.
| Operation | Energy | Relative to int ADD |
|---|---|---|
| 32-bit int ADD | 0.1 pJ | 1x |
| 32-bit float ADD | 0.9 pJ | 9x |
| 32-bit register file | 1 pJ | 10x |
| 32-bit int MULT | 3.1 pJ | 31x |
| 32-bit float MULT | 3.7 pJ | 37x |
| 32-bit SRAM cache | 5 pJ | 50x |
| 32-bit DRAM memory | 640 pJ | 6400x |
Han et al. summarize the ladder in one sentence: memory access is three orders of magnitude more energy expensive than simple arithmetic. Sze et al. make the same point in their survey: DRAM accesses require up to several orders of magnitude more energy than computation, and DRAM consumes two orders of magnitude more energy per access than a small on-chip memory of a few kilobytes. Measured against the rows of the ladder, one DRAM access costs as much as each of the following.
One 640 pJ DRAM access costs as much as one...
- One 32-bit int ADD
- 6400x
- One register file read
- 640x
- One SRAM cache read
- 128x
- One 32-bit int MULT
- 206x
The slide's icon line, one DRAM stick equals 200 ×+, rounds the chart's arrow: that arrow runs from the DRAM bar to the 32-bit int MULT bar, so the 200 is 640 / 3.1 ≈ 206 rounded down. Pricing one MAC instead (3.1 + 0.1 = 3.2 pJ) gives 640 / 3.2 = 200. Either way the answer is about two hundred.
The chain from weights to watts
The slide states the consequence as a chain: data movement, more memory references, more energy. Every weight that does not fit on chip is a DRAM reference on every inference. A network with more weights moves more bytes, more bytes mean more DRAM references, and each reference costs 640 pJ. The compute, the MACs that the earlier lectures counted so carefully, turns out to be the cheap part. This is the memory access energy problem, and pruning attacks it at the root by reducing the number of weights that have to move at all.
Worked example
A billion connections at 20 frames per second (Han et al. 2015)
Count the fetches
A network with 1,000,000,000 connections run at 20 Hz fetches every weight twenty times a second: 2 × 10^10 DRAM references per second.Price each fetch
2 × 10^10 × 640 pJ = 12.8 J every second, so 12.8 W.Result
12.8 W for DRAM traffic alone, before a single multiply is counted. Han et al. call this well beyond the power envelope of a typical mobile device.
Worked example
One layer of a million fp32 weights, before and after 90 percent pruning
Dense: memory
10^6 weights fetched once each from DRAM: 10^6 × 640 pJ = 640 µJ.Dense: arithmetic
One float multiply and one float add per weight: 10^6 × (3.7 + 0.9) pJ = 4.6 µJ.Dense: share
640 / 644.6 ≈ 0.993. Memory is 99.3% of the layer's energy, and the ratio of memory to arithmetic is 640 / 4.6 ≈ 139.Pruned: keep 100,000 weights
Fetch 10^5 × 640 pJ = 64 µJ, compute 10^5 × 4.6 pJ = 0.46 µJ.Result
Total drops from 644.6 µJ to 64.46 µJ, about 10x, ignoring the index overhead of a sparse format, which Part 03 reintroduces.
| Quantity | Dense, 10^6 weights | Pruned, 10^5 weights |
|---|---|---|
| DRAM fetch energy | 640 µJ | 64 µJ |
| MAC energy | 4.6 µJ | 0.46 µJ |
| Total per inference | 644.6 µJ | 64.46 µJ |
| Share from memory | 99.3% | 99.3% |
There is a second payoff hiding in the ladder. Once a pruned model is small enough, its weights stop living in DRAM at all and sit in on-chip SRAM, where an access costs 5 pJ instead of 640 pJ. That is the argument of Deep Compression: pruning plus quantization shrinks both networks to a few megabytes, small enough to fit in on-chip SRAM cache rather than off-chip DRAM.
| Model | Before | After | Ratio |
|---|---|---|---|
| AlexNet | 240 MB | 6.9 MB | 35x |
| VGG-16 | 552 MB | 11.3 MB | 49x |
Separately, benchmarking the pruned fully connected layers on CPU, GPU and mobile GPU measured 3x to 7x less energy per layer. Fewer weights is the first win; crossing the SRAM boundary is the second.
Figures are the slide's 45 nm, 0.9 V numbers from 2014 and ignore activation traffic and the index overhead of storing a sparse matrix. The 1 B at 20 Hz preset reproduces Han et al.'s memory-only estimate of 12.8 W (the total adds 0.09 W of MACs).
Quick check
Using the slide's 45 nm figures, about how many 32-bit integer multiplies cost the same energy as one 32-bit DRAM access?
Quick check
According to slide 3, what is the primary motivation for pruning a network?
Recall
One DRAM access versus one 32-bit integer multiply in 45 nm: give the two energies and the ratio. What is the ratio against an integer add?
The slide's before-and-after picture, taken from Han et al. (2015), is a small fully connected network with layers of 5, 4, 3 and 2 nodes. Count the edges: 5 × 4 + 4 × 3 + 3 × 2 = 20 + 12 + 6 = 38 synapses and 14 neurons. After pruning the layers read 5, 3, 2, 2. One hidden neuron is gone from the second layer, one from the third, and most of the remaining edges have vanished. Two different things were removed, and the slide labels them with two different arrows.
A synapse is one weight w_ij, one edge between neuron j of one layer and neuron i of the next. Synapse pruning sets that single entry to zero, and the neurons at both ends survive with one fewer connection. A neuron is a node. Neuron pruning removes the node and therefore every edge incident to it at once: all of its incoming weights and all of its outgoing weights. Nothing about the neuron remains, so nothing that fed it or read from it needs to exist either.
The matrix view makes the difference concrete. A linear layer holds its weights in a matrix W of shape [out, in], one row per output neuron and one column per input neuron. Synapse pruning zeroes scattered entries of that matrix, and the matrix keeps its shape; the result is a sparse matrix that must be stored with indices to say where the survivors are. Neuron pruning deletes a whole row of this layer's W(the neuron's inputs) and the matching column of the next layer's W (its outputs); both matrices become smaller dense matrices with no bookkeeping at all. This is the seed of the granularity spectrum in Part 03: fine-grained pruning lives at the synapse end and coarse-grained pruning at the neuron end.
Worked example
Same number of weights removed, two different results
The setup
Layer one has 4 inputs and 3 outputs, so W_1 is 3 × 4 = 12 weights. Layer two takes those 3 outputs to 2, so W_2 is 2 × 3 = 6 weights.Option A: prune 6 synapses
Zero six entries of W_1. It still has 3 rows and 4 columns, with six zeros scattered inside. Every neuron still exists.Option B: prune neuron 2 of layer one
Delete row 2 of W_1 (4 weights) and column 2 of W_2 (2 weights): 4 + 2 = 6 weights gone.Result
Both options remove six weights. Option A leaves a sparse 3 × 4 matrix. Option B leaves dense 2 × 4 and 2 × 2 matrices that any hardware multiplies at full speed.
| Choice | Weights removed | Shapes after | Sparse or dense |
|---|---|---|---|
| Prune 6 synapses | 6 | 3 × 4 and 2 × 3, unchanged | Sparse: 6 zeros scattered inside a 3 × 4 matrix |
| Prune neuron 2 | 4 + 2 = 6 | 2 × 4 and 2 × 2 | Dense: both matrices simply got smaller |
Han et al. describe the effect of synapse pruning on a layer in one line: this pruning converts a dense, fully-connected layer to a sparse layer. They also stress that retraining the surviving weights is critical, because zeroing connections drops accuracy immediately. Part 02 shows that curve and how fine-tuning recovers it.
- Synapse pruning: unit is one weight, neurons survive, the matrix keeps its shape but becomes sparse.
- Neuron pruning: unit is one node, all incident weights go, a row and a column disappear, matrices stay dense.
- Both reduce the number of weights that must be fetched; only the second reduces it in a shape hardware likes.
Quick check
Which statement about pruning one hidden neuron is correct?
Recall
A 3 × 4 linear layer feeds a 2 × 3 layer. You prune neuron 2 of the first layer. How many weights vanish, and what shapes remain?
Start with a weight vector small enough to see whole: W = [0.8, -0.05, 0.3, -0.01]. It has four nonzero entries. Give yourself a budget of two. One candidate is W_P = [0.8, 0, 0.3, 0], which has exactly two nonzeros. Is it the best candidate? That depends on the training loss it produces, and the pruning formulation on the slide is precisely the question: among all weight vectors with at most two nonzeros, which one makes the loss smallest?
The left half of the slide figure is ordinary training: pick W to minimize L, with the whole dense network available. The right half adds one line. The search variable becomes W_P, the pruned weights, and a constraint limits how many of its entries may be nonzero. Everything else, the loss, the data, the architecture, is unchanged. Pruning is training with a budget.
Every symbol in the formulation
- L
- The training objective (the loss), unchanged from ordinary training
- x
- The input data the loss is evaluated on
- W
- The original dense weights the network was trained with
- W_P
- The pruned weights, the thing we search over
- ||W_P||_0
- The count of nonzero entries in W_P, the L0 pseudo-norm
- N
- The target number of nonzeros, the budget the pruned model must respect
Why the constraint needs heuristics
The L0 norm counts nonzeros, and despite its name it is not a norm at all. A norm must scale with its argument, so that doubling the vector doubles the norm. Doubling our example gives ||2W||_0 = 4 = ||W||_0, not 8. Worse, as a function of the weights it is piecewise constant: nudge any nonzero weight and the count does not change, so the gradient is zero almost everywhere and undefined exactly at zero. Louizos, Welling and Kingma state it plainly: the L0 norm of weights is non-differentiable, so it cannot be incorporated directly as a regularization term. Gradient descent, the only tool that scales to millions of weights, gets no signal from the constraint.
The constraint is also combinatorial. Choosing which N of the |W| entries survive is a subset selection. With 16 weights and a budget of 8 there are C(16, 8) = 12,870 masks to compare, each requiring a retrained loss to evaluate. With a million weights and a budget of a hundred thousand the count is astronomically large. Exact search is out of the question.
So the field replaces the exact problem by the pipeline of the first concept. A criterion assigns each weight or neuron an importance score, such as its magnitude |w|, and the least important are zeroed; that is a greedy stand-in for the search over masks. A ratio fixes N for each layer; that is the budget. Fine-tuning then re-minimizes L over the surviving entries, which is the only part gradient descent can do. The formulation is exact; everything after it is an approximation, and the quality of the approximation is what the rest of this lecture and the next are about.
From N to sparsity
Worked example
AlexNet under Han et al. (2015)
Count
AlexNet has |W| = 61 M parameters. Han et al. prune it to N = 6.7 M.Sparsity
1 - 6.7 / 61 = 1 - 0.11 = 0.89, so 89% of the weights are zero.Result
89% sparsity, a pruning ratio of 89%, and 61 / 6.7 ≈ 9x fewer parameters, with no loss of accuracy after retraining.
In the tiny example, keeping 2 of 4 entries is 50% sparsity; the mask visual above keeps 8 of 24, which is 67%. The glossary defines the pruning ratio as the percentage of parameters pruned away, and when every zero comes from pruning the two quantities coincide.
Quick check
In argmin over W_P of L(x; W_P) subject to ||W_P||_0 <= N, what does N stand for?
Recall
Why can gradient descent not handle the L0 constraint directly, and what replaces it in practice?
Recall
Write the pruning formulation and name each symbol.
A newborn's cortical neuron carries about 2,500 synapses. By the age of two to four the figure is near 15,000. An adult settles around 7,000. The brain grows to six times its newborn connection count, then removes more than half of that peak. Growth to a peak, then elimination: the curve on the slide is the shape of train-dense-then-prune, drawn by biology decades before anyone pruned a neural network.
The three numbers on the slide
- Newborn
- about 2,500 synapses per neuron
- 2 to 4 years
- peak, about 15,000 synapses per neuron
- Adult
- about 7,000 synapses per neuron
Worked example
How much the brain overprovisions and removes
Growth
15,000 / 2,500 = 6x more synapses per neuron at the peak than at birth.Elimination
(15,000 - 7,000) / 15,000 = 8,000 / 15,000 ≈ 0.53, so about 53% of the peak is pruned away.Result
Adults keep roughly 47% of their peak synapses. Using the slide's illustrative figures, in the vocabulary of the previous concept the brain runs at about 53% sparsity relative to its own dense peak.
This is synaptic pruning, and Han et al. invoke it in the introduction of the paper the slide follows: their method learns the network connectivity in addition to the weights, much as in the mammalian brain, where synapses are created in the first few months of a child's development, followed by gradual pruning of little-used connections, falling to typical adult values. The parallel to the pipeline is exact in shape. Overprovision (train a large dense network), score by use (the criterion), remove the weak connections (prune), and let the remaining ones strengthen (fine-tune).
Quick check
Using slide 6's figures, roughly what fraction of the peak synapses per neuron is eliminated by adulthood?
Recall
Give the synapses per neuron at birth, at the peak and in adulthood from slide 6, and the fraction eliminated between peak and adult.
Recap
If you remember nothing else
- Pruning is a pipeline: formulate, choose granularity, choose criterion, choose ratio, fine-tune. This lecture covers the first three, Lecture 04-2 the last two.
- In 45 nm at 0.9 V a 32-bit DRAM access costs 640 pJ against 3.1 pJ for an int multiply and 0.1 pJ for an int add: about 200x and 6400x.
- Data movement drives memory references, memory references drive energy, so fewer weights means fewer fetches and, once the model fits SRAM, 128x cheaper accesses.
- A 1-billion-connection network at 20 Hz spends 12.8 W on DRAM fetches alone.
- Synapse pruning zeroes single weights and leaves neurons in place; neuron pruning deletes a node with all incident edges, a row here and a column in the next layer.
- Pruning is argmin over W_P of L(x; W_P) subject to ||W_P||_0 <= N; the slide bullet's strict less-than is a typo inherited from the MIT deck.
- ||.||_0 counts nonzeros, is not a true norm and has no useful gradient, so practical pruning uses importance criteria and per-layer ratios.
- Sparsity equals 1 - N/|W|; AlexNet at 61 M to 6.7 M parameters is 89 percent sparsity, 9x fewer weights.
- The brain grows from about 2,500 to 15,000 synapses per neuron and prunes to about 7,000: overprovision, then remove the little-used.
Sources
- Learning both Weights and Connections for Efficient Neural NetworksPaperNeurIPS 2015, Han, Pool, Tran and DallyEnergy table (0.1 to 640 pJ, relative 1 to 6400), the 12.8 W example, Figure 3 synapses and neurons, 9x AlexNet, the brain analogy.(opens in a new tab)
- 1.1 Computing's energy problem (and what we can do about it)PaperIEEE ISSCC 2014, M. HorowitzOrigin of the 45 nm, 0.9 V energy per operation figures.(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 3: Pruning and Sparsity Part IDocsMIT HAN Lab, Song HanUpstream deck with the same outline, the same strict-inequality typo and the same brain slide.(opens in a new tab)
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperICLR 2016, Han, Mao and DallyAlexNet 240 MB to 6.9 MB, VGG-16 552 MB to 11.3 MB, fitting in on-chip SRAM; 3x to 7x less energy per pruned FC layer on CPU, GPU and mobile GPU.(opens in a new tab)
- Efficient Processing of Deep Neural Networks: A Tutorial and SurveyPaperProceedings of the IEEE 2017, Sze, Chen, Yang and EmerDRAM accesses cost several orders of magnitude more energy than computation; two orders more than small on-chip memory.(opens in a new tab)
- Learning Sparse Neural Networks through L0 RegularizationPaperICLR 2018, Louizos, Welling and KingmaThe L0 norm of weights is non-differentiable and cannot be used directly as a regularizer.(opens in a new tab)
- What is the State of Neural Network Pruning?PaperMLSys 2020, Blalock, Gonzalez Ortiz, Frankle and GuttagSurvey of 81 pruning papers; lack of standardized benchmarks across pruning choices.(opens in a new tab)
- Synaptic density in human frontal cortex: developmental changes and effects of agingPaperBrain Research 163, 1979, P. R. HuttenlocherPeak at one to two years about 50 percent above the adult mean; decline from two to sixteen years.(opens in a new tab)
- Regional differences in synaptogenesis in human cerebral cortexPaperJournal of Comparative Neurology 387, 1997, Huttenlocher and DabholkarPrefrontal peak after fifteen months; elimination into mid-adolescence.(opens in a new tab)
- Do we have brain to spare?PaperNeurology 64(12), 2005, D. A. DrachmanAbout 20 billion neocortical neurons averaging 7,000 synapses each; the slide's 2004 is the page number.(opens in a new tab)
- Peter Huttenlocher (1931 to 2013)ArticleNature 502, 2013, C. A. WalshObituary cited on slide 6; synapse formation and pruning in child development.(opens in a new tab)
Part 02: Train, prune, fine-tune: what pruning achieves
The Han et al. pipeline of training connectivity, pruning and retraining, how iterative pruning pushes the pruning ratio past 90 percent without accuracy loss, the resulting parameter and MAC reductions, and hardware support for sparsity.
6 concepts, slides 7-13
Why this part matters
Part 01 ended with the reason to prune: a 32-bit DRAM access costs about 640 pJ, roughly 200 times a multiply, so a model that fits in on-chip memory wins on energy before it wins on anything else. This part is where the lecture proves that pruning actually delivers: AlexNet loses 9x of its parameters and VGG-16 loses 12x with no accuracy loss at all.
The proof comes as one chart built up over four slides, a five-row reduction table, a set of image captions and a slide of hardware. Along the way it exposes the two traps that catch most first attempts: pruning without retraining, which throws away several percent of accuracy for nothing, and assuming that fewer parameters means faster inference, which is only true when the hardware knows how to skip zeros. The pipeline chart and the reduction table are classic exam material, and the hardware slide is the bridge to the granularity discussion in Part 03.
By the end you can
- Explain the train, prune, retrain pipeline and why retraining is the step the paper calls critical.
- Read accuracy loss and reduction factor off the pruning-ratio chart for one-shot, retrained and iterative pruning.
- Explain from layer tables why parameter reduction and MAC reduction differ across AlexNet, VGG-16, GoogleNet, ResNet-50 and SqueezeNet.
- State what hardware needs, a 2:4 pattern or a sparse engine, before sparsity turns into speed.
Take AlexNet as Han, Pool, Tran and Dally trained it for their NeurIPS 2015 paper: 57.2% top-1 and 80.3% top-5 on ImageNet. Its first fully connected layer alone holds 38 million weights, and if you histogram them you get a narrow bell centered on zero, almost all of it inside [-0.015, 0.015] by the paper's own account. Now pick a threshold that removes the smallest half of every layer. Nothing happens to accuracy. Remove three quarters, and top-5 accuracy falls by about 2.2%. Remove four fifths, and it falls by about 4%. That single experiment is the whole of slides 7 and 8.
The rule behind it is a two-step recipe. Step one is ordinary training, but Han reads it differently: the dense network is not trained to learn final weights, it is trained to learn which connections are important. Step two removes every weight whose magnitude falls below a threshold, which the paper sets as a quality parameter times the standard deviation of that layer's weights. A dense layer becomes a sparse layer. This is Pruning at its simplest, Synapse pruning in the vocabulary of Part 01, and it is the plainest form of Magnitude-based pruning: importance is |w| and nothing else. Once connections are gone, some neurons are left with no surviving input or no surviving output. Those neurons contribute nothing and are removed too, so Neuron pruning falls out of synapse pruning for free.
The right-hand inset of slide 8 shows exactly that gap: the same bell with its center cut out, a hole of width 2t around zero, and nothing else changed. The paper's discussion of its Figure 7 describes the distribution as "centered around zero with tails dropping off quickly" before pruning, then "the center of the distribution" removed. The weights that survive have not moved. They will move in the next concept, and that movement is what retraining does.
Reading the prune-only curve
The chart on slide 8 plots top-5 accuracy loss against the Pruning ratio, the fraction of parameters pruned away, from 40% to 100% on the x axis and from +0.5% to -4.5% on the y axis. The dashed purple curve is what happens with no retraining. It sits at zero up to 50%, which the paper calls a "free lunch of reducing 2x the connections without losing accuracy even without retraining". It reaches about -1% at 67%, about -2.2% at 75%, about -4% at 80%, and leaves the chart just past 82%. Without retraining, the paper says, accuracy "begins dropping much sooner", once only a third of the connections remain.
The x axis counts what is removed, so you have to translate it into a reduction factor before you can compare with a table that reports "9x". Keeping a fraction 1 - r of the weights makes the model 1 / (1 - r) times smaller.
Anchor points to memorize
- 50% pruned
- 2x
- 67% pruned
- 3x
- 75% pruned
- 4x
- 80% pruned
- 5x
- 87.5% pruned
- 8x
- 88.9% pruned
- 9x
- 90% pruned
- 10x
Where the threshold comes from
Because the criterion is magnitude, the threshold and the pruning ratio are two views of the same cut. If the weights of a layer are roughly Gaussian with standard deviation sigma, removing a fraction r means removing everything inside ±t where the Gaussian mass inside ±t equals r. That is an inverse normal lookup: t = sigma × z with z = 0.674 for 50%, z = 1.282 for 80% and z = 1.645 for 90%.
Worked example
Threshold for a Gaussian layer with sigma = 0.03
Half the weights
t = 0.03 × 0.674 = 0.020. Everything with |w| < 0.020 goes. The model is 2x smaller and, on AlexNet, loses nothing.Four fifths
t = 0.03 × 1.282 = 0.038. This is the cut in the visual above: 5x smaller, about -4% top-5 without retraining.Nine tenths
t = 0.03 × 1.645 = 0.049. 10x smaller. Prune-only is off the chart here, one-shot retraining loses about 1.7%, and only the iterative recipe of the third concept holds zero loss.The threshold scales with sigma, the ratio does not
Han sets t per layer as a quality parameter times that layer's standard deviation, so a layer with wider weights gets a proportionally wider cut and the same share removed.
Recall
What does the x axis of the pruning chart measure, and how do you turn 80 percent into a reduction factor?
Return to the AlexNet that lost 4% at 80% pruned. Keep the mask fixed, so the removed weights stay at zero, and train the survivors again with a learning rate one hundredth of the original. The loss comes back to 0.0%. That run took 173 hours on a Titan X against 75 hours for the original training, which is why the paper says pruning is "not used when iteratively prototyping the model, but rather used for model reduction when the model is ready for deployment".
This is step three of the pipeline, and the paper is blunt about its status: retraining "learns the final weights for the remaining sparse connections. This step is critical. If the pruned network is used without retraining, accuracy is significantly impacted." The lecture calls it Fine-tuning. The green curve on slide 9 shows what it buys. It stays at zero, or a hair above, all the way to 80%, then bends: about -0.25% at 84%, about -0.9% at 88%, about -1.7% at 90%, about -4% at 93%. The paper summarizes the same curve as "with retraining we are able to reduce connections by 9x".
Two of the green points sit slightly above zero. The authors do not treat that as noise: "We believe this accuracy improvement is due to pruning finding the right capacity of the network and hence reducing overfitting." In other words, Pruning behaves like a regularizer, and an over-parameterized network can lose most of its weights and generalize a little better for it.
What retraining does to the weights
The third inset on slide 9 is the most informative picture in this part. After pruning, the histogram was a bell with a hole. After retraining it is two smooth lobes, one on each side of zero, and the whole distribution is wider. The paper's text on Figure 7 states the numbers: the original weights lived inside [-0.015, 0.015]; after retraining "the parameters form a bimodal distribution and become more spread across the x-axis, between [-0.025, 0.025]". The survivors have grown in magnitude to take over the work of the connections that were removed. Nothing has been restored; the mask still holds the pruned weights at zero.
Three rules the paper gives for retraining
- Keep the surviving weights; do not reinitialize them. The paper argues that networks contain "fragile co-adapted features" that gradient descent finds when the network is first trained but cannot find again from scratch on a sparse layout.
- Shrink dropout. Pruning has already removed capacity, so the retraining dropout D_r is scaled from the original D_o by the square root of the fraction of connections kept.
- Choose the regularizer for the stage. L1 pushes more weights toward zero and gives better accuracy straight after pruning, but L2 gives better accuracy once the survivors are retrained, so the paper uses L2 for the curves on these slides.
Worked example
Dropout for a fully connected layer kept at 9 percent
Fraction of connections kept
AlexNet's fc6 keeps 9% of its weights, so C_ir / C_io = 0.09.Scale the original dropout
With D_o = 0.5: D_r = 0.5 × sqrt(0.09) = 0.5 × 0.3 = 0.15.Result
Retrain with dropout 0.15, not 0.5. A sparse layer already regularizes itself.
One more observation from the paper's sensitivity study (Figure 6) matters for your own experiments: convolutional layers are more sensitive to pruning than fully connected ones, and the first convolutional layer is the most sensitive of all, because its input has only three channels and there is little redundancy to remove. That is why the per-layer keep rates in the next concepts are so uneven.
Quick check
In Han's three-step pipeline, which step does the paper call critical because skipping it makes accuracy drop significantly?
Recall
State the three steps of Han's pipeline and say which one the paper calls critical.
Start from the retrained network at 80% pruned, the last green point still on the zero line, a 5x model with no loss. Now prune it again, using the retrained magnitudes, and fine-tune again. The paper describes what happens: "The leftmost dot on this curve corresponds to the point on the green line at 80% (5x pruning) pruned to 8x. There's no accuracy loss at 9x. Not until 10x does the accuracy begin to drop sharply." The red curve on slide 10 is that experiment: flat through 90%, about -0.5% at 92%, -1% at 93%, -2% at 94%, and about -4% between 95% and 96%.
This is Iterative pruning, and the paper states the rule and the payoff in one breath: "Pruning followed by a retraining is one iteration, after many such iterations the minimum number connections could be found. Without loss of accuracy, this method can boost pruning rate from 5x to 9x on AlexNet compared with single-step aggressive pruning." Each iteration is a greedy search. VGG-16 used five rounds; ResNet-50 in Han's thesis used three. The left side of slide 10 draws the loop: train connectivity, prune connections, train weights, and an arrow from train weights back to prune.
Learn which connections matter.
Cut a fraction of the survivors.
Survivors redistribute, then loop back to prune.
Why several small cuts beat one big cut
A single cut to 90% judges every weight by the magnitude it had in the dense network. But the previous concept showed that retraining changes those magnitudes: the survivors grow and the distribution becomes bimodal. Weights that looked expendable in the dense network may become load-bearing after the first round, and weights that looked important may shrink once their neighbours take over. Iterating lets each cut use the freshest evidence. Frankle and Carbin reach the same conclusion in a different setting: iterative pruning over n rounds, each removing p^(1/n) of what remains, "finds winning tickets that match the accuracy of the original network at smaller sizes than does one-shot pruning". The price, which they also state, is that repeated retraining is expensive.
Worked example
Compounding a pruning schedule
Equal halves
Three rounds that each remove half of the survivors leave 0.5 × 0.5 × 0.5 = 12.5%, an 8x model. Four rounds leave 6.25%, which is 16x.Hitting a target in equal rounds
To reach 90% overall in three equal rounds, each round must keep 0.1^(1/3) = 0.464 of what remains, so it removes 53.6% of the current survivors.Han's actual path
80% in one round (5x), then re-pruned to 8x, then 9x, all at zero loss. The drop only starts past 10x.
| Pruning ratio | Prune only | Prune + fine-tune | Iterative |
|---|---|---|---|
| 80% (5x) | about -4% | 0% | starting point: the retrained 80% model |
| 90% (10x) | off the chart | about -1.7% | about 0% |
| 93% (14x) | off the chart | about -4% | about -1% |
Slide to 80% and switch recipes: prune-only sits near -4%, both retrained recipes sit at zero. Slide to 90%: only the iterative loop is still at zero. The red curve begins at the 80% retrained model, as on slide 10, so below that it has no data. The histogram is a model, not the paper's data: a zero-mean Gaussian with sigma = 0.03, cut at the threshold that removes the chosen share, then redrawn as two lobes once retraining lets the survivors grow.
Quick check
Reading slide 10, roughly how far can iterative prune-and-retrain go before top-5 loss exceeds half a percent?
Recall
At 80 percent pruned, what top-5 loss do prune-only and prune-plus-retrain give, where does the iterative curve begin, and what reduction factor is that?
Recall
Why did iterative pruning lift AlexNet from 5x to 9x with no loss?
Look at AlexNet layer by layer, as the paper's Table 4 does. Its first fully connected layer, fc6, holds 38 M weights but costs only 75 M FLOPs, because each weight is used once per image. Its second convolutional layer, conv2, holds 307 K weights but costs 448 M FLOPs, because each weight is reused at every spatial position. Add the layers up and the network splits into two worlds: the three FC layers hold 58.6 M of the 61 M parameters (96.2%, which the paper rounds to 59 M) but only about 117 M of 1.45 G FLOPs (8%), while the five conv layers hold 2.3 M parameters (3.8%) but 1.33 G FLOPs (92%).
That split explains the table on slide 11 before you read it. Pruning fc6 to 9% deletes 34.6 M parameters but only 68 M FLOPs by weight count (73 M once zero activations are skipped as well, which is how Han counts). Pruning conv2 to 38% deletes only 190 K parameters but 278 M FLOPs by weight count (300 M by Han's count). Parameter reduction is a story about FC layers; MAC reduction is a story about conv layers, and the two are pruned to very different depths.
| Network | Parameters before | After | Parameter reduction | MAC reduction | FC share of parameters |
|---|---|---|---|---|---|
| AlexNet | 61 M | 6.7 M | 9x | 3x | 96.2% |
| VGG-16 | 138 M | 10.3 M | 12x | 5x | 89.9% |
| GoogleNet | 7 M | 2.0 M | 3.5x | 5x | about 14% |
| ResNet-50 | 26 M | 7.47 M | 3.4x | 6.3x | about 8% |
| SqueezeNet | 1 M | 0.38 M | 3.2x | 3.5x | 0% |
Why the over-parameterized nets compress more
AlexNet and VGG-16 get 9x and 12x; GoogleNet, ResNet-50 and SqueezeNet get about 3.2x to 3.5x. The extra column is the reason. VGG-16's fc6 alone holds 103 M of its 138 M weights, and the paper prunes fc6 and fc7 to 4% of their size while conv layers keep 22% to 58%. GoogleNet has one FC layer of about 1 M in 7 M, ResNet-50 one of about 2 M in 25.5 M, and SqueezeNet has none at all, ending in global average pooling. Han's thesis says it directly: the pruning ratio of GoogleNet is smaller than AlexNet and VGG-16 "because convolutional layers dominate GoogleNet, and convolutional layers are much more efficient than fully connected layers". The three conv-dominated networks land in the same place, about 30% of parameters nonzero (GoogleNet 29%, SqueezeNet 31%, ResNet 29%), which is the 3.4x in the table. Their FC rows, where Neuron pruning would delete whole rows of a weight matrix, are too small to matter.
Why MAC reduction is not parameter reduction
Two mechanisms separate the two columns. The first is the split above: parameters concentrate in FC layers, which are pruned hardest, and MACs concentrate in conv layers, which are pruned least. That is how AlexNet gets 9x on parameters but 3x on MACs, and VGG-16 12x against 5x. The second is how Han counts. A multiply-accumulate is only counted as saved when it is really skipped, and it is skipped when either the weight or the input activation is zero. ReLU produces plenty of zero activations, so the FLOP column in Table 4 is roughly the weight density times the density of the layer's input activations.
Worked example
Checking the rule against AlexNet's Table 4
conv2
Weights kept 38%, input activations (the output of conv1) 88% nonzero: 0.38 × 0.88 = 33%. The table says 33%.fc6
Weights kept 9%, input activations (the output of conv5) 34% nonzero: 0.09 × 0.34 = 3%. The table says 3%.ResNet-50, whole network, run backwards
The thesis reports 29% of weights kept (3.4x) and about 16% of FLOPs remaining (6.25x, rounded to 6.3x on the slide). The rule then implies an average input activation density near 0.16 / 0.29 = 55%, which is a plausible ReLU figure. This step derives the density from the two reported numbers rather than checking a third.Compute can fall faster than parameters
For conv-heavy networks the activation zeros from ReLU are a second source of Sparsity, which is why ResNet-50 and GoogleNet cut MACs by more than they cut parameters.
Even where MACs barely fall, the parameter count is worth cutting. A 6.7 M parameter AlexNet fits in on-chip SRAM, and the paper's point from Part 01 stands: at 640 pJ per DRAM access, the energy of fetching weights dominates the energy of multiplying them.
Quick check
AlexNet's parameters fall 9x after pruning but its MACs fall only 3x. Why?
Recall
AlexNet: 9x fewer parameters but only 3x fewer MACs. Give both reasons.
Everything so far was an image classifier with a huge fully connected tail. NeuralTalk, Karpathy and Fei-Fei's image captioner, is a different animal: a CNN feature extractor feeding an LSTM that writes a sentence one word at a time. Han froze the CNN, pruned every LSTM weight matrix except the word-embedding table to 10% nonzeros, retrained with the original weight decay and batch size, and measured BLEU-1 to BLEU-4 on Flickr-8K. The thesis reports: "Not until pruning away 90% of the parameters does the BLEU score begin to drop sharply."
The recipe did not change. Train, cut the small weights, retrain the survivors: the same three steps, the same knee near 90%, and the same dependence on Fine-tuning, which the thesis says "plays a very important role" when it compares the retrained curve with the one that skips retraining. Slide 12 shows the qualitative check that a BLEU number cannot: the captions themselves.
| Image | Baseline | Pruned | Pruning ratio | Verdict |
|---|---|---|---|---|
| Basketball | a basketball player in a white uniform is playing with a ball | a basketball player in a white uniform is playing with a basketball | 90% | Same meaning, more specific noun |
| Dog | a brown dog is running through a grassy field | a brown dog is running through a grassy area | 90% | Synonym |
| Surfer | a man is riding a surfboard on a wave | a man in a wetsuit is riding a wave on a beach | 90% | Different but valid description |
| Soccer | a soccer player in red is running in the field | a man in a red shirt and black and white black shirt is running through a field | 95% | Drift: repeated phrase, lost the word soccer |
At 90% the pruned model "sometimes produces the same caption, sometimes produces a different word to describe the same thing", and sometimes describes the scene differently but still correctly. Replacing "ball" with "basketball" is arguably an improvement. The fourth image is the warning. At 95% pruned, a 20x model, the sentence starts to stutter: "a red shirt and black and white black shirt" repeats a phrase and loses the word "soccer". That is what crossing the knee of the Pruning ratio curve looks like in a language model: not silence, but drift.
Recall
Name a non-CNN case where the prune-and-retrain recipe worked, and give its pruning ratio.
Take fc6 of AlexNet pruned to 9% and run it with an ordinary dense matrix kernel on a GPU. The kernel does not know the zeros are zeros. It multiplies all 38 M weight-activation pairs, 34.6 M of them by zero, and finishes in exactly the time the dense layer took. Nine times fewer parameters, zero speedup. The reduction table of two concepts ago counted what could be skipped; it did not promise that anything would be. Skipping needs either a custom engine that understands sparse formats or a sparsity pattern that commodity hardware is built for. Slide 13 shows both.
The commodity route: NVIDIA A100 and 2:4
The Ampere whitepaper defines 2:4 sparsity as a structure "that allows two non-zero values in every four-entry vector". Every group of four contiguous weights along a row keeps at most two, so the matrix is exactly half zeros, stored as the nonzero values plus a 2-bit index per survivor. That compression cuts storage and bandwidth "by almost 2x", and the Sparse Tensor Core has a matrix multiply instruction that reads the indices, gathers only the matching activations, and finishes a tile in N/2 cycles instead of N: "a 2x speedup". This is the special case N = 2, M = 4 of N:M sparsity.
How does a model get into that pattern? The whitepaper's recipe is the pipeline of this part with one constraint added: the network is "first trained using dense weights, then fine-grained structured pruning is applied, and finally the remaining non-zero weights are fine-tuned". NVIDIA's developer blog reports BERT-Large keeping its SQuAD F1 of 91.9 dense and sparse. The magnitude criterion, the mask and the retraining are all Han's; the only change is that the two smallest of every four are cut instead of the smallest 50% of the layer.
What the A100 asks for and what it delivers
- Pattern required
- 2 nonzeros in every 4 contiguous weights (50% sparsity)
- Storage and bandwidth
- almost 2x smaller: half the values plus 2-bit indices
- Peak Tensor Core throughput
- up to 2x: Sparse MMA finishes a tile in N/2 cycles
- Measured, BERT-Large GEMM layers (cuSPARSELt on A100)
- 1.3x (projection), 1.4x (QKV, FC1), 1.6x (FC2)
- Slide's summary
- 1.5x measured BERT speedup
The gap between 2x and 1.5x is the gap between a peak instruction rate and a whole layer. The whitepaper says "up to 2x". NVIDIA's cuSPARSELt measurements on BERT-Large GEMM layers on an A100 give 1.3x for the projection, 1.4x for QKV and FC1, and 1.6x for FC2 over dense cuBLAS, because memory traffic for activations, the non-GEMM parts of the layer and kernel launch costs do not halve. The slide's "1.5X measured BERT speedup" is Han's summary of those numbers. Treat 1.5x as the realistic middle and 2x as the ceiling.
The custom route: engines built to skip zeros
Before 2:4 existed, the way to profit from unstructured sparsity was to build the hardware yourself. The four papers cited on slide 13 are all from Han and his students, and each makes a different thing sparse. EIE, the Efficient Inference Engine, holds the compressed model in on-chip SRAM, so the 640 pJ DRAM access from Part 01 disappears, and it skips both zero weights and the zero activations that ReLU produces, which its authors say "saves another 3x". ESE moves the same idea onto an FPGA for pruned speech-recognition LSTMs, the same recipe the previous concept applied to NeuralTalk. SpArch accelerates multiplying two sparse matrices, and SpAtten prunes tokens and attention heads at run time instead of weights.
| System | Venue | What is sparse | Headline |
|---|---|---|---|
| EIE | ISCA 2016 | Weights and activations of pruned FC layers, model held in on-chip SRAM | 189x faster than CPU, 13x faster than GPU, 24000x more energy efficient than CPU |
| ESE | FPGA 2017 | Pruned LSTM weights for speech recognition | 43x faster than a Core i7, 3x faster than a Pascal Titan X, 282 GOPS on the compressed model |
| SpArch | HPCA 2020 | Sparse matrix times sparse matrix (outer product with merge) | 2.8x fewer DRAM accesses, 4x over OuterSPACE |
| SpAtten | HPCA 2021 | Tokens and heads of attention, pruned in a cascade | 10x less DRAM traffic, 162x over a Titan Xp |
| A100 Sparse Tensor Core | NVIDIA 2020 | Any weight matrix in the 2:4 pattern | up to 2x peak, 1.3x to 1.6x measured per BERT-Large layer |
Worked example
The same pruned layer on three targets
Dense GPU kernel
fc6 at 9% density still executes all 38 M MACs (75 M FLOPs). Speedup 1x. Memory footprint is smaller only if you store it sparse and decompress it, which costs time too.EIE
Work is proportional to nonzero weight times nonzero activation pairs, roughly 3% of the dense count for fc6, and the weights never leave SRAM. This is where the MAC column of the reduction table becomes real time and real energy.A100 Sparse Tensor Core
You must prune exactly half in the 2:4 pattern, no more and no less, and you get at most 2x. The 9% density of fc6 cannot be expressed, so you either settle for 50% or lose the hardware path.Speed is a property of the pair
The same sparse matrix is a 1x, a 2x or a 30x win depending on what executes it. Parameter count alone predicts none of those.
Quick check
What must a weight matrix satisfy before A100 sparse Tensor Cores can double its throughput?
Recall
What does the A100 require of a pruned matrix, and what does it deliver?
Recap
If you remember nothing else
- Train, prune below a magnitude threshold, retrain the survivors. The retraining step is critical.
- Prune-only: free lunch at 50 percent, about -1 percent at 67 percent, about -4 percent at 80 percent pruned.
- Prune plus retrain: zero loss to about 80 percent, 9x on AlexNet. Weights become bimodal and spread from ±0.015 to ±0.025.
- Iterative prune and retrain: zero loss to about 90 percent, 5x lifted to 9x, sharp drop only past 10x.
- Reduction factor = 1 / (1 - pruning ratio): 80 percent is 5x, 90 percent is 10x.
- AlexNet is 9x smaller but only 3x cheaper: FC layers hold 96.2 percent of parameters, conv layers hold 92 percent of MACs. FLOP% ≈ weight density × input activation density.
- Fully convolutional nets (GoogleNet, ResNet-50, SqueezeNet) all keep about 30 percent, so about 3.4x.
- The NeuralTalk LSTM pruned 90 percent keeps BLEU flat and captions nearly identical. 95 percent starts to drift.
- Sparsity is speed only with hardware support: EIE, ESE, SpArch, SpAtten, or the A100 2:4 pattern (up to 2x peak, about 1.3x to 1.6x measured on BERT-Large layers).
Sources
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NeurIPS 2015Three-step pipeline, retraining is critical, Figure 5 curves, Table 4 layer statistics, Figure 7 bimodal weights, dropout equation 2, 9x and 13x.(opens in a new tab)
- Efficient Methods and Hardware for Deep LearningPaperSong Han, PhD thesis, Stanford University, 2017Tables 3.4 to 3.8 (GoogleNet, ResNet-50, SqueezeNet rows), about 30 percent nonzero in conv-dominated networks, NeuralTalk pruning and captions (section 3.4.3).(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 3: Pruning and Sparsity (Part I)DocsMIT HAN LabThe deck these slides reproduce, including the reduction table, the four captions and the A100 line.(opens in a new tab)
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperHan, Mao and Dally, ICLR 2016Pruning as the first stage (9x to 13x) of a 35x to 49x compression pipeline.(opens in a new tab)
- The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural NetworksPaperFrankle and Carbin, ICLR 2019Iterative pruning over n rounds finds smaller networks than one-shot pruning; each round prunes p^(1/n) of survivors.(opens in a new tab)
- EIE: Efficient Inference Engine on Compressed Deep Neural NetworkPaperHan et al., ISCA 2016189x and 13x faster than CPU and GPU, 24000x and 3400x more energy efficient, skipping zero activations saves 3x.(opens in a new tab)
- ESE: Efficient Speech Recognition Engine with Sparse LSTM on FPGAPaperHan et al., FPGA 201720x model compression (10x pruning, 2x quantization), 43x over a Core i7, 3x over a Pascal Titan X, 282 GOPS.(opens in a new tab)
- SpArch: Efficient Architecture for Sparse Matrix MultiplicationPaperZhang et al., HPCA 20202.8x fewer DRAM accesses, 4x over OuterSPACE.(opens in a new tab)
- SpAtten: Efficient Sparse Attention Architecture with Cascade Token and Head PruningPaperWang, Zhang and Han, HPCA 202110x DRAM access reduction, 162x over a Titan Xp.(opens in a new tab)
- NVIDIA A100 Tensor Core GPU Architecture whitepaperDocsNVIDIA2:4 definition, almost 2x storage and bandwidth, N/2 cycles, dense-prune-finetune recipe (pages 31 to 32).(opens in a new tab)
- Accelerating Inference with Sparsity Using the NVIDIA Ampere Architecture and NVIDIA TensorRTArticleNVIDIA Developer Blog2:4 recipe and BERT-Large SQuAD F1 of 91.9 dense and sparse.(opens in a new tab)
- Exploiting NVIDIA Ampere Structured Sparsity with cuSPARSELtArticleNVIDIA Developer BlogMeasured 1.3x to 1.6x speedups on BERT-Large GEMM layers on an A100.(opens in a new tab)
- Accelerating Sparse Deep Neural NetworksPaperMishra et al., NVIDIA, 2021Twice the math throughput for 2:4 sparse matrices and the training recipe that preserves accuracy.(opens in a new tab)
Part 03: Pruning granularity: from irregular to regular
Fine-grained versus coarse-grained pruning on a 2D weight matrix, the four dimensions of a convolution weight tensor, and the five commonly used granularities from fine-grained to channel-level.
3 concepts, slides 14-18
Why this part matters
Sooner or later your embedded project will hit this moment: a network that is 90% zeros runs no faster on the target MCU or GPU than the dense one did. Nothing is wrong with the pruning. What is wrong is the shape of the holes, and that shape is what this part is about.
Part 02 showed that pruning can remove most of a network's weights without hurting accuracy. The next question on the lecture's outline is in what pattern to remove them. We start with a single 8 x 8 matrix and two ways of cutting it, then open up a convolution weight to see that it has four dimensions and therefore many more ways to be cut, and finish with a ladder of five granularities adapted from Mao et al., who studied four. Exams ask you to order that ladder, to count the weights a given unit removes and to argue the trade between flexibility and acceleration. The same ladder returns in the next part as NVIDIA 2:4 sparsity, channel pruning and AMC, and again in lecture 04-2.
By the end you can
- Define pruning granularity and place fine-grained and coarse-grained pruning at its two ends.
- Explain why coarse-grained choices are a subset of fine-grained ones and what that does to attainable sparsity at equal accuracy.
- Read a convolution weight as [c_o, c_i, k_h, k_w] and count the weights in a filter, an input channel, a kernel and a row.
- Order fine-grained, pattern-based, vector-level, kernel-level and channel-level from irregular to regular and say what hardware each maps onto.
- Compute the sparsity and the surviving shape after removing a given unit.
Take a weight matrix with eight rows and eight columns, 64 weights in all, and decide to remove 24 of them. One way is to cross out rows 3, 4 and 7 completely. Another is to cross out 24 individual entries wherever the magnitude criterion of part 05 says they matter least. Both leave 40 weights and both reach a Sparsity of 24 / 64 = 37.5%. Everything else about them is different.
The unit you delete is the Pruning granularity. Deleting single weights is fine-grained, or unstructured, pruning. Deleting whole rows, columns, kernels or channels is coarse-grained, or structured, pruning. Two consequences pull in opposite directions as the unit grows. The number of masks you may choose from falls, which costs accuracy at a given Pruning ratio. The regularity of what survives rises, which is what lets ordinary hardware run the pruned layer faster.
Counting the choices
The slide calls fine-grained pruning "more flexible" and coarse-grained pruning "a subset of the fine-grained case". Both statements can be made exact by counting masks. A mask is the set of positions you zero, and the pruning problem of part 01 searches over masks for the one with the lowest loss.
Worked example
How many masks remove 24 of 64 weights
Fine-grained
Any 24 of the 64 positions may go, so there are C(64, 24) = 250,649,105,469,666,120 masks, about 2.5 x 10^17.Row-structured
Any 3 of the 8 rows may go, so there are C(8, 3) = 56 masks.Nest one inside the other
Every one of the 56 row masks is also a set of 24 individual positions, so it is one of the 2.5 x 10^17 fine-grained masks. The structured menu sits strictly inside the unstructured menu.Consequence for accuracy
The best row mask can at most tie the best fine-grained mask on the loss. It can never beat it. At a fixed accuracy target, structured pruning therefore reaches equal or lower sparsity, never higher, for the best achievable mask under the same retraining.
Same sparsity, different search spaces
- Weights removed
- 24 of 64 (37.5%)
- Fine-grained masks
- C(64, 24) ≈ 2.5 x 10^17
- Row-structured masks
- C(8, 3) = 56
- Surviving shape, fine-grained
- 8 x 8 with 24 holes
- Surviving shape, row-structured
- 5 x 8 dense
Why irregular means hard to accelerate
Multiply a vector by the 5 x 8 survivor and nothing special happens. It is just a smaller dense matrix, and every BLAS routine, every tensor core and every microcontroller loop handles it at full speed. That is the slide's "easy to accelerate (just a smaller matrix!)". Now multiply by the 8 x 8 matrix with 24 holes. A dense routine still performs all 64 multiplies, 24 of them by zero, and gains nothing. To gain, you must store the 40 surviving values together with their positions, in a compressed sparse format, and let the hardware skip the zeros one by one. Mao et al. draw the same line: fine-grained sparsity scatters the tensor into isolated weights and needs custom accelerators such as EIE or SCNN to exploit it, while filter and channel sparsity is simple to accelerate on general-purpose processors because it "is equivalent to obtaining a smaller dense model" (Mao et al., 2017, section 2).
The gap is measurable. Wen et al. trained AlexNet with structured sparsity and reported average layer-wise speedups of the convolutional layers of 5.1x on CPU and 3.1x on GPU with off-the-shelf libraries, against 3.0x and 0.9x for non-structured l1 sparsity (Wen et al., 2016, Table 4). The fine-grained model had more zeros. The structured model ran faster.
What the accuracy price looks like
Because coarse units search a smaller space, they lose a little accuracy at the same density (the fraction of weights kept). Mao et al. measured this on ImageNet with the same pipeline at every granularity. The differences are small between fine and vector grains and grow as the grain reaches whole kernels; pruning entire filters "loses nearly 1% validation accuracy at the very first pruning stage" on AlexNet (Mao et al., 2017).
| Network | Density kept | Fine-grained | Vector-level | Kernel-level |
|---|---|---|---|---|
| AlexNet | 24.8% | 80.41% | 79.94% | 79.20% |
| VGG-16 | 23.5% | 90.56% | 90.48% | 89.70% |
| ResNet-50 | 40.0% | 92.34% | 92.26% | 92.07% |
| Granularity | Density kept | Storage relative to dense |
|---|---|---|
| Fine-grained | 22.1% | 33.0% |
| Vector-level | 29.9% | 34.5% |
| Kernel-level | 37.8% | 39.7% |
Recall
Rows 3, 4 and 7 of an 8 x 8 weight matrix are pruned. What is the sparsity, and what shape survives?
Recall
Why does the slide call coarse-grained choices a subset of the fine-grained case, and what does that imply for compression?
Quick check
Why is fine-grained pruning hard to accelerate on an ordinary GPU?
Quick check
Which statement about coarse-grained pruning matches slide 15?
A linear layer's weight is a matrix, so its only structured units are rows and columns. A convolution weight is richer. Slide 17 draws one: three rows of kernels stacked vertically, two columns of kernels side by side, and each kernel a 3 x 3 grid. Count the cells and you get 3 x 2 x 3 x 3 = 54 weights.
Those four factors are the four dimensions of a convolution weight. The tensor has shape [c_o, c_i, k_h, k_w]: c_o output channels, also called filters; c_i input channels; and a kernel of height k_h and width k_w. Goodfellow, Bengio and Courville write the same object as a 4-D kernel tensor K whose element K[i, j, k, l] is the connection strength between output channel i and input channel j at a row offset of k and a column offset of l (Goodfellow et al., 2016, section 9.5). PyTorch stores Conv2d.weight with exactly the slide's ordering, (out_channels, in_channels / groups, kernel_size[0], kernel_size[1]) (PyTorch documentation).
Slicing the tensor into units
The reason the lecture stops to name the dimensions is that each way of slicing the tensor is a candidate pruning unit. Mao et al. name the slices with array notation, and reading them that way makes the counts automatic. Fix the output channel and you have a filter, a 3-D slab. Fix the output and input channel and you have one kernel, a 2-D grid. Fix a row inside that kernel and you have a 1-D vector. Fix everything and you have a single scalar weight (Mao et al., 2017, section 3.2).
| Unit | Slice | Weights | Share of 54 |
|---|---|---|---|
| Single weight | W[o, i, r, c] | 1 | 1.9% |
| Row inside a kernel | W[o, i, r, :] | k_w = 3 | 5.6% |
| Kernel | W[o, i, :, :] | k_h x k_w = 9 | 16.7% |
| Filter (output channel) | W[o, :, :, :] | c_i x k_h x k_w = 18 | 33.3% |
| Input channel | W[:, i, :, :] | c_o x k_h x k_w = 27 | 50.0% |
Two formulas do all the work. A filter holds c_i · k_h · k_w weights, because it has one kernel per input channel. An input channel holds c_o · k_h · k_w weights, because every filter has a kernel that reads it. In the slide these are 18 and 27, and it is easy to mix them up, so picture the grid: a filter is a row of kernels, an input channel is a column of kernels.
The same counts at a realistic scale
Slide 17 is a toy so the picture fits. A VGG-style layer with 64 input and 64 output channels and 3 x 3 kernels has 64 x 64 x 9 = 36,864 weights, and the same slicing rules apply.
| Unit removed | Weights removed | Share | Surviving shape |
|---|---|---|---|
| One kernel | 9 | 0.024% | Still [64, 64, 3, 3] with holes |
| One filter | 64 x 9 = 576 | 1.56% | [63, 64, 3, 3] |
| One input channel | 64 x 9 = 576 | 1.56% | [64, 63, 3, 3] |
| Sixteen input channels | 16 x 576 = 9,216 | 25% | [64, 48, 3, 3] |
Removing a whole filter has a second effect that Li et al. spell out. The filter's output feature map disappears, so the next layer no longer receives that channel, and the corresponding kernels in the next layer's weight tensor disappear too. Pruning m of the n filters of a layer removes m / n of the compute in that layer and in the one after it (Li et al., 2017).
Recall
Name the four dimensions of a convolution weight in the slide's order, and give the weight count for c_o = 3, c_i = 2 and 3 x 3 kernels.
Recall
How many weights go when you remove one kernel, one input channel and one filter from the 54-weight tensor?
Quick check
A convolution layer has c_o = 3, c_i = 2 and 3 x 3 kernels. Channel-level pruning removes one input channel. How many weights are removed?
Put the two previous ideas together and the lecture's central figure appears. Slide 18 takes the same 54-weight tensor and prunes it five times, once per unit, arranging the results on an axis from irregular to regular. Read from left to right, the holes grow from single cells, to fixed shapes inside kernels, to whole rows, to whole kernels, to an entire column of kernels.
Every panel can be counted, and counting them shows something the picture hides: every panel removes between a third and two thirds of the weights, so the real difference between them is not how much Sparsity they reach but how the zeros are arranged. The fine-grained panel keeps 23 scattered weights. The pattern-based panel keeps exactly four cells in every kernel, and each kept shape is a Tetris piece (a T or an L of four cells). The vector-level panel keeps seven of the eighteen kernel rows. The kernel-level panel drops the first filter's right kernel and the second filter's left kernel. The channel-level panel drops the whole second input channel across all three filters, and what survives is a dense [3, 1, 3, 3] tensor.
| Panel | What was removed | Weights removed | Sparsity | Survivor |
|---|---|---|---|---|
| Fine-grained | 31 single weights | 31 | 57.4% | 54 slots with holes |
| Pattern-based | 5 of 9 cells in each of 6 kernels | 6 x 5 = 30 | 55.6% | 54 slots, one shape per kernel |
| Vector-level | 11 of 18 kernel rows | 11 x 3 = 33 | 61.1% | 54 slots with empty rows |
| Kernel-level | 2 of 6 kernels | 2 x 9 = 18 | 33.3% | 54 slots with empty kernels |
| Channel-level | 1 of 2 input channels | 3 x 9 = 27 | 50.0% | dense [3, 1, 3, 3] |
The ladder, rung by rung
Mao et al. organise four grains (fine, vector, kernel, filter) by how many dimensions each unit spans. The slide keeps their order, inserts pattern-based pruning between fine-grained and vector-level, and shows the 3-D rung as an input channel instead of Mao's filter (Mao et al., 2017, section 3.2). At the bottom, fine-grained pruning removes 0-D scalars anywhere. Pattern-based pruning keeps a small catalogue of fixed shapes inside each kernel, which the slide calls "like Tetris": the hardware knows the finite set of masks in advance instead of facing arbitrary holes. Niu et al. describe it as "fine-grained pruning patterns inside the coarse-grained structures" and, by compiling specialised code per pattern, ran networks on mobile CPUs and GPUs up to 44.5x faster than TensorFlow Lite and up to 11.4x faster than TVM with no accuracy loss (Niu et al., 2020). Vector-level pruning removes 1-D rows, W[o, i, r, :], of a kernel. Kernel-level pruning removes 2-D kernels, W[o, i, :, :]. At the top, channel pruning removes a 3-D slab: on the slide, an input channel W[:, i, :, :] across every filter.
| Granularity | Unit | Weights per unit | Index cost | Runs efficiently on |
|---|---|---|---|---|
| Fine-grained | Any single weight (0-D) | 1 | One index per surviving weight | Custom sparse engines such as EIE or SCNN |
| Pattern-based | A fixed mask inside each kernel | 5 per kernel | One pattern id per kernel | Compilers that specialize code per pattern (PatDNN) |
| Vector-level | A row of a kernel (1-D) | k_w = 3 | One index per surviving row | Custom 1-D convolution hardware such as Eyeriss |
| Kernel-level | A whole k_h x k_w kernel (2-D) | 9 | One index per surviving kernel | Custom 2-D convolution hardware (not stock dense libraries) |
| Channel-level | An input channel across all filters (3-D) | 27 | None: the tensor shrinks | Any dense CPU or GPU library |
The right-hand column is the practical half of the story. Only the channel and filter rungs run faster on unmodified dense libraries, because the tensor simply shrinks. Kernel and vector sparsity line up with 2-D and 1-D convolution primitives (Winograd, Eyeriss-style 1-D units), which makes custom hardware simpler, but Mao et al. note they are still hard to accelerate on general-purpose processors. Pattern-based pruning needs compiler support (PatDNN) or dedicated support such as NVIDIA's 2:4 sparse tensor cores, and fine-grained sparsity needs accelerators such as EIE (Mao et al., 2017, section 6).
Try every rung on one tensor
The simulator below holds a random [3, 2, 3, 3] tensor and lets you prune it with any of the six units, including the filter unit that Mao et al. list alongside channels. It groups the weights by the chosen unit, scores each group with the L1 or L2 magnitude that part 05 develops, zeros the weakest groups until the target is met, and reports what survives. Watch three things as you switch units: the achieved sparsity snaps to coarser steps, the index count collapses as units grow, and only the channel and filter units ever produce a smaller dense tensor.
- Unit
- Individual weight
- Weights per unit
- 1
- Slice
- W[o, i, r, c]
- Units removed
- 19 of 54
Units are ranked by the L1 norm of the weights they would remove, lowest first, and pruned until at least 19 of 54 weights are zero. Achieved sparsity snaps to whole units.
The energy argument from part 01 also runs along this axis. Mao et al. simulated the SCNN sparse accelerator on VGG-16 and found that, at the same density, vector-level sparsity needs 30 to 35% fewer output memory references than fine-grained sparsity. Neighbouring surviving weights in a row write to the same output address, so SCNN can skip the repeated read and write of that address (Mao et al., 2017, section 6 and Table 4). Since a DRAM access costs about two hundred times a multiply, fewer memory references is where the energy goes, not fewer multiplies.
Recall
Order fine-grained, kernel-level, pattern-based, channel-level and vector-level pruning from irregular to regular.
Quick check
Which granularity turns the weight tensor into a smaller dense tensor that needs no index storage at all?
Recap
If you remember nothing else
- Granularity is the unit you delete. Smaller units give more index choices, larger units give regular structure.
- Coarse-grained masks are a subset of fine-grained masks, so at equal accuracy structured pruning reaches equal or lower sparsity, never higher, for the best achievable mask under the same retraining.
- Fine-grained pruning is hard to accelerate because zeros sit anywhere. Channel or filter pruning yields a smaller dense tensor that any library runs.
- Convolution weights are [c_o, c_i, k_h, k_w]. Slide 17's example holds 3 x 2 x 3 x 3 = 54 weights.
- From irregular to regular: fine-grained, pattern-based, vector-level, kernel-level, channel-level.
- Removing one kernel drops k_h x k_w weights, one input channel drops c_o x k_h x k_w, one filter drops c_i x k_h x k_w.
- Coarser grains share indices, so their storage penalty is smaller than their sparsity penalty (Mao et al.).
Sources
- Exploring the Granularity of Sparsity in Convolutional Neural NetworksPaperCVPR Workshops 2017, Mao, Han, Pool, Li, Liu, Wang and DallySource of the slide's figure, which adds a pattern-based rung and uses channel-level where the paper uses filter-level. Grain definitions in 3.2, accuracy at equal density in Table 1, storage with 4-bit indices in Table 2, hardware mapping and SCNN memory reference savings in section 6.(opens in a new tab)
- MIT 6.5940 EfficientML.ai, Lecture 3: Pruning and Sparsity (Part I)DocsMIT HAN LabThe course from which this lecture's slides are adapted.(opens in a new tab)
- Learning Structured Sparsity in Deep Neural NetworksPaperNIPS 2016, Wen, Wu, Wang, Chen and LiStructured sparsity gives average layer-wise convolution speedups of 5.1x on CPU and 3.1x on GPU with standard libraries, against 3.0x and 0.9x for non-structured l1 sparsity (Table 4).(opens in a new tab)
- Pruning Filters for Efficient ConvNetsPaperICLR 2017, Li, Kadav, Durdanovic, Samet and GrafFilter pruning removes the feature map and the next layer's kernels; pruning m of n filters cuts m/n of the compute in both layers.(opens in a new tab)
- PatDNN: Achieving Real-Time DNN Execution on Mobile Devices with Pattern-based Weight PruningPaperASPLOS 2020, Niu et al.Pattern-based pruning as fine-grained patterns inside coarse-grained structures, up to 44.5x over TensorFlow Lite and up to 11.4x over TVM.(opens in a new tab)
- Structured Pruning of Deep Convolutional Neural NetworksPaperAnwar, Hwang and Sung, 2015Channel-wise, kernel-wise and intra-kernel strided sparsity, an early version of the ladder.(opens in a new tab)
- Deep Learning, chapter 9: Convolutional NetworksBookGoodfellow, Bengio and Courville, MIT Press 2016Section 9.5 defines the 4-D kernel tensor K with output channel, input channel, row offset and column offset.(opens in a new tab)
- torch.nn.Conv2dDocsPyTorch documentationWeight shape (out_channels, in_channels / groups, kernel_size[0], kernel_size[1]).(opens in a new tab)
- Learning both Weights and Connections for Efficient Neural NetworksPaperNIPS 2015, Han, Pool, Tran and DallyFine-grained magnitude pruning, the left end of the ladder.(opens in a new tab)
Part 04: Fine-grained, N:M and channel pruning in practice
Trade-offs of each granularity with real numbers: fine-grained compression ratios, NVIDIA 2:4 pattern sparsity with its compressed format and accuracy table, and channel pruning with non-uniform per-layer sparsity versus uniform shrinking.
5 concepts, slides 19-25
Why this part matters
Your research targets embedded deployment, where the question is never "how many weights can I remove" but "which removal makes this board faster". This part is where the granularity spectrum of part 03 meets real hardware.
It explains why a 9x compressed AlexNet (or a 13x compressed VGG-16) can run no faster on a GPU, why NVIDIA built a 2:4 pattern into its Ampere Tensor Cores, and why the model-compression papers you will cite (AMC, channel pruning) search for per-layer ratios instead of one global number. These are also the three most examinable facts in the lecture: which granularity gives speedup on commodity GPUs and why, what sparsity 2:4 means, and why non-uniform per-layer sparsity beats uniform shrink.
By the end you can
- Explain why fine-grained pruning gives the largest compression ratio but little or no speedup on GPUs with standard kernels, and name the hardware that can exploit it.
- Define N:M sparsity under the NVIDIA convention, compute its sparsity for any N and M, and explain why the slide's wording is ambiguous.
- Derive the 2:4 compressed layout and compute its memory saving for FP16 and INT8 values.
- State the pro and con of channel pruning and show how pruning one layer's channels shrinks two layers.
- Argue with AMC's measured Pixel 1 numbers why per-layer sparsity ratios beat uniform shrink at equal latency.
Go back to the very first picture of this lecture: a network before and after pruning, with individual synapses cut out while every neuron stays. That picture is fine-grained pruning, the synapse pruning of slide 4 seen through the lens of granularity. Slides 19 and 20 bring it back only to attach numbers to it, so treat them as a short callback rather than new material.
The numbers are the ones from part 02. Han et al. pruned AlexNet from 61 M to 6.7 M parameters and VGG-16 from 138 M to 10.3 M without losing accuracy, a pruning ratio of roughly 89% and 93% (Han, Pool, Tran and Dally, NIPS 2015). Those results are only possible because the method may zero any single weight, wherever it sits in the tensor. The slide calls this "flexible pruning indices": the set of surviving positions is unconstrained, so the algorithm can find redundant weights anywhere and usually reaches the largest compression ratio of all granularities.
| Network | Parameters before | Parameters after | Reduction |
|---|---|---|---|
| AlexNet | 61 M | 6.7 M | 9x |
| VGG-16 | 138 M | 10.3 M | 12x (paper: 13x) |
| GoogleNet | 7 M | 2.0 M | 3.5x |
| ResNet-50 | 26 M | 7.47 M | 3.4x |
Why flexibility is expensive at run time
Now look at what the flexibility leaves behind. After fine-grained pruning the weight tensor still has its original shape; it is simply riddled with zeros at irregular positions. A dense matrix multiply on a GPU does not know the zeros are there and multiplies them anyway, so the work is unchanged. To skip them you must store the weights in a sparse format such as CSR, CSC or COO, where every surviving value carries an index saying where it belongs. Mishra et al. note that these formats make memory accesses data dependent and that the index metadata can cost up to 200% of the weight storage when the weights are 8-bit (Mishra et al., 2021). Zhou et al. summarize the situation in one line: fine-grained sparsity "can achieve a high compression ratio but is not hardware friendly and hence receives limited speed gains" (Zhou et al., ICLR 2021).
That is why the red line on slide 20 matters more than the table. Speedup from fine-grained sparsity needs hardware built around indices. Han's own EIE accelerator is the example the MIT source deck names: by reading compressed weights and skipping zero activations, it ran fully-connected layers 189x faster than a CPU and 13x faster than a GPU running the uncompressed network (Han et al., ISCA 2016). With sparse kernels the picture depends on batch size: in EIE's own measurements cuSPARSE ran pruned FC layers 4x to 9x faster than dense at batch 1 on a Titan X, but slower at batch 64, which is why the slide says "not GPU (easily)". On an ordinary GPU with dense kernels, the same pruned network runs at roughly dense speed.
EIE on compressed fully-connected layers (Han et al., ISCA 2016)
- Speedup over CPU
- 189x
- Speedup over GPU
- 13x
- Energy efficiency over GPU
- 3400x
Recall
Why does fine-grained pruning usually reach a larger compression ratio than channel pruning, and why does that not translate into GPU speedup?
Quick check
A layer is pruned to 90 percent unstructured sparsity and run on a plain GPU with dense kernels. What happens to latency?
Take one row of eight FP16 weights and split it into two groups of four. In each group keep the two largest magnitudes and zero the other two. Every group now has exactly two zeros and two nonzeros, so the row is 50% sparse, and so is every other row treated the same way. That is 2:4 sparsity, the classic case of N:M sparsity and the reason the lecture lists pattern-based pruning as its own step on the granularity spectrum.
The general rule needs one careful sentence, because the slide's sentence is ambiguous. In NVIDIA's definition, which is the one hardware implements, an N:M pattern allows at most N nonzero values in every contiguous group of M. The Ampere whitepaper describes 2:4 as a matrix "that allows two non-zero values in every four-entry vector", and Mishra et al. write of "the 2 nonzero values in each group of 4" (NVIDIA, 2020; Mishra et al., 2021). Slide 21 instead says that "N of them is pruned". For 2:4 the two readings agree, since two kept and two pruned are the same thing. For any other pattern they do not.
Why a pattern is the middle of the spectrum
Inside each group of four the pattern is still fine-grained: any two of the four positions may survive, six possible masks, chosen by magnitude. Across the matrix it is rigidly structured: every group holds exactly two values, no more and no fewer. Mishra et al. point out what this buys: because the sparsity is constant across the matrix, "there is no indirection required; a nonzero value's position in memory can be determined from the compression rate directly" (Mishra et al., 2021). The hardware always knows that group g starts at value slot 2g. That is the difference between a lookup and an address calculation, and it is what makes fine-grained-in-the-small, structured-in-the-large worth a place of its own.
The compressed format
The rule also fixes the storage layout, which is the right-hand panel of slide 21. An R by C dense matrix becomes an R by C/2 block of nonzero values plus an R by C/2 block of 2-bit indices, where each index records the position, 0 to 3, of a kept value inside its group of four. Two bits are enough because a group has only four positions. One corner case keeps the format regular: if a group happens to have three or four zeros after training, two values are stored anyway, padded with zeros as needed (Mishra et al., 2021).
Worked example
Compressing an 8 by 8 FP16 matrix
Dense storage
64 values at 16 bits each: 64 x 16 = 1024 bits.Kept values
Half survive, 32 values: 32 x 16 = 512 bits.Indices
One 2-bit position per kept value: 32 x 2 = 64 bits.Compressed total
512 + 64 = 576 bits.Result
1024 / 576 = 1.78x smaller, 43.75% saved. Per group of four the arithmetic is 64 bits versus 36 bits, which is exact for a matrix of any size.
2:4 storage for FP16 weights, 8 by 8 matrix
- Dense FP16
- 1024 bits
- Kept values
- 512 bits
- 2-bit indices
- 64 bits
- Compressed total
- 576 bits
- Ratio
- 1.78x
- Index overhead on the kept values
- 12.5%
The same matrix with INT8 weights
- Dense INT8
- 512 bits
- Kept values
- 256 bits
- 2-bit indices
- 64 bits
- Compressed total
- 320 bits
- Ratio
- 1.6x
- Index overhead on the kept values
- 25%
The two tables carry an insight that matters when you combine pruning with the quantization lectures: the index costs two bits whatever the value width, so the narrower the value type the more the index costs relatively. Mishra et al. give the same figures, about 44% saved for 16-bit and about 38% for 8-bit weights, which is why NVIDIA says the format cuts storage and bandwidth by "almost" 2x rather than exactly 2x (Mishra et al., 2021; NVIDIA, 2020).
Where the 2x speedup comes from
Storage is only half of the payoff. The Ampere A100 added Sparse Tensor Core instructions that take a 2:4 compressed operand and, in the whitepaper's words, "skip the compute on entries that have zero values, resulting in a doubling of the Tensor Core compute throughput": a 16 x 8 x 16 matrix multiply instruction completes in half the cycles of its dense counterpart (NVIDIA, 2020). Software reaches it through TensorRT 8 and cuSPARSELt; the slide's link covers the TensorRT 8.0 path. Zhou et al. restate the same about 2x for the A100, citing NVIDIA rather than measuring it themselves (Zhou et al., ICLR 2021).
Try the pattern yourself below. Switch the convention from "N nonzero" to "N pruned" at 2:4 and nothing changes; switch it at 1:4 and the sparsity flips from 75% to 25%, which is exactly the ambiguity flagged above. Then toggle FP16 to INT8 and watch the index overhead double.
Recall
Define 2:4 sparsity, give its sparsity percentage, and state the storage layout.
Recall
Under the NVIDIA convention, what is the sparsity of 1:4 and of 4:8?
Quick check
A weight matrix satisfies the 2:4 pattern. What fraction of its weights is zero?
Quick check
Using NVIDIA's convention, how many weights in every group of four are zero under a 1:4 pattern?
A format that halves storage and doubles matmul throughput is worth nothing if the network gets worse. So look at one row first: ResNet-50 on ImageNet scores 76.1% top-1 dense in FP16 and 76.2% after 2:4 pruning. Half the weights are gone and the accuracy is unchanged; the extra 0.1 is run-to-run noise, not a gain.
The rule that produced that row is NVIDIA's three-step recipe. Train the dense network as usual. Prune it to 2:4 by keeping the two largest magnitudes in every group of four, which fixes the mask. Then retrain with the mask held fixed, using the original schedule and hyperparameters, so the survivors absorb the job of the pruned weights. That last step is the fine-tuning loop of part 02 applied under a structural constraint, and the whitepaper reports "virtually no loss in inferencing accuracy" across dozens of networks with it (NVIDIA, 2020). The choice of mask by magnitude inside each group previews the magnitude criterion of part 05.
| Network | Data set | Metric | Dense FP16 | Sparse FP16 | Change |
|---|---|---|---|---|---|
| ResNet-50 | ImageNet | Top-1 | 76.1 | 76.2 | +0.1 |
| ResNeXt-101_32x8d | ImageNet | Top-1 | 79.3 | 79.3 | 0.0 |
| Xception | ImageNet | Top-1 | 79.2 | 79.2 | 0.0 |
| SSD-RN50 | COCO 2017 | bbAP | 24.8 | 24.8 | 0.0 |
| MaskRCNN-RN50 | COCO 2017 | bbAP | 37.9 | 37.9 | 0.0 |
| FairSeq Transformer | EN-DE WMT'14 | BLEU | 28.2 | 28.5 | +0.3 |
| BERT-Large | SQuAD v1.1 | F1 | 91.9 | 91.9 | 0.0 |
Read the table across, never down. The seven rows use four different metrics (top-1 accuracy, box AP, BLEU and F1), so the only meaningful comparison is dense versus sparse within one row. Read that way the evidence is unusually broad: image classification, object detection, instance segmentation, translation and question answering, spanning convolutional networks and Transformers, and not one row lost measurable accuracy. The whitepaper's explanation is that after training "only a subset of weights have acquired a meaningful purpose", and the retraining step lets the network re-adapt around the fixed mask (NVIDIA, 2020).
Recall
Name the three steps of NVIDIA's 2:4 recipe and give one row of evidence that it holds accuracy.
Now the coarse end of the spectrum. A convolution layer with 64 output channels is pruned at sparsity 0.5: thirty-two whole filters are deleted and the layer becomes a 32-channel layer. Nothing about the result is sparse. Its weight tensor, in the [c_o, c_i, k_h, k_w] layout of part 03, is simply smaller in the c_o dimension, and the next layer, which consumed those channels, is smaller in its c_i dimension.
That is the whole argument for channel pruning, and both sides of the slide's trade-off follow from it. Pro: direct speedup on any hardware, because a network with fewer channels does less work in every dense library that exists. Li et al. put it precisely: removing whole filters "does not result in sparse connectivity patterns", so it "does not need the support of sparse convolution libraries and can work with existing efficient BLAS libraries" (Li et al., ICLR 2017). He, Zhang and Sun report a 5x speedup on VGG-16 for a 0.3% increase in error and 2x on ResNet for 1.4% (He, Zhang and Sun, ICCV 2017). Con: a smaller compression ratio, because a channel is a much coarser unit than a weight. Keeping a channel means keeping all of its weights, including the weak ones that fine-grained pruning would have dropped, so you cannot reach the 9x to 13x of slide 20.
Pruning one layer shrinks two
The example above hid a compounding effect that the slide's bar chart depends on. Pruning the output channels of layer l removes rows from its own weight tensor and columns from layer l+1, because the input channels of l+1 are the output channels of l. The per-layer sparsity values on slide 24 therefore do not add up the way they look; they multiply through the chain.
Worked example
Five conv layers, uniform 0.3 versus the slide's per-layer sparsities
Set the baseline
Five stacked 3 x 3 layers, each 64 in and 64 out: 64 x 64 x 9 = 36,864 weights each, 184,320 in total. Layer 0's inputs come from the stem, which is not pruned, so its input columns are never removed.Write the kept fraction of one layer
Layer l keeps (1 - s_(l-1)) x (1 - s_l) of its weights: its input columns follow the previous layer's output sparsity, its output rows follow its own.Uniform shrink, s = 0.3 everywhere
Layer 0 keeps 0.70, every later layer keeps 0.7 x 0.7 = 0.49.Per-layer sparsities 0.5, 0.3, 0.7, 0.2, 0.3
Layer 0 keeps 0.50, then 0.35, 0.21, 0.24, 0.56.Result
Uniform shrink at 0.3 keeps 53.2% of the weights, uniform shrink at the per-layer set's mean of 0.4 keeps 40.8%, and the slide's per-layer set keeps 37.2%. Conv MACs scale with c_i x c_o, so the same fractions apply to compute.
| Layer | Uniform 0.3 kept | Uniform 0.4 kept | Per-layer kept |
|---|---|---|---|
| Layer 0 | 1.0 x 0.7 = 0.70 | 1.0 x 0.6 = 0.60 | 1.0 x 0.5 = 0.50 |
| Layer 1 | 0.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.36 | 0.5 x 0.7 = 0.35 |
| Layer 2 | 0.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.36 | 0.7 x 0.3 = 0.21 |
| Layer 3 | 0.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.36 | 0.3 x 0.8 = 0.24 |
| Layer 4 | 0.7 x 0.7 = 0.49 | 0.6 x 0.6 = 0.36 | 0.8 x 0.7 = 0.56 |
| Total kept | 2.66 / 5 = 53.2% | 2.04 / 5 = 40.8% | 1.86 / 5 = 37.2% |
Uniform shrink versus channel prune
The inequality on slide 24, "Uniform Shrink < Channel Prune", compares accuracy at a comparable budget. Uniform shrink applies one ratio to every layer, which is what a MobileNet width multiplier does. It ignores the fact that layers differ in how much redundancy they carry: some tolerate 70% removal and others only 20%. Channel pruning proper starts from the trained wide network, chooses a ratio per layer, deletes the least useful channels in each, and fine-tunes. Under the same latency or MAC budget, spending the cuts where they hurt least keeps more accuracy. Slide 24 defers the obvious question, how to find those ratios; the sensitivity analysis of lecture 04-2 (Pruning ratios, fine-tuning and sparse hardware) and the AMC search of the next concept are the answers.
Recall
State the pro and con of channel pruning in one sentence each.
Quick check
Which granularity speeds up inference on any GPU that has only dense BLAS libraries?
On a Google Pixel 1, the full-width MobileNet takes 123.3 ms per image and scores 70.6% ImageNet top-1. Shrinking it uniformly with the 0.75 width multiplier brings the latency down to 72.3 ms but the accuracy down to 68.4%. The channel-pruned model found by AMC runs in 68.3 ms at 70.5%: as fast as the shrunken model, 2.1 points more accurate, and only 0.1 below the full model at 1.81x its speed (He et al., ECCV 2018).
AMC (AutoML for Model Compression) is the method behind the red curve on slide 25. It treats the per-layer sparsity ratios as actions for a reinforcement-learning agent, which walks the network layer by layer, proposes a ratio for each, and is rewarded by the accuracy the pruned model reaches under a FLOPs or latency constraint. The pruned model is then fine-tuned. The baseline is the easiest thing one could do instead, which the paper states plainly: "the easiest way to reduce the channels of a model is to use uniform channel shrinkage, i.e. use a width multiplier", and the result is that AMC "consistently outperforms the uniform baselines" (He et al., ECCV 2018).
| Model | MMACs | Top-1 | Pixel 1 latency | Speedup |
|---|---|---|---|---|
| MobileNet 1.0 (full width) | 569 | 70.6% | 123.3 ms | 1.00x |
| MobileNet 0.75 (uniform shrink) | 325 | 68.4% | 72.3 ms | 1.7x |
| AMC, 50% FLOPs budget | 285 | 70.5% | 68.3 ms | 1.81x |
| AMC, 50% latency budget | 272 | 70.2% | 63.3 ms | 1.95x |
The chart on the slide is AMC's Figure 5b. The four table rows above are exact; the remaining points in the table below are read off the figure and are approximate. Either way the shape is the same. At equal latency the searched ratios are about 1.5 to 2 points better. At similar accuracy they are much faster: the 50% latency-budget model keeps 70.2% at 63.3 ms, 1.95x faster than the 123.3 ms full model at 70.6%, only 0.4 points higher.
| Curve | Latency | Top-1 |
|---|---|---|
| Uniform | about 52 ms | about 67.5% |
| Uniform | about 90 ms | about 69.1% |
| AMC | about 52 ms | about 69.2% |
Choosing a granularity for a real board
This is where the part comes together for your project. The granularity you pick is a hardware decision, not a compression decision:
- Target is an Ampere-class or newer NVIDIA GPU (a Jetson Orin, an A100): prune to 2:4. Half the weights, about 2x on the matmuls, accuracy held by retraining.
- Target is a phone CPU, a microcontroller or an NPU with dense kernels only: channel pruning with searched per-layer ratios, AMC style. A smaller dense network is the safest choice, since it needs no special kernels. Some mobile runtimes (XNNPACK) do accelerate high unstructured sparsity in 1x1 convolutions, so check what your runtime supports.
- Target has a sparse accelerator such as EIE, or the constraint is storage and not latency: fine-grained pruning, for the largest compression ratio.
Quick check
Why does channel pruning with per-layer sparsities beat a uniform width multiplier at the same latency?
Recall
Give the AMC versus uniform numbers that show per-layer ratios beat uniform shrink.
Recap
If you remember nothing else
- Fine-grained pruning may zero any weight, so it compresses most (AlexNet 9x, VGG-16 13x) but needs a per-weight index; only custom hardware such as EIE turns that into speed.
- N:M sparsity keeps at most N nonzeros in every contiguous M weights; 2:4 is 50 percent sparse under either reading, but 1:4 is 75 percent (NVIDIA) versus 25 percent (slide wording).
- A 2:4 matrix stores half its values plus 2-bit indices: 36 bits per four FP16 weights instead of 64, about 1.78x, and Ampere Sparse Tensor Cores skip the zeros for about 2x math throughput.
- NVIDIA's train, prune to 2:4, retrain recipe held accuracy on all seven slide-22 tasks (ResNet-50 76.1 to 76.2, BERT-Large 91.9 to 91.9).
- Channel pruning removes whole channels, so the result is a smaller dense network with direct speedup on any hardware, at the cost of a smaller compression ratio.
- Pruning layer l's output channels also shrinks layer l+1's inputs, so per-layer channel sparsities compound in parameters and MACs.
- Uniform shrink applies one ratio everywhere; AMC's searched per-layer ratios give 70.5 percent at 68.3 ms versus 68.4 percent at 72.3 ms for the 0.75 width MobileNet on a Pixel 1.
- Higher sparsity is not faster inference unless the sparsity has a structure the target hardware can exploit.
Sources
- Accelerating Inference with Sparsity Using the NVIDIA Ampere Architecture and NVIDIA TensorRTDocsNVIDIA Developer BlogThe slide's own link: 2:4 definition, the train, prune, retrain recipe, and the seven-row accuracy table.(opens in a new tab)
- NVIDIA A100 Tensor Core GPU ArchitectureDocsNVIDIAPages 31 to 32: 2:4 definition, almost 2x storage saving, Sparse MMA doubling throughput.(opens in a new tab)
- NVIDIA Ampere Architecture In-DepthDocsNVIDIA Developer BlogFine-grained structured sparsity section.(opens in a new tab)
- Accelerating Sparse Deep Neural NetworksPaperMishra et al., arXiv 2021Section 3.1: 2-bit indices, 64 versus 36 bits per group, 44 and 38 percent savings, CSR metadata overhead.(opens in a new tab)
- Learning N:M Fine-grained Structured Sparse Neural Networks From ScratchPaperZhou et al., ICLR 2021Fine-grained sparsity is not hardware friendly; restates NVIDIA's about 2x on the A100 (not independently measured).(opens in a new tab)
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NIPS 2015AlexNet 9x and VGG-16 13x parameter reduction without accuracy loss.(opens in a new tab)
- EIE: Efficient Inference Engine on Compressed Deep Neural NetworkPaperHan et al., ISCA 2016189x over CPU, 13x over GPU, 3400x more energy efficient than GPU, compared with CPU and GPU running the same DNN without compression.(opens in a new tab)
- Efficient Methods and Hardware for Deep LearningBookSong Han, PhD thesis, Stanford 2017Table 3.1: GoogleNet 7 M to 2 M, ResNet-50 25.5 M to 7.47 M.(opens in a new tab)
- Pruning Filters for Efficient ConvNetsPaperLi et al., ICLR 2017Filter pruning needs no sparse libraries; 34 and 38 percent inference cost reduction.(opens in a new tab)
- Channel Pruning for Accelerating Very Deep Neural NetworksPaperHe, Zhang and Sun, ICCV 2017VGG-16 5x speedup at 0.3 percent error increase, ResNet 2x at 1.4 percent.(opens in a new tab)
- AMC: AutoML for Model Compression and Acceleration on Mobile DevicesPaperHe, Lin, Liu, Wang, Li and Han, ECCV 2018Table 4 and Figure 5b: Pixel 1 latencies and the uniform width-multiplier baseline.(opens in a new tab)
- TinyML and Efficient Deep Learning Computing, Lecture 3: Pruning and Sparsity (Part I)DocsMIT 6.5940, Song Han, Fall 2024Source deck for slides 19 to 25, including the '(e.g., EIE)' example dropped from the COE 592 copy.(opens in a new tab)
Part 05: Pruning criteria: magnitude and scaling factors
What makes a parameter less important, magnitude-based importance at element and row level with L1, L2 and general Lp norms, and scaling-based filter pruning that reuses batch normalization gamma factors.
4 concepts, slides 26-33
Why this part matters
Parts 03 and 04 settled the shape of what gets removed: a single weight, a pattern, a row, a whole channel. They never said which one. This part answers that question with the two criteria that run most real pruning: the magnitude of a weight or a group of weights, and a learned scaling factor per channel.
The same computations come back in three places. In a COE 592 exam you will be handed a small matrix and asked for its element-wise and row-wise importances and the pruned result. In code, every call to PyTorch's prune.l1_unstructured or prune.ln_structured does exactly what this part derives by hand. And in your research project, when a channel-pruned model has to justify its accuracy on an embedded board, the batch normalization gamma criterion at the end of this part is the one most practical channel-pruning pipelines actually use.
By the end you can
- State the principle behind every pruning criterion and apply it to a single neuron.
- Compute element-wise importances |W| and produce the pruned matrix for a target sparsity.
- Score rows or channels with L1, L2 and general Lp norms and say which row is pruned.
- Show with numbers when L1 and L2 rank structural sets differently.
- Explain scaling-based pruning and why batch norm gamma is a free channel importance.
Start with one neuron and three inputs. Its output is y = ReLU(10 x_0 - 8 x_1 + 0.1 x_2), and the budget says one of the three connections has to go. Removing the 10 changes the pre-activation by up to 10 |x_0|. Removing the -8 changes it by up to 8 |x_1|. Removing the 0.1 changes it by at most 0.1 |x_2|. If the three inputs are of similar size, the third cut is a hundred times gentler than the first, and that is the one to make.
That small decision contains the whole idea of a Pruning criterion. Pruning asks the network to give up parameters, and the principle the lecture states is simple: the less important the parameters being removed are, the better the performance of the pruned network is. Every criterion in this lecture is a different way of estimating importance, and importance always means the same thing underneath: how much the loss would change if this parameter, or this group, were set to zero. Magnitude, the subject of this part, is the cheapest such estimate. Second-order methods in the next part spend far more compute to estimate the same quantity more carefully (Second-order pruning).
Worked example
Three candidate deletions
Cut the 10
The pre-activation loses 10 x_0. For a typical input this is the largest term in the sum, so the output can flip from firing to silent.Cut the -8
The pre-activation loses -8 x_1. The sign is negative, but the size of the change is 8 |x_1|, almost as large as the first case.Cut the 0.1
The pre-activation loses 0.1 x_2. With inputs of similar scale, this is a rounding error next to the other two terms.Remove the 0.1
The connection with the smallest absolute weight is removed, and y = ReLU(10 x_0 - 8 x_1) is almost the same function as before.
Notice what the example needed to make the decision: nothing but the weights. No data, no gradients, no second run through the training set. That is the appeal of magnitude criteria and also their limit. They answer the Pruning formulation only approximately, because the formulation asks for the smallest increase in loss under a budget on nonzeros, and magnitude is a proxy for loss, not the loss itself. The next three sections make the proxy precise for single weights, for rows, and for whole channels.
Recall
W = [10, -8, 0.1] feeds a ReLU neuron. Which weight goes first, and what assumption makes that answer safe?
Quick check
With W = [10, -8, 0.1] and inputs of similar scale, which weight does magnitude pruning remove first?
Now scale the neuron up to a weight matrix. Take W = [[3, -2], [1, -5]] and a budget of 50 percent Sparsity, which on four weights means exactly two zeros. Write the absolute value of every entry, keep the two largest, zero the rest. The importances are [[3, 2], [1, 5]], the survivors are 3 and -5, and the pruned matrix is [[3, 0], [0, -5]].
This is Magnitude-based pruning at its finest granularity, the fine-grained case from part 03, and it is the criterion of the paper the slides cite. Han, Pool, Tran and Dally train a network, prune every connection whose weight falls below a threshold, and retrain the survivors. Done once, that took AlexNet to 5x fewer parameters; done iteratively, prune then retrain then prune again, it reached 9x on AlexNet (61M to 6.7M) and 13x on VGG-16 (138M to 10.3M) with no loss of accuracy. They also tried the obvious alternative, removing weights at random with probability tied to their magnitude, and report that it gave worse results. Hard thresholding on |w| won.
Worked example
From W to the pruned matrix at 50 percent sparsity
Take absolute values
|W| = [[3, 2], [1, 5]]. The -2 becomes 2 and the -5 becomes 5.Count how many survive
Four weights at 50 percent sparsity means 4 × (1 - 0.5) = 2 survivors.Rank and keep
Sorted importances are 5, 3, 2, 1. Keep the entries scoring 5 and 3, which are the original -5 and 3.Pruned weight
[[3, 0], [0, -5]]. The kept weights keep their signs; only the zeros are new.
In code, this is one call. PyTorch's prune.l1_unstructured(module, name, amount) prunes a tensor by removing the units with the lowest L1 norm, and amount can be a fraction such as 0.5 or an absolute count. The name is exact: on a single element the L1 norm is just its absolute value, so element-wise L1 and |W| are the same criterion, and the slide's label "L1-norm, element-wise" is the same statement as Importance = |W|. Any other p would give the same ranking on single elements, which is why the choice of norm only starts to matter in the next section.
Recall
Compute the element-wise importances of [[3, -2], [1, -5]] and the result at 50 percent sparsity.
Keep the same matrix, [[3, -2], [1, -5]], but change the unit of removal. Instead of two individual entries, remove one whole row. A row of a linear layer's weight matrix is one output neuron's incoming connections, so deleting it is Neuron pruning, and the result is a smaller dense matrix that any library runs faster (Coarse-grained (structured) pruning). The question is how to score a row when it holds several weights of different sizes and signs.
The lecture's answer is to treat the row as a Structural set, written W^(S) for the set S of parameters it contains, and to collapse its absolute values into one number. Two collapses are standard. Add them: the L1-norm importance. Or square them, add, and take the root: the L2-norm importance. Row 0 scores |3| + |-2| = 5 under L1 and sqrt(9 + 4) = sqrt(13) = 3.61 under L2. Row 1 scores |1| + |-5| = 6 and sqrt(1 + 25) = sqrt(26) = 5.10. Both norms rank row 1 higher, so both prune row 0, and the pruned matrix is [[0, 0], [1, -5]].
Worked example
Row-wise scores, both norms
Absolute values first
Row 0 is [3, 2] in magnitude, row 1 is [1, 5].L1: add
Row 0: 3 + 2 = 5. Row 1: 1 + 5 = 6.L2: square, add, root
Row 0: sqrt(9 + 4) = sqrt(13) = 3.61. Row 1: sqrt(1 + 25) = sqrt(26) = 5.10.Compare and zero the loser
Under both norms row 0 scores lower, so every entry of row 0 becomes zero.Pruned weight
[[0, 0], [1, -5]]. Compare with the element-wise result [[3, 0], [0, -5]]: the same Sparsity, a different pattern, because the unit of removal changed.
| Criterion | Row 0 score | Row 1 score | Row pruned | Pruned matrix |
|---|---|---|---|---|
| Element-wise |w| | not a row score | not a row score | none (two smallest elements) | [[3, 0], [0, -5]] |
| Row-wise L1 | 5 | 6 | row 0 | [[0, 0], [1, -5]] |
| Row-wise L2 | sqrt(13) = 3.61 | sqrt(26) = 5.10 | row 0 | [[0, 0], [1, -5]] |
One formula for every p
L1 and L2 are two settings of one dial. Goodfellow, Bengio and Courville define the Lp norm of a vector for any p ≥ 1 as the p-th root of the sum of p-th powers of the absolute values. Set p = 1 and the root and the power vanish, leaving slide 29. Set p = 2 and you get the Euclidean length of slide 30. Slide 31 is the same example under the general formula, not a new method.
When the norm changes the answer
On the slide's matrix L1 and L2 agree, and it is tempting to file the norm as a cosmetic choice. It is not. Compare a row [3, 3] with a row [0, 5] competing for the last surviving slot. L1 scores them 6 against 5 and keeps [3, 3]. L2 scores them sqrt(18) = 4.24 against 5 and keeps [0, 5]. Squaring amplifies the single largest entry, so L2 rewards a row with one dominant weight. Summing treats every unit of magnitude the same, so L1 rewards a row with many moderate weights. Goodfellow et al. describe the same contrast in general terms: the L1 norm grows at the same rate in all locations, while the squared L2 norm increases very slowly near the origin.
| Row | L1 score | L2 score |
|---|---|---|
| [3, 3] | 3 + 3 = 6 | sqrt(9 + 9) = 4.24 |
| [0, 5] | 0 + 5 = 5 | sqrt(0 + 25) = 5 |
| Row kept | [3, 3] | [0, 5] |
Try it yourself. The explorer below scores an editable matrix element-wise or row-wise, always computes both row norms so a disagreement is visible without toggling, and ships with the slide's example and the [3, 3] against [0, 5] case as presets. Change a single entry and watch which row the two norms fight over.
Keeping the top 2 of 4 elements by |w|; the rest become zero. Signs never enter the score. Ties keep the lower index. Achieved sparsity: 50 percent of 4 weights.
Where the row-wise criteria come from
The L1 row score is the criterion of Li et al. Their filter importance is the sum of the absolute kernel weights of a filter, which they describe as an expectation of the magnitude of the output feature map. They remove the m filters with the smallest sums, delete the matching input channels from the next layer, and show that pruning the smallest works better than pruning at random or pruning the largest. On CIFAR-10 this cut inference cost by up to 34 percent for VGG-16 and 38 percent for ResNet-110 with retraining recovering the accuracy. Because a filter is a structural set, this filter pruning is Channel pruning from part 04 with an explicit score attached.
The L2 row score is what Wen et al. put inside training. Their structured sparsity learning adds a group Lasso regularizer to the loss, a sum over groups of sqrt(sum of squared weights in the group), which is exactly the L2 norm of each structural set. The optimizer is then rewarded for driving whole filters, channels, filter shapes or even layers to zero, and they report 5.1x CPU and 3.1x GPU speedups on AlexNet's convolutional layers, and a ResNet on CIFAR-10 shrunk from 20 to 18 layers with accuracy moving from 91.25 to 92.60 percent, still above the original 32-layer ResNet. The difference between the two papers is when the norm is used: Li et al. score a trained network after the fact, Wen et al. shape the network during training so the sets to remove are already near zero.
PyTorch exposes the post-hoc version directly. prune.ln_structured(module, name, amount, n, dim) removes the channels with the lowest Ln norm along the specified dimension; n = 1 or 2 picks the norm, and dim = 0 on a weight of shape [c_o, c_i, k_h, k_w] scores whole filters. Finer structural sets such as a row inside a kernel (Vector-level pruning) use the same formula on a smaller S.
Recall
Row-wise L1 and L2 scores of [[3, -2], [1, -5]], and the pruned result at 50 percent.
Recall
Give two rows where L1 and L2 disagree, with the numbers.
Quick check
Row-wise L1 pruning of [[3, -2], [1, -5]] at 50 percent sparsity removes which row, and why?
Quick check
Rows [3, 3] and [0, 5] compete for one surviving slot. Which row does each norm keep?
A convolution layer has N filters, one per output channel (Convolution weight dimensions). Give each filter a single trainable number, its scaling factor, and multiply that channel's entire output by it. On the slide the factors come out as 1.17, 0.10, 0.29, 0.82, ..., 0.56. Suppose the threshold is 0.3 (the slide only marks the two smallest factors as pruned) and two channels fall below it: filter 1 at 0.10 and filter 2 at 0.29. Delete those filters, delete the input channels that consumed their outputs in the next layer, and what remains is filter 0, filter 3, on to filter N-1: a physically narrower layer.
This is Scaling-based pruning, and it differs from the norms in one important way. A norm scores a trained network after the fact, from the weights alone. A scaling factor is a parameter that training itself sets, so the network is asked, during training, how much it wants each channel. Liu et al. call the method network slimming and make the question sharp by adding an L1 penalty on the factors to the loss.
The L1 penalty is the same L1 from the previous section, now used as a regularizer rather than a score: it charges every unit of |gamma| equally, so factors that the loss does not defend slide all the way to zero. Liu et al. use lambda = 1e-4 for VGGNet and 1e-5 for ResNet and DenseNet on CIFAR. After training they sort every factor in the whole network and set one global threshold at a percentile: pruning 70 percent of channels means the threshold is the 70th percentile of all factors, so layers with many weak channels lose more than layers with strong ones, which is the per-layer Pruning ratio falling out automatically. Then they fine-tune the slimmed network, and can repeat the whole loop.
Network slimming on VGGNet, CIFAR-10, 70 percent of channels pruned (Liu et al., 2017)
- Test error
- 6.34 percent to 6.20 percent
- Parameters
- 20.04M to 2.30M (88.5 percent fewer)
- FLOPs
- 7.97e8 to 3.91e8 (51.0 percent fewer)
- Multi-pass
- up to 20x smaller and 5x less compute
Why the factor is already there: batch norm gamma
Where does the scaling factor live? Liu et al. observe that almost every modern convolution is followed by batch normalization, and batch normalization already contains one. Ioffe and Szegedy normalize each channel of a mini-batch to zero mean and unit variance, then let the network undo that with two learned parameters per channel: a scale gamma and a shift beta. Goodfellow et al. explain why they exist: the normalized activation is replaced by gamma H' + beta so the new variable can have any mean and standard deviation the network wants. That gamma is the Batch normalization scaling factor, one per output channel, and it is the scaling factor the slide reuses.
Two things make gamma the right choice, and both are exam material. First, cost: reusing gamma adds no new parameters and no new layers. Liu et al. say it introduces no overhead, and in PyTorch the vector is already sitting in BatchNorm2d.weight, a learnable parameter of size C initialized to one, next to beta in BatchNorm2d.bias initialized to zero, with epsilon = 1e-5 by default.
Second, and more subtle, meaning. Suppose you skipped batch normalization and simply inserted a scaling layer after the convolution. Convolution is linear and scaling is linear, so the network could halve every factor and double the corresponding filter weights without changing a single output. The factor would then say nothing about importance, because the network can move magnitude freely between the factor and the weights, and an L1 penalty on the factor would be defeated the same way. Liu et al. call such a factor meaningless. Batch normalization breaks the symmetry: the normalized activation has a fixed unit scale regardless of what the filter weights do, so gamma alone sets the size of the channel's output and its magnitude is a genuine measure of how much the channel contributes.
Recall
Why does network slimming reuse batch norm gamma instead of adding a new scaling layer?
Recall
Factors 1.17, 0.10, 0.29, 0.82 and 0.56 with a threshold of 0.3: which filters go?
Quick check
Why does network slimming reuse batch normalization's gamma as the channel scaling factor?
Recap
If you remember nothing else
- A criterion estimates importance. The less important the removed parameters, the better the pruned network performs.
- Magnitude pruning uses absolute value, never the signed weight: -5 is more important than 3.
- Element-wise: Importance = |W|. [[3, -2], [1, -5]] at 50 percent sparsity becomes [[3, 0], [0, -5]].
- Row-wise L1 gives 5 and 6, row-wise L2 gives 3.61 and 5.10. Both prune row 0, giving [[0, 0], [1, -5]].
- General form: ||W^(S)||_p = (sum over i in S of |w_i|^p)^(1/p). L1 favors many moderate weights, L2 favors one dominant weight, as [3, 3] against [0, 5] shows.
- Scaling-based pruning trains one factor per output channel and prunes small |gamma|. Network slimming adds an L1 penalty on gamma and prunes below a global percentile.
- Batch norm gamma is that factor for free: z_o = gamma (z_i - mu_B)/sqrt(sigma_B^2 + epsilon) + beta, one gamma per channel, no extra parameters.
Sources
- Learning both Weights and Connections for Efficient Neural NetworksPaperHan, Pool, Tran and Dally, NeurIPS 2015Threshold on absolute value, threshold as quality parameter times layer std, 9x AlexNet and 13x VGG-16 with iterative pruning(opens in a new tab)
- Pruning Filters for Efficient ConvNetsPaperLi, Kadav, Durdanovic, Samet and Graf, ICLR 2017Filter importance as the sum of absolute kernel weights; smallest beats random and largest; 34 percent VGG-16 and 38 percent ResNet-110 FLOP cuts on CIFAR-10(opens in a new tab)
- Learning Structured Sparsity in Deep Neural NetworksPaperWen, Wu, Wang, Chen and Li, NeurIPS 2016Group Lasso with the L2 norm of each group; filter, channel, shape and depth structures; 5.1x CPU and 3.1x GPU AlexNet conv speedups(opens in a new tab)
- Learning Efficient Convolutional Networks through Network SlimmingPaperLiu, Li, Shen, Huang, Yan and Zhang, ICCV 2017L1 penalty on BN gamma, global percentile threshold, why a bare scaling layer is meaningless, VGGNet CIFAR-10 numbers(opens in a new tab)
- Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate ShiftPaperIoffe and Szegedy, ICML 2015Algorithm 1: mini-batch mean and variance, normalization with epsilon, learned gamma and beta per feature map(opens in a new tab)
- Deep Learning, chapter 2.5: NormsBookGoodfellow, Bengio and Courville, MIT PressLp norm definition (eq. 2.30), L1 versus squared L2 growth, L0 as incorrect terminology(opens in a new tab)
- Deep Learning, section 8.7.1: Batch NormalizationBookGoodfellow, Bengio and Courville, MIT PressWhy gamma and beta are reintroduced after normalization(opens in a new tab)
- torch.nn.utils.prune.l1_unstructuredDocsPyTorch documentationRemoves the units with the lowest L1 norm; amount as a fraction or a count(opens in a new tab)
- torch.nn.utils.prune.ln_structuredDocsPyTorch documentationRemoves channels with the lowest Ln norm along a chosen dimension(opens in a new tab)
- torch.nn.BatchNorm2dDocsPyTorch documentationgamma and beta as learnable vectors of size C, gamma initialized to 1, eps default 1e-5(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, fall 2024DocsMIT HAN LabLectures 3 and 4, Pruning and Sparsity, the source lineage of these slides(opens in a new tab)
Part 06: Second-order, activation and regression criteria
Optimal Brain Damage's Taylor-expansion importance 1/2 h_ii w_i^2, neuron pruning as coarse-grained weight pruning, APoZ activation-sparsity scoring, and regression-based channel pruning that minimizes layer output reconstruction error.
6 concepts, slides 34-43
Why this part matters
Part 05 ranked weights by their absolute value and nothing else. That rule cannot tell a small weight sitting in a steep valley of the loss from a small weight resting on a flat plain, and only one of those two is safe to delete. This part gives you three criteria that look past the weight value to what actually happens when the weight is gone.
The first reads the curvature of the loss: Optimal Brain Damage from 1989, the root of the SparseGPT-style methods that prune large language models today. The second reads the activations: APoZ, the cheapest data-driven structured criterion you can run before deploying on an embedded board. The third reads the layer output itself: regression-based channel pruning, the basis of the pipelines used to shrink networks for edge accelerators. All three are standard exam derivations, and the reasoning behind them is what you will reuse when your research project has to justify a pruning choice.
By the end you can
- Derive the OBD importance 1/2 h_ii w_i^2 from the Taylor expansion and name the assumption that removes each term.
- Explain why magnitude pruning is OBD with a constant Hessian diagonal, and show a case where the two rankings disagree.
- Compute APoZ for a channel from its activation maps and decide which channel to prune.
- State the regression-based channel pruning objective, its L0 constraint and the two alternating LASSO and least-squares steps.
- Place each criterion in the reference list and say what data it needs.
Start with a trained network and its loss L(x; W). Setting one weight to zero moves the parameter vector from W to W_P = W + δW, where δW is zero everywhere except at the pruned position, where δw_i = -w_i. The question every criterion in this part is trying to answer is simple: how much does the loss move? You could answer it exactly by re-evaluating the loss after each candidate deletion, but LeCun, Denker and Solla call that approach prohibitively laborious, and for a network with thousands of weights it is. Second-order pruning builds a local model of the loss instead.
One weight before the general case. A weight sits at w = 0.5 in a valley of the loss surface given by L(w) = 1 + 2(w - 0.5)². Setting it to zero walks back to w = 0 and raises the loss from 1 to 1.5, and that rise is exactly ½ h w² with curvature h = 4: the gradient at the bottom of the valley is zero, so the first-order term contributes nothing and the curvature term contributes everything. Now scale the picture up to a whole parameter vector. The local model is a Taylor expansion of the loss around the trained point. Perturbing the weights by δW changes the loss by a first-order slope term, a second-order curvature term, and a remainder that shrinks as the cube of the perturbation.
Read the four pieces one at a time. The first sum is the slope: how fast the loss rises if you nudge each weight on its own. The second sum is the self-curvature: how quickly that slope itself changes along each weight's own axis, weighted by the square of the nudge. The third sum is the cross-curvature: whether moving weight i also tilts the loss along weight j. The last piece is everything the quadratic picture misses. The Hessian is the matrix that holds the second and third pieces together: its diagonal h_ii feeds the self-curvature sum and its off-diagonal h_ij feeds the cross terms.
Goodfellow, Bengio and Courville define the Hessian exactly this way, as the matrix with entries ∂²f/(∂x_i ∂x_j), and note that it is symmetric wherever the second partials are continuous. The cross sum runs over ordered pairs i ≠ j, so each unordered pair appears twice, once as (i, j) and once as (j, i); the one half in front is the second-order Taylor coefficient from ½ δWᵀ H δW, not a symmetry correction. Because H is symmetric the same term can be written without the one half as Σ_{i < j} h_ij δw_i δw_j. They also use this same second-order expansion to derive Newton's method, so the expression on the slide is not a pruning trick: it is the standard local model of any smooth function.
How big the Hessian is for the OBD zip-code network (LeCun et al., 1989, p. 600)
- Parameters
- about 2600 (2578 free parameters)
- Full Hessian entries
- about 6.5 × 10⁶, the figure the paper quotes
- Diagonal entries
- about 2600, one per parameter
The table is the reason the rest of this part exists. Even a 1989 network with about 2600parameters has millions of Hessian entries, and a modern network with 10⁸ weights would have 10¹⁶. Nobody computes that matrix. The whole art of second-order pruning is deciding which of its entries you can afford to ignore.
Recall
Write the second-order Taylor expansion of the loss change and name what each of its four pieces measures.
Four terms is three too many. Optimal Brain Damage keeps the expansion usable by making three assumptions, and each one erases exactly one piece of the sum. The paper gives them names, the slide gives them plain-language bullets, and you should be able to match the two lists and say which term each one kills.
| OBD name | Slide wording | Term removed | Why it is allowed |
|---|---|---|---|
| Quadratic | L is nearly quadratic | O(||δW||³) | Near the minimum the loss surface is well described by its curvature alone, so the cubic remainder is negligible. |
| Extremal | Training has converged | Σ gᵢ δwᵢ | At a local minimum every partial derivative is zero, so the whole first-order sum vanishes and every hᵢᵢ is non-negative. |
| Diagonal | Deletion errors are independent | ½ Σᵢ≠ⱼ hᵢⱼ δwᵢ δwⱼ | The cost of deleting several weights is taken as the sum of their individual costs, which is exactly what dropping the off-diagonal terms means. |
The extremal assumption does double duty. Because training stopped at a local minimum, the gradient is zero and the first sum disappears, but LeCun, Denker and Solla also point out that at a local minimum all the h_ii are non-negative, so any perturbation of the parameters will cause the loss to increase or stay the same. That single sentence is the source of the footnote on slide 36 that h_ii is non-negative, and it is what lets the surviving term serve as a cost rather than a signed change.
What survives is the diagonal curvature term alone. Deleting weight i means setting it to zero and, in the paper's words, freezing it there, so the step along that axis has the size of the weight itself, |δw_i| = |w_i|. The squared terms of the expansion do not care about the sign of δw_i, so substitute and you have the OBD estimate of the loss increase.
The paper calls this quantity the saliency of a parameter, s_k = h_kk w_k² / 2 (the paper writes its parameter as u_k, the same variable as the w_k used on the slide and here), and the recipe is to delete the parameters with the lowest saliency. Notice what the formula says about a weight's importance: it is the product of two things, how large the weight is and how sharply the loss curves along that weight's axis. Magnitude pruning from part 05 kept only the first factor.
Magnitude pruning is OBD with the curvature assumed constant
Suppose every h_ii were the same number h. Then importance would be (h/2) w_i², and ranking weights by that value is exactly ranking them by |w_i|, since squaring and scaling by a positive constant preserve the order. So Magnitude-based pruning is OBD under a fourth, hidden assumption: that the loss curves equally steeply along every weight. The 1989 paper states its goal as moving beyond the approximation that magnitude equals saliency, and the point of a second-order criterion is to drop that assumption. The table below is a small case where doing so changes the answer.
| Weight | wᵢ | hᵢᵢ | |wᵢ| | ½ hᵢᵢ wᵢ² | Magnitude | OBD |
|---|---|---|---|---|---|---|
| A | 1.5 | 0.2 | 1.5 | 0.225 | keep | prune |
| B | 1.0 | 1.0 | 1.0 | 0.5 | keep | keep |
| C | -0.6 | 4.0 | 0.6 | 0.72 | keep | keep |
| D | 0.5 | 8.0 | 0.5 | 1.0 | prune | keep |
| E | 0.2 | 2.0 | 0.2 | 0.04 | prune | prune |
Worked example
Five weights, two rankings, prune two
Square each weight
1.5² = 2.25, 1.0² = 1.0, (-0.6)² = 0.36, 0.5² = 0.25, 0.2² = 0.04. The sign of C disappears, as it does in |w|.Multiply by the curvature and halve
A: ½ × 0.2 × 2.25 = 0.225, B: ½ × 1.0 × 1.0 = 0.5, C: ½ × 4.0 × 0.36 = 0.72, D: ½ × 8.0 × 0.25 = 1.0, E: ½ × 2.0 × 0.04 = 0.04.Rank by each criterion, lowest first
Magnitude: E, D, C, B, A. Saliency: E, A, B, C, D.Pruning two weights
Both criteria delete E. Magnitude then deletes D, the weight OBD rates as the most important of all five. OBD deletes A instead, the largest weight in the set, because it sits on almost flat ground.
| Weight | w_i | h_ii | |w_i| | ½ h_ii w_i² | mag rank | magnitude | obd rank | obd |
|---|---|---|---|---|---|---|---|---|
| A | 1.5 | 0.225 | 5 | keep | 2 | prune | ||
| B | 1 | 0.5 | 4 | keep | 3 | keep | ||
| C | 0.6 | 0.72 | 3 | keep | 4 | keep | ||
| D | 0.5 | 1 | 2 | prune | 5 | keep | ||
| E | 0.2 | 0.04 | 1 | prune | 1 | prune |
Set every h_ii in the table to the same value and watch the two decision columns fall into line. Then give a small weight a large curvature and watch them split again. That is the entire relationship between the two criteria in one gesture.
Why the slide says the Hessian is difficult
The full Hessian has n² entries, and the previous concept showed that this is out of reach even for a small network. OBD never computes it. The diagonal approximation means only the n entries h_ii are needed, and the paper derives a second back-propagation pass that computes them with, in its words, the same order of complexity as computing the gradient. Along the way it drops the terms involving the second derivative of the activation function, a Levenberg-Marquardt style approximation that gives guaranteed positive estimates of the second derivative. So the difficulty the slide flags is real for the full matrix and for networks with 10⁸ parameters, where even a diagonal pass over the whole training set is expensive, but it is not a reason OBD itself was impractical. Optimal Brain Surgeon (Hassibi and Stork, 1993) kept the cross terms by using the inverse of the full Hessian. SparseGPT (2023) makes second-order pruning practical at scale by solving layer-wise reconstruction problems with block-wise Hessian updates, which the final concept points to.
The recipe and what it achieved
The abstract on the slide states the motivation the formula serves. Deleting unimportant weights is a trade-off between network complexity and training-set error, and the paper expects better generalization, fewer training examples required and faster learning and classification from it. That is why the recipe below is framed as model selection, not only compression.
- Choose a reasonable network architecture.
- Train the network until reasonable convergence.
- Compute the second derivatives h_kk for each parameter.
- Compute the saliencies s_k = h_kk w_k² / 2.
- Sort the parameters by saliency and delete some low-saliency parameters.
- Return to step 2.
The loop back to training is the Iterative pruning and Fine-tuning pattern from part 02, thirty years earlier. The 1989 experiment applied it to a handwritten zip-code recognizer.
Optimal Brain Damage results (LeCun, Denker and Solla, 1989)
- Setup
- about 10⁵ connections controlled by 2578 free parameters, trained on roughly 9300 digits and tested on 3350
- Prediction quality
- The quadratic, extremal, diagonal estimate tracks the measured loss up to about 800 deleted parameters, roughly 30%; beyond that the cross terms and higher-order terms the approximation dropped start to matter
- After retraining
- Up to 1500 parameters, about 60%, deleted with almost unchanged training and test error
- Versus magnitude
- Deleting in order of saliency causes a significantly smaller increase of the objective than deleting by magnitude (figure 1a)
- Versus random
- Random deletion was so much worse it could not be plotted on the same scale
- Venue
- Advances in Neural Information Processing Systems 2 (NIPS 1989), AT&T Bell Laboratories, Holmdel NJ
Quick check
Under OBD, which assumption removes the first-order gradient term from the Taylor expansion?
Quick check
Weight A has w = 1.0 and h = 1; weight B has w = 0.5 and h = 8. Which does OBD keep first?
Recall
Why is magnitude pruning a special case of OBD?
Everything so far scored individual synapses. Take a linear layer with 5 inputs and 4 outputs, so its weight matrix has shape [4, 5]. Deleting the second output neuron does not zero one entry; it removes the entire row W[1, :], all 5 incoming weights at once, along with the edges drawn into that neuron on the slide, which is why the lower layer shows three circles with a gap where the fourth stood. The matrix becomes [3, 5], a smaller dense matrix, which is the reason Coarse-grained (structured) pruning gives real speedup without any sparse format.
That is the whole content of the sentence on the slide: Neuron pruning is coarse-grained weight pruning. In a convolution layer with weights of shape [c_o, c_i, k_h, k_w] (recall Convolution weight dimensions), deleting output channel o deletes W[o, :, :, :], one full row of c_i kernels in the slide's grid, where rows 3 and 5 of six filters are blanked out. It also deletes the corresponding map from the layer's output, and therefore the input channel o of every filter in the next layer, a point He et al. make explicitly in their figure. Channel pruning cuts twice.
| Unit removed | Slice deleted | Weights deleted | Shape after |
|---|---|---|---|
| Output neuron of a linear layer | W[o, :] | One row: all incoming weights of that neuron | [c_o - 1, c_i] |
| Output channel (filter) of a conv layer | W[o, :, :, :] | c_i kernels of k_h × k_w each | [c_o - 1, c_i, k_h, k_w] |
| Input channel of the next conv layer | W[:, o, :, :] | c_o kernels, one per filter, that read the removed map | [c_o, c_i - 1, k_h, k_w] |
The rule on the slide is then almost a tautology: the less useful the removed neurons are, the better the pruned network performs. The work is in defining useful. The Pruning criterion question has simply moved up one level of granularity, and part 05 already gave one answer, the L1 or L2 norm of the row or filter. The next two concepts give two answers that need no Hessian and no norm: look at the activations the neuron produces, or look at how well the layer output can be rebuilt without it.
Recall
A linear layer has weight shape [8, 16]. You prune three output neurons. How many weights disappear and what is the new shape?
ReLU outputs zero for every negative pre-activation. A channel whose output map is mostly zero, image after image, contributes almost nothing to the layer that follows, whatever its weights look like. Hu, Peng, Tai and Tang turned that observation into a criterion. On VGG-16 they found 631 neurons whose activations were zero more than 90% of the time on ImageNet validation images, and they found that the mean fraction of zeros is far higher in the deeper convolutional layers and the fully connected layers than in the early layers, so most of the redundancy sits at the top of the network.
| Layer | Mean APoZ |
|---|---|
| CONV1-1 | 47.07% |
| CONV3-3 | 69.93% |
| CONV4-3 | 87.30% |
| CONV5-3 | 93.19% |
| FC6 | 75.26% |
| FC7 | 74.14% |
The score is the APoZ. For channel c of a layer, run N validation images through the network, look at every position of the H × W output map for every image, and count how often the value is exactly zero. Divide by the number of positions you looked at.
The slide writes the same thing as zeros divided by batch times height times width. Its example uses a batch of 2, three channels and 4 × 4 maps, so every channel is judged over 2 × 4 × 4 = 32 positions. Count the bold zeros in each grid and the numbers on the slide come out exactly.
Worked example
APoZ for the three channels on the slide
Count zeros per channel in batch 1
Channel 0: 5. Channel 1: 5. Channel 2: 6.Count zeros per channel in batch 2
Channel 0: 6. Channel 1: 7. Channel 2: 8.Divide the totals by 2 x 4 x 4 = 32
Channel 0: 11/32 = 0.344. Channel 1: 12/32 = 0.375. Channel 2: 14/32 = 0.438.Channel 2 is pruned
Smaller APoZ means a more important channel. Channel 2 is silent most often, so it is the one crossed out on the slide; channels 0 and 1 are kept.
Zero counts verified against the slide grids
- Channel 0
- 5 + 6 = 11 zeros, APoZ 11/32 = 34.4%
- Channel 1
- 5 + 7 = 12 zeros, APoZ 12/32 = 37.5%
- Channel 2
- 6 + 8 = 14 zeros, APoZ 14/32 = 43.8%
- Denominator
- batch 2 × height 4 × width 4 = 32
Each grid is one 4 × 4 output map after ReLU. A zero cell is a position where the pre-activation was negative. Switch batches to edit the other 16 positions of the same channel.
| Channel | zeros b1 | zeros b2 | total | APoZ | bar | decision |
|---|---|---|---|---|---|---|
| Channel 0 | 5 | 6 | 11/32 | 34.4% | keep | |
| Channel 1 | 5 | 7 | 12/32 | 37.5% | keep | |
| Channel 2 | 6 | 8 | 14/32 | 43.8% | prune |
APoZ_c = (z_c,1 + z_c,2) / (2 × 4 × 4)
Direction is the only thing people get wrong here, so state it in words: importance falls as APoZ rises. The paper's operating rule, the procedure it names Network Trimming, is to trim the neurons whose APoZ is more than one standard deviation above the layer's mean, which under a Gaussian assumption on APoZ values rejects about 16% of the neurons in a trimmed layer on average. Trimming is iterative: prune a few high-APoZ layers, retrain with the surviving weights initialized from the pre-trim network rather than from scratch, and repeat. The authors show that training the trimmed architecture from scratch leaves more zero-activation neurons than initializing from the trimmed weights does, so the initialization matters.
Network Trimming results (Hu et al., 2016)
- LeNet on MNIST
- 20-50-500-10 trimmed to 20-24-252-10, 3.85× fewer parameters, accuracy 99.31% to 99.26%
- VGG-16, trim CONV5-3 and FC6
- Top-5 85.900% before retraining, 90.278% after, above the original 88.444%
- VGG-16, trim CONV4, CONV5, FC6, FC7 at once
- Top-5 falls to 46.650% before retraining, the reason trimming is done a few layers at a time
- Validation set
- ImageNet, N = 50,000 images per APoZ measurement
| Criterion | Reads | Cost | Granularity | Score |
|---|---|---|---|---|
| Magnitude (part 05) | Weight values only | None, read the tensor | Any | |w|, Lp norm of a structural set |
| OBD | Weights and hᵢᵢ from a second backward pass | About one gradient computation | Weight | ½ hᵢᵢ wᵢ² |
| APoZ | ReLU outputs on a validation set | One forward pass over N images | Neuron or channel | Fraction of zero activations |
| Regression | Sampled layer inputs and outputs | LASSO plus least squares per layer | Input channel | Reconstruction error of Z |
The comparison shows a split that matters for your project. Magnitude and OBD are read off the weights and their derivatives. APoZ and the regression criterion of the next concept are data-driven: they need a forward pass over real inputs, so they capture what the network does on your data rather than what its parameters look like, at the price of needing that data available at pruning time.
Quick check
Over a batch of 2 with 4 x 4 maps, channel 2 has 14 zeros and channel 0 has 11. Which is pruned under APoZ?
Recall
What is the Network Trimming operating threshold, what fraction of a layer's neurons does it remove on average, and why does retraining start from the pre-trim weights?
OBD asked what pruning does to the loss. APoZ looked at what a channel emits. He, Zhang and Sun ask a third question that is easier to answer than the first and more precise than the second: after you remove some input channels of a layer, how well can the survivors reproduce the layer's original output? Take one conv layer and sample b positions from real images (the paper used 5000 images with 10 samples each). Unroll each receptive field into a row of a matrix X of shape b × c_i in the slide's simplified picture. The layer's output at those positions is a matrix multiply.
The second equality is the whole idea. A matrix product can be split by the shared dimension: column c of X times row c of W^T is one b × c_o outer product, and Z is the sum of c_i of them, one per input channel. Removing input channel c means removing exactly one term of that sum. Regression-based pruning attaches a switch β_c to each term and asks which switches can be turned off while keeping the sum close to the original.
Name every symbol. β is the Channel selection coefficient, a vector of length c_i; β_c = 0 prunes input channel c. N_c is the number of channels allowed to survive, so the L0 norm constraint counts nonzero switches, the same kind of constraint as the pruning formulation of part 01. The objective is the Reconstruction error: the Frobenius norm is the square root of the sum of all squared entries, so its square is just the elementwise squared error summed over the whole b × c_o output. Nothing about the network loss, the labels or the layers downstream appears anywhere.
The figure on the slide shows why the input side is the one that shrinks. X_P loses a column and W_P^T loses the row that multiplied it; the two disappear as a pair, because they were only ever used together. The output Ẑ still has b rows and c_o columns. The next layer sees an input of the same shape as before, only slightly perturbed, which is what lets the paper prune a very deep network layer by layer and account for the accumulated error by always regressing toward the un-pruned model's output.
Solving it: alternate between selecting and rebuilding
The L0 constraint makes the problem NP-hard, so the paper relaxes it to an L1 penalty, adding λ ||β||₁ to the objective. That turns channel selection into LASSO regression, whose solutions are naturally sparse: as λ grows, more β_c are driven exactly to zero. With two unknowns, β and W, the paper alternates.
| Step | Fixed | Solved | Solver | Output |
|---|---|---|---|---|
| 1 | W | β | LASSO (L1-relaxed selection) | Which input channels survive |
| 2 | β | W | Least squares (closed form) | Weights that best rebuild Z from the survivors |
With W fixed, Ẑ is linear in β, so the objective is an ordinary least-squares fit in β and the added L1 penalty makes it a LASSO problem that picks the channels. With β fixed, the survivors' weights are re-fitted by ordinary least squares so that they rebuild Z as well as possible, in closed form. A constraint ||W_c||_F = 1 on each channel's weights stops the trivial solution of shrinking β while inflating W. In practice the authors run the selection step repeatedly, raising λ until ||β||₀ drops to the target, and then run the reconstruction step once.
Channel pruning results (He, Zhang and Sun, ICCV 2017)
- VGG-16
- 4× speedup with 1.0% increase in top-5 error; 5× with tensor factorization at 0.3%
- ResNet-50 and Xception-50
- 2× speedup at 1.4% and 1.0% extra top-5 error
- Fine-tuning
- 10 epochs, batch 128, learning rate 10⁻⁵
- Samples for regression
- 5000 images × 10 positions each
Quick check
In regression-based channel pruning, what does setting beta_c = 0 do?
Recall
State the regression-based pruning objective and its two alternating steps.
The reference list at the end of the deck is a map of where every Pruning criterion in parts 05 and 06 came from, and of what comes next. Reading it as a family tree makes the lecture easier to hold in memory than reading it as nineteen unrelated titles.
| Criterion | What it reads | Ref | Paper | Where taught |
|---|---|---|---|---|
| Magnitude | Weight values | 4 | Han et al., NeurIPS 2015 | Part 05 |
| Scaling factor | Trainable γ per channel | 11 | Liu et al., Network Slimming, ICCV 2017 | Part 05 |
| Second order | Loss curvature hᵢᵢ | 3 | LeCun, Denker, Solla, NeurIPS 1989 | This part |
| Second order, modern | Hessian of a layer-wise reconstruction | 18 | Frantar and Alistarh, SparseGPT, 2023 | Pointer |
| Activation | Zero fraction after ReLU | 14 | Hu et al., Network Trimming, 2016 | This part |
| Regression | Layer output reconstruction | 16 | He, Zhang, Sun, ICCV 2017 | This part |
| Next-layer statistics | Next layer's reconstruction | 17 | Luo, Wu, Lin, ThiNet, ICCV 2017 | Pointer |
| First-order Taylor | Gradient times value on mini-batches | 15, 13 | Molchanov et al., ICLR 2017 and CVPR 2019 | Pointer |
Three of the pointers deserve a sentence each. SparseGPT is the modern descendant of Second-order pruning: it prunes GPT-scale models with 175 billion parameters in one shot to 50 to 60% unstructured sparsity with little loss in perplexity, using Hessian information of a layer-wise reconstruction problem very much like the one in the previous concept. ThiNet selects filters using statistics from the next layer rather than the current one, a cousin of Regression-based pruning. Molchanov's first-order Taylor criterion scores units by gradient times value on mini-batches. It is the same expansion as OBD with the gradient term kept and the Hessian dropped.
Recall
Given the criterion, name the paper and what it reads: magnitude, OBD, APoZ, regression.
Recall
Which of the criteria in this part need data pushed through the network, and which read only the parameters?
Recap
If you remember nothing else
- Pruning is a perturbation delta W. Its loss cost is approximated by a second-order Taylor expansion with a gradient term, a diagonal Hessian term, cross terms and a cubic remainder.
- OBD keeps only 1/2 h_ii w_i^2: the quadratic assumption removes the remainder, convergence removes the gradient term, independent deletions remove the cross terms; h_ii is non-negative at a minimum.
- Magnitude pruning is OBD with every h_ii equal. The full Hessian has n^2 entries; OBD computes only the diagonal by a second back-propagation pass.
- Removing a neuron deletes a row of a linear weight matrix; removing a conv channel deletes a whole filter. Neuron pruning is coarse-grained weight pruning.
- APoZ = zeros / (batch x H x W). The slide's channels score 11/32, 12/32 and 14/32 and the largest, channel 2, is pruned. Smaller APoZ means more important.
- Regression-based pruning minimizes ||Z - sum_c beta_c X_c W_c^T||_F^2 subject to ||beta||_0 <= N_c, alternating LASSO channel selection and least-squares reconstruction. VGG-16 reached 4x speedup at 1.0 percent extra top-5 error.
- Slide errata: the h_ii denominator on slide 36, the sign convention on slide 34, Network Trimming is 2016 not 2017, and the 'more importance' typo on slide 40.
Sources
- Optimal Brain DamagePaperAdvances in Neural Information Processing Systems 2 (NIPS 1989), LeCun, Denker and SollaTaylor expansion (eq. 1 to 3), non-negative h_ii at a minimum, 6.5 million Hessian entries, Levenberg-Marquardt estimate, recipe and saliency, zip-code experiments.(opens in a new tab)
- Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep ArchitecturesPaperarXiv 1607.03250, Hu, Peng, Tai and Tang, 2016APoZ definition (eq. 1), mean APoZ per layer (Table 1), 631 neurons above 90 percent, mean plus one standard deviation threshold, LeNet and VGG-16 results.(opens in a new tab)
- Channel Pruning for Accelerating Very Deep Neural NetworksPaperICCV 2017, He, Zhang and Sun (arXiv 1707.06168)Objective (eq. 1 to 4), NP-hardness and L1 relaxation, unit Frobenius norm constraint, alternating LASSO and least squares, 5000 images times 10 samples, VGG-16 and ResNet-50 results.(opens in a new tab)
- Deep Learning, chapter 4: Numerical ComputationBookMIT Press, Goodfellow, Bengio and Courville, 2016Hessian definition (eq. 4.6), symmetry (eq. 4.7), second-order Taylor expansion used for Newton's method (eq. 4.11).(opens in a new tab)
- Learning both Weights and Connections for Efficient Neural NetworksPaperNIPS 2015, Han, Pool, Tran and DallyMagnitude criterion baseline referenced as item 4 on slide 43.(opens in a new tab)
- Pruning Convolutional Neural Networks for Resource Efficient InferencePaperICLR 2017, Molchanov, Tyree, Karras, Aila and KautzFirst-order Taylor criterion, pointer only.(opens in a new tab)
- ThiNet: A Filter Level Pruning Method for Deep Neural Network CompressionPaperICCV 2017, Luo, Wu and LinFilter selection using statistics of the next layer, pointer only.(opens in a new tab)
- SparseGPT: Massive Language Models Can Be Accurately Pruned in One-ShotPaperarXiv 2301.00774, Frantar and Alistarh, 2023One-shot pruning of 175B-parameter models to 50 to 60 percent sparsity, the modern descendant of second-order pruning.(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Fall 2024, Lecture 3: Pruning and Sparsity (Part I)DocsMIT HAN Lab, Song HanThe course deck these slides follow, listed as reference 19.(opens in a new tab)