Majid Al-RaimiFull guide

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
Understood
0/29 concepts

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

  1. Name the four decisions of the pruning pipeline and say which ones this lecture covers.
  2. Reproduce the 45 nm energy ladder and argue with numbers why DRAM traffic, not arithmetic, dominates.
  3. Distinguish synapse pruning from neuron pruning and state what each does to a layer's weight matrix.
  4. Write the pruning formulation with a less-or-equal budget, name every symbol, and explain why the L0 constraint forces heuristic criteria.
  5. Describe the brain's overprovision-then-prune curve and use it as motivation, not as proof, for network pruning.

Pruning is a pipeline of four decisions

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.

Formulate
This part

Loss under an L0 budget

Granularity
Parts 03 to 04

What pattern to remove

Criterion
Parts 05 to 06

Which synapses or neurons

Ratio
Lecture 04-2

Sparsity per layer

Fine-tune
Lecture 04-2

Recover the accuracy

The pruning pipeline: the formulation plus four decisions, taught across two lectures
DecisionQuestion the slide asksWhere it is taught
FormulateWhat is pruning? How should we formulate pruning?This part
GranularityIn what pattern should we prune the neural network?Parts 03 and 04
CriterionWhat synapses or neurons should we prune?Parts 05 and 06
RatioWhat should target sparsity be for each layer?Lecture 04-2
Fine-tune or trainHow should we improve performance of pruned models?Part 02 previews it; Lecture 04-2
The outline slide as a table: each decision, the question the slide attaches to it, and where it is taught

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?

Granularity (in what pattern to prune), criterion (which synapses or neurons to prune), ratio (what target sparsity each layer gets), and fine-tuning or training the pruned network. Ratio and fine-tuning are 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.

OperationEnergyRelative to int ADD
32-bit int ADD0.1 pJ1x
32-bit float ADD0.9 pJ9x
32-bit register file1 pJ10x
32-bit int MULT3.1 pJ31x
32-bit float MULT3.7 pJ37x
32-bit SRAM cache5 pJ50x
32-bit DRAM memory640 pJ6400x
Rough energy per 32-bit operation, 45 nm, 0.9 V (Horowitz 2014 via Han et al. 2015)
Seven energies on a log axis: six short bars for arithmetic and on-chip storage, one bar nearly four decades long for DRAM. The arrow reads off 640 / 3.1, about 206x.

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
EDRAMEint MULT=640 pJ3.1 pJ206\frac{E_{\text{DRAM}}}{E_{\text{int MULT}}} = \frac{640\ \text{pJ}}{3.1\ \text{pJ}} \approx 206
One weight fetch buys about two hundred multiplies

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)

  1. 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.
  2. Price each fetch

    2 × 10^10 × 640 pJ = 12.8 J every second, so 12.8 W.
  3. 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

  1. Dense: memory

    10^6 weights fetched once each from DRAM: 10^6 × 640 pJ = 640 µJ.
  2. Dense: arithmetic

    One float multiply and one float add per weight: 10^6 × (3.7 + 0.9) pJ = 4.6 µJ.
  3. 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.
  4. Pruned: keep 100,000 weights

    Fetch 10^5 × 640 pJ = 64 µJ, compute 10^5 × 4.6 pJ = 0.46 µJ.
  5. 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.
QuantityDense, 10^6 weightsPruned, 10^5 weights
DRAM fetch energy640 µJ64 µJ
MAC energy4.6 µJ0.46 µJ
Total per inference644.6 µJ64.46 µJ
Share from memory99.3%99.3%
The same layer dense and 90 percent pruned

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.

ModelBeforeAfterRatio
AlexNet240 MB6.9 MB35x
VGG-16552 MB11.3 MB49x
Model size before and after Deep Compression (Han, Mao and Dally 2016)

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.

SimulatorMemory energy budget: weights, sparsity and where they live
Presets
each kept weight is fetched once per inference and used in one MAC (4.6 pJ)
Energy per inference39.32mJ61 M kept weights × (640 pJ + 4.6 pJ)
Power at 20 Hz786.41mWmemory alone 780.8 mW
Share spent on memory99.3%39.04 mJ of 39.32 mJ
Model size (fp32)244MBvs dense in DRAM: 1x less energy

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?

640 pJ versus 3.1 pJ, so 640 / 3.1 ≈ 206, about 200x. Against the 0.1 pJ integer add it is 6400x.

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.

First the synapses: thirteen of the 38 edges fade while every node stays. Then the neurons: one node in each hidden layer collapses and the thirteen edges still attached to them go with it, leaving exactly the slide's 5-3-2-2 network with its twelve edges.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
ChoiceWeights removedShapes afterSparse or dense
Prune 6 synapses63 × 4 and 2 × 3, unchangedSparse: 6 zeros scattered inside a 3 × 4 matrix
Prune neuron 24 + 2 = 62 × 4 and 2 × 2Dense: both matrices simply got smaller
Six weights removed, two ways

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?

Row 2 of the first matrix (4 weights) and column 2 of the second (2 weights): 6 weights. The layers become 2 × 4 and 2 × 2, both still dense.

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?

argminW  L(x;W)\underset{\mathbf{W}}{\arg\min}\; L(\mathbf{x};\, \mathbf{W})
Ordinary training: minimize the loss with no constraint on the weights
argminWP  L(x;WP)s.t.WP0N\underset{\mathbf{W}_P}{\arg\min}\; L(\mathbf{x};\, \mathbf{W}_P) \quad \text{s.t.} \quad \lVert \mathbf{W}_P \rVert_0 \le N
Pruning: the same loss, but only weight vectors with at most N nonzeros are admissible

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
A 4 × 6 weight matrix under a budget of N = 8. The sixteen smallest magnitudes are zeroed one rank at a time, the eight largest survive, and the counter drops from 24 nonzeros to 8: a hard count constraint being met, not a soft shrink.

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

sparsity=1NW\text{sparsity} = 1 - \frac{N}{|\mathbf{W}|}
The fraction of weights that are zero, equal to the pruning ratio when everything below the budget is removed

Worked example

AlexNet under Han et al. (2015)

  1. Count

    AlexNet has |W| = 61 M parameters. Han et al. prune it to N = 6.7 M.
  2. Sparsity

    1 - 6.7 / 61 = 1 - 0.11 = 0.89, so 89% of the weights are zero.
  3. 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?

||W||_0 is piecewise constant, so its gradient is zero almost everywhere and undefined at zero, and it is not a true norm since ||2W||_0 = ||W||_0. Practical methods score importance with a criterion and fix N per layer with a ratio, then fine-tune the survivors.

Recall

Write the pruning formulation and name each symbol.

argmin over W_P of L(x; W_P) subject to ||W_P||_0 ≤ N. L is the training loss, x the input, W the original weights, W_P the pruned weights, ||.||_0 the count of nonzeros, and N the target number of nonzeros.

The brain overprovisions and then prunes

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.

Synapses per neuron against age, using the slide's figures: 2,500 at birth, a peak of 15,000 at two to four years, 7,000 in adulthood. The shaded region is what pruning removed.

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

  1. Growth

    15,000 / 2,500 = 6x more synapses per neuron at the peak than at birth.
  2. Elimination

    (15,000 - 7,000) / 15,000 = 8,000 / 15,000 ≈ 0.53, so about 53% of the peak is pruned away.
  3. 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.

About 2,500 at birth, 15,000 at two to four years, 7,000 in adults. 8,000 / 15,000 ≈ 53% eliminated.

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

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

  1. Explain the train, prune, retrain pipeline and why retraining is the step the paper calls critical.
  2. Read accuracy loss and reduction factor off the pruning-ratio chart for one-shot, retrained and iterative pruning.
  3. Explain from layer tables why parameter reduction and MAC reduction differ across AlexNet, VGG-16, GoogleNet, ResNet-50 and SqueezeNet.
  4. 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 bell of a trained layer. On hover the weights inside ±t collapse from the center outward, leaving the gap that is the visual signature of magnitude pruning. The bell is a model with sigma = 0.03 drawn on the slide inset's ±0.1 axis, not the paper's fc6 histogram.

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.

k=11rr=11kk = \frac{1}{1 - r} \qquad r = 1 - \frac{1}{k}
Reduction factor k from pruning ratio r, and back

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

  1. 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.
  2. 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.
  3. 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.
  4. 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?

The share of parameters pruned away. Keeping 1 - 0.8 = 0.2 of the weights makes the model 1 / 0.2 = 5x smaller.

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

The prune-only curve is the dashed line. On hover the retrained curve draws itself along the zero line and the accuracy that retraining gives back is shaded between them.

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.
Dr=DoCirCioD_r = D_o \sqrt{\frac{C_{ir}}{C_{io}}}
Dropout for retraining (Han et al. 2015, equation 2): C_io connections before, C_ir after

Worked example

Dropout for a fully connected layer kept at 9 percent

  1. Fraction of connections kept

    AlexNet's fc6 keeps 9% of its weights, so C_ir / C_io = 0.09.
  2. Scale the original dropout

    With D_o = 0.5: D_r = 0.5 × sqrt(0.09) = 0.5 × 0.3 = 0.15.
  3. 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.

Train the dense network to learn connectivity, prune the connections below a magnitude threshold, retrain the survivors. Retraining is the critical step: without it accuracy drops significantly, about 4% top-5 at 80% pruned.

Iterate: prune a little, retrain, repeat

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.

Train connectivity
dense network

Learn which connections matter.

magnitudes
Prune connections
below threshold

Cut a fraction of the survivors.

mask fixed
Train weights
fine-tuning

Survivors redistribute, then loop back to prune.

The prune and retrain loop. The return arrow is what lifts AlexNet from 5x to 9x.

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

  1. 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.
  2. 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.
  3. 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 ratioPrune onlyPrune + fine-tuneIterative
80% (5x)about -4%0%starting point: the retrained 80% model
90% (10x)off the chartabout -1.7%about 0%
93% (14x)off the chartabout -4%about -1%
Top-5 accuracy loss for the three recipes, read from slides 8 to 10
SimulatorPruning curve explorer: prune, fine-tune, iterate
80% pruned away
+0.5%0.0%-1.0%-2.0%-3.0%-4.0%-4.5%40%50%60%70%80%90%100%pruning ratio (parameters pruned away), AlexNet top-5 accuracy loss80% pruned: -4.05%
-0.10-0.050.000.050.10after the cut: the bell with its center removedgrey: dense reference, dashed: ±t = ±0.038
Top-5 loss-4.05%read off the active curve
Reduction5.0xsmaller1 / (1 - ratio)
AlexNet left12.2M weights61 M × (1 - ratio)
Threshold t0.038sigma = 0.03, Gaussian weights

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?

About -4% and 0%. The iterative curve has no separate value there: its leftmost dot is the retrained 80% model pruned further, so it starts from that 0% point. Keeping 20% of the weights is a 5x reduction factor.

Recall

Why did iterative pruning lift AlexNet from 5x to 9x with no loss?

After each retraining the surviving weights redistribute (bimodal, wider), so the next magnitude cut removes weights judged small under the new assignment. A greedy search over several rounds finds a smaller network than one aggressive cut.

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.

AlexNet's parameters live in FC layers, its MACs live in conv layers. On hover both bars drain to what pruning leaves: 11 percent of the parameters but 30 percent of the MACs.
NetworkParameters beforeAfterParameter reductionMAC reductionFC share of parameters
AlexNet61 M6.7 M9x3x96.2%
VGG-16138 M10.3 M12x5x89.9%
GoogleNet7 M2.0 M3.5x5xabout 14%
ResNet-5026 M7.47 M3.4x6.3xabout 8%
SqueezeNet1 M0.38 M3.2x3.5x0%
Slide 11 with one extra column: how much of each network's parameter count sits in fully connected layers

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.

FLOP%Weight%×Act%in\text{FLOP\%} \approx \text{Weight\%} \times \text{Act\%}_{\text{in}}
Han's remaining-compute rule: a MAC survives only if both operands are nonzero

Worked example

Checking the rule against AlexNet's Table 4

  1. conv2

    Weights kept 38%, input activations (the output of conv1) 88% nonzero: 0.38 × 0.88 = 33%. The table says 33%.
  2. fc6

    Weights kept 9%, input activations (the output of conv5) 34% nonzero: 0.09 × 0.34 = 3%. The table says 3%.
  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.
  4. 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.

Parameters are 96.2% in FC layers, which are pruned hardest, while 92% of MACs are in conv layers, which are pruned less. And Han's FLOP count only removes a MAC when both the weight and the input activation are nonzero, so activation sparsity shifts the MAC column independently.

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.

ImageBaselinePrunedPruning ratioVerdict
Basketballa basketball player in a white uniform is playing with a balla basketball player in a white uniform is playing with a basketball90%Same meaning, more specific noun
Doga brown dog is running through a grassy fielda brown dog is running through a grassy area90%Synonym
Surfera man is riding a surfboard on a wavea man in a wetsuit is riding a wave on a beach90%Different but valid description
Soccera soccer player in red is running in the fielda man in a red shirt and black and white black shirt is running through a field95%Drift: repeated phrase, lost the word soccer
Captions from the baseline LSTM and the pruned LSTM (slide 12)

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.

The NeuralTalk LSTM captioner: all LSTM weights except the word embedding pruned to 10% density (90% pruned), with BLEU flat until then and captions nearly identical. At 95% the captions start to repeat phrases.

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.

A 4 by 8 dense block. On hover two weights in every group of four fade, the survivors slide left into a packed 4 by 4 block, and the 2-bit index strip that tells the Tensor Core where each survivor came from appears below.

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.

SystemVenueWhat is sparseHeadline
EIEISCA 2016Weights and activations of pruned FC layers, model held in on-chip SRAM189x faster than CPU, 13x faster than GPU, 24000x more energy efficient than CPU
ESEFPGA 2017Pruned LSTM weights for speech recognition43x faster than a Core i7, 3x faster than a Pascal Titan X, 282 GOPS on the compressed model
SpArchHPCA 2020Sparse matrix times sparse matrix (outer product with merge)2.8x fewer DRAM accesses, 4x over OuterSPACE
SpAttenHPCA 2021Tokens and heads of attention, pruned in a cascade10x less DRAM traffic, 162x over a Titan Xp
A100 Sparse Tensor CoreNVIDIA 2020Any weight matrix in the 2:4 patternup to 2x peak, 1.3x to 1.6x measured per BERT-Large layer
Hardware support for sparsity on slide 13, with each system's headline claim from its abstract

Worked example

The same pruned layer on three targets

  1. 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.
  2. 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.
  3. 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.
  4. 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?

Two zeros in every four contiguous weights (50%, the 2:4 pattern). It delivers up to 2x Tensor Core throughput and almost 2x less storage and bandwidth; measured BERT-Large layer speedups are 1.3x to 1.6x.

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

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

  1. Define pruning granularity and place fine-grained and coarse-grained pruning at its two ends.
  2. Explain why coarse-grained choices are a subset of fine-grained ones and what that does to attainable sparsity at equal accuracy.
  3. 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.
  4. Order fine-grained, pattern-based, vector-level, kernel-level and channel-level from irregular to regular and say what hardware each maps onto.
  5. 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.

Removing rows 3, 4 and 7 of an 8 x 8 matrix leaves a dense 5 x 8 block. Nothing needs an index, so any matrix library multiplies it as is.
Removing 24 scattered entries reaches the same 37.5% sparsity, but the matrix keeps its 8 x 8 footprint and each survivor needs a stored position.

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

  1. 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.
  2. Row-structured

    Any 3 of the 8 rows may go, so there are C(8, 3) = 56 masks.
  3. 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.
  4. 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).

NetworkDensity keptFine-grainedVector-levelKernel-level
AlexNet24.8%80.41%79.94%79.20%
VGG-1623.5%90.56%90.48%89.70%
ResNet-5040.0%92.34%92.26%92.07%
Top-5 ImageNet accuracy at equal density (Mao et al., 2017, Table 1)
GranularityDensity keptStorage relative to dense
Fine-grained22.1%33.0%
Vector-level29.9%34.5%
Kernel-level37.8%39.7%
AlexNet at baseline accuracy: density versus storage with 4-bit indices (Mao et al., 2017, Table 2)

Recall

Rows 3, 4 and 7 of an 8 x 8 weight matrix are pruned. What is the sparsity, and what shape survives?

24 of 64 weights become zero, a sparsity of 37.5%. The survivor is a dense 5 x 8 matrix with no index storage.

Recall

Why does the slide call coarse-grained choices a subset of the fine-grained case, and what does that imply for compression?

Every set of whole rows is also a set of individual weights, so each structured mask is one of the unstructured masks. The structured optimum can only tie the unstructured optimum, so at equal accuracy the attainable sparsity is lower or equal, never higher.

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

N=cocikhkwN = c_o \cdot c_i \cdot k_h \cdot k_w
Weights in one convolution layer
The slide 17 tensor with its four dimensions labeled on one object: three filters down, two input channels across, nine weights per kernel, 54 in all.

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

UnitSliceWeightsShare of 54
Single weightW[o, i, r, c]11.9%
Row inside a kernelW[o, i, r, :]k_w = 35.6%
KernelW[o, i, :, :]k_h x k_w = 916.7%
Filter (output channel)W[o, :, :, :]c_i x k_h x k_w = 1833.3%
Input channelW[:, i, :, :]c_o x k_h x k_w = 2750.0%
Units inside the 54-weight tensor of slide 17

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 removedWeights removedShareSurviving shape
One kernel90.024%Still [64, 64, 3, 3] with holes
One filter64 x 9 = 5761.56%[63, 64, 3, 3]
One input channel64 x 9 = 5761.56%[64, 63, 3, 3]
Sixteen input channels16 x 576 = 9,21625%[64, 48, 3, 3]
Removing units from a [64, 64, 3, 3] layer

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.

[c_o, c_i, k_h, k_w]: output channels (filters), input channels, kernel height, kernel width. The count is 3 x 2 x 3 x 3 = 54.

Recall

How many weights go when you remove one kernel, one input channel and one filter from the 54-weight tensor?

One kernel removes k_h x k_w = 9 (16.7%). One input channel removes c_o x k_h x k_w = 27 (50%). One filter removes c_i x k_h x k_w = 18 (33.3%).

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.

Five prunings of one tensor. Each step to the right deletes a larger unit, until the channel-level panel simply drops a column and leaves a dense 3 x 1 x 3 x 3 tensor.

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.

PanelWhat was removedWeights removedSparsitySurvivor
Fine-grained31 single weights3157.4%54 slots with holes
Pattern-based5 of 9 cells in each of 6 kernels6 x 5 = 3055.6%54 slots, one shape per kernel
Vector-level11 of 18 kernel rows11 x 3 = 3361.1%54 slots with empty rows
Kernel-level2 of 6 kernels2 x 9 = 1833.3%54 slots with empty kernels
Channel-level1 of 2 input channels3 x 9 = 2750.0%dense [3, 1, 3, 3]
Counting the five panels of slide 18 (54 weights each)

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.

GranularityUnitWeights per unitIndex costRuns efficiently on
Fine-grainedAny single weight (0-D)1One index per surviving weightCustom sparse engines such as EIE or SCNN
Pattern-basedA fixed mask inside each kernel5 per kernelOne pattern id per kernelCompilers that specialize code per pattern (PatDNN)
Vector-levelA row of a kernel (1-D)k_w = 3One index per surviving rowCustom 1-D convolution hardware such as Eyeriss
Kernel-levelA whole k_h x k_w kernel (2-D)9One index per surviving kernelCustom 2-D convolution hardware (not stock dense libraries)
Channel-levelAn input channel across all filters (3-D)27None: the tensor shrinksAny dense CPU or GPU library
Five granularities on the 54-weight tensor and the hardware each maps onto (Mao et al., 2017, section 6; Niu et al., 2020)

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.

SimulatorGranularity pruner: one tensor, six ways to cut it
c_o = 3c_i = 2k_h × k_w = 3 × 3filter 0, input channel 0, kernel 0, row 0, column 0: -0.73filter 0, input channel 0, kernel 0, row 0, column 1: 0.39filter 0, input channel 0, kernel 0, row 0, column 2: 0.15 (pruned)filter 0, input channel 0, kernel 0, row 1, column 0: 0.15 (pruned)filter 0, input channel 0, kernel 0, row 1, column 1: 0.58filter 0, input channel 0, kernel 0, row 1, column 2: -0.19 (pruned)filter 0, input channel 0, kernel 0, row 2, column 0: -0.63filter 0, input channel 0, kernel 0, row 2, column 1: 0.09 (pruned)filter 0, input channel 0, kernel 0, row 2, column 2: 0.36filter 0, input channel 1, kernel 1, row 0, column 0: 0.25 (pruned)filter 0, input channel 1, kernel 1, row 0, column 1: 0.38filter 0, input channel 1, kernel 1, row 0, column 2: 0.05 (pruned)filter 0, input channel 1, kernel 1, row 1, column 0: -0.97filter 0, input channel 1, kernel 1, row 1, column 1: 0.24 (pruned)filter 0, input channel 1, kernel 1, row 1, column 2: -0.16 (pruned)filter 0, input channel 1, kernel 1, row 2, column 0: -0.93filter 0, input channel 1, kernel 1, row 2, column 1: 0.72filter 0, input channel 1, kernel 1, row 2, column 2: -0.45filter 1, input channel 0, kernel 2, row 0, column 0: -0.33filter 1, input channel 0, kernel 2, row 0, column 1: -0.67filter 1, input channel 0, kernel 2, row 0, column 2: 0.29 (pruned)filter 1, input channel 0, kernel 2, row 1, column 0: 0.55filter 1, input channel 0, kernel 2, row 1, column 1: -0.31 (pruned)filter 1, input channel 0, kernel 2, row 1, column 2: -0.47filter 1, input channel 0, kernel 2, row 2, column 0: 0.34filter 1, input channel 0, kernel 2, row 2, column 1: 0.19 (pruned)filter 1, input channel 0, kernel 2, row 2, column 2: -0.02 (pruned)filter 1, input channel 1, kernel 3, row 0, column 0: 0.92filter 1, input channel 1, kernel 3, row 0, column 1: -0.96filter 1, input channel 1, kernel 3, row 0, column 2: 0.70filter 1, input channel 1, kernel 3, row 1, column 0: 0.68filter 1, input channel 1, kernel 3, row 1, column 1: -0.88filter 1, input channel 1, kernel 3, row 1, column 2: 0.68filter 1, input channel 1, kernel 3, row 2, column 0: -0.22 (pruned)filter 1, input channel 1, kernel 3, row 2, column 1: -0.12 (pruned)filter 1, input channel 1, kernel 3, row 2, column 2: -0.19 (pruned)filter 2, input channel 0, kernel 4, row 0, column 0: -0.12 (pruned)filter 2, input channel 0, kernel 4, row 0, column 1: 0.75filter 2, input channel 0, kernel 4, row 0, column 2: -0.11 (pruned)filter 2, input channel 0, kernel 4, row 1, column 0: -0.63filter 2, input channel 0, kernel 4, row 1, column 1: -0.38filter 2, input channel 0, kernel 4, row 1, column 2: -0.48filter 2, input channel 0, kernel 4, row 2, column 0: 0.55filter 2, input channel 0, kernel 4, row 2, column 1: 0.70filter 2, input channel 0, kernel 4, row 2, column 2: 0.78filter 2, input channel 1, kernel 5, row 0, column 0: 0.28 (pruned)filter 2, input channel 1, kernel 5, row 0, column 1: 0.65filter 2, input channel 1, kernel 5, row 0, column 2: 0.66filter 2, input channel 1, kernel 5, row 1, column 0: -0.87filter 2, input channel 1, kernel 5, row 1, column 1: 0.47filter 2, input channel 1, kernel 5, row 1, column 2: -0.56filter 2, input channel 1, kernel 5, row 2, column 0: 0.25 (pruned)filter 2, input channel 1, kernel 5, row 2, column 1: -0.53filter 2, input channel 1, kernel 5, row 2, column 2: -0.85
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.

Achieved sparsity35.2%19 zerostarget 35%, rounded up to whole units
Remaining parameters35of 54values that still need storing
Index entries35positionsone index per surviving weight
Still 54 slots in memory. The zeros sit inside the tensor, so a dense library computes them anyway; skipping them needs a sparse format and hardware that reads indices.

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.

Fine-grained, pattern-based, vector-level, kernel-level, channel-level.

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

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

  1. 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.
  2. 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.
  3. Derive the 2:4 compressed layout and compute its memory saving for FP16 and INT8 values.
  4. State the pro and con of channel pruning and show how pruning one layer's channels shrinks two layers.
  5. 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.

NetworkParameters beforeParameters afterReduction
AlexNet61 M6.7 M9x
VGG-16138 M10.3 M12x (paper: 13x)
GoogleNet7 M2.0 M3.5x
ResNet-5026 M7.47 M3.4x
Fine-grained pruning results as printed on slide 20, reused from slide 11 (source: Han, PhD thesis, Table 3.1)

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

Zeros land anywhere in the tile, and every survivor needs an address written next to it. Flexibility buys compression and charges an index per weight.

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?

It may zero any weight, so it finds redundancy anywhere. But survivors sit at irregular positions, need per-weight indices and data-dependent memory access, and dense GPU kernels cannot skip them. Custom hardware such as EIE can (13x over a GPU running the dense model).

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.

s=1NMs = 1 - \frac{N}{M}
Sparsity of an N:M pattern under the N-nonzero convention

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

Each run of four snaps to two survivors, the survivors slide left into a half-width block, and a 2-bit sidecar records where each came from.

Worked example

Compressing an 8 by 8 FP16 matrix

  1. Dense storage

    64 values at 16 bits each: 64 x 16 = 1024 bits.
  2. Kept values

    Half survive, 32 values: 32 x 16 = 512 bits.
  3. Indices

    One 2-bit position per kept value: 32 x 2 = 64 bits.
  4. Compressed total

    512 + 64 = 576 bits.
  5. 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.

SimulatorN:M pruner: keep the largest magnitudes in every group
-0.380.180.130.72
0.08-0.37-0.790.78
-0.13-0.220.30-0.58
0.590.260.610.06
kept values (2 per group)
-0.380.72
-0.790.78
0.30-0.58
0.590.61
position indices
0011
1011
1011
0010
Sparsity50.0%8 of 16 zero1 - 2/4
Index width2bitslog2(4) per kept value
Per group36of 64 bits32 value + 4 index
Compression1.78x43.8% savedindex overhead 12.5%
Scaled to an 8 × 8 matrix (16 groups): dense 1024 bits, compressed 576 bits, ratio 1.78x. The ratio never depends on matrix size, only on M, N and the value width.

Recall

Define 2:4 sparsity, give its sparsity percentage, and state the storage layout.

Two nonzeros in every contiguous four (two zeros), so 50%. Stored as half the values plus a 2-bit index per kept value: 36 bits per group of four FP16 weights instead of 64, about 1.78x.

Recall

Under the NVIDIA convention, what is the sparsity of 1:4 and of 4:8?

1:4 keeps one of four, so 75% sparsity. 4:8 keeps four of eight, so 50%.

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.

NetworkData setMetricDense FP16Sparse FP16Change
ResNet-50ImageNetTop-176.176.2+0.1
ResNeXt-101_32x8dImageNetTop-179.379.30.0
XceptionImageNetTop-179.279.20.0
SSD-RN50COCO 2017bbAP24.824.80.0
MaskRCNN-RN50COCO 2017bbAP37.937.90.0
FairSeq TransformerEN-DE WMT'14BLEU28.228.5+0.3
BERT-LargeSQuAD v1.1F191.991.90.0
Dense versus 2:4 sparse FP16 accuracy after NVIDIA's train, prune, retrain recipe (NVIDIA Developer Blog)

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.

Train dense, prune each group of four to its two largest magnitudes, retrain with the original schedule and the mask fixed. Evidence: BERT-Large on SQuAD v1.1 scores 91.9 F1 both dense and sparse; ResNet-50 goes from 76.1% to 76.2% top-1.

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

  1. 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.
  2. 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.
  3. Uniform shrink, s = 0.3 everywhere

    Layer 0 keeps 0.70, every later layer keeps 0.7 x 0.7 = 0.49.
  4. 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.
  5. 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.
LayerUniform 0.3 keptUniform 0.4 keptPer-layer kept
Layer 01.0 x 0.7 = 0.701.0 x 0.6 = 0.601.0 x 0.5 = 0.50
Layer 10.7 x 0.7 = 0.490.6 x 0.6 = 0.360.5 x 0.7 = 0.35
Layer 20.7 x 0.7 = 0.490.6 x 0.6 = 0.360.7 x 0.3 = 0.21
Layer 30.7 x 0.7 = 0.490.6 x 0.6 = 0.360.3 x 0.8 = 0.24
Layer 40.7 x 0.7 = 0.490.6 x 0.6 = 0.360.8 x 0.7 = 0.56
Total kept2.66 / 5 = 53.2%2.04 / 5 = 40.8%1.86 / 5 = 37.2%
Kept fraction per layer, (1 - input sparsity) x (1 - output sparsity)
Five layers shrink by their own ratio while the dashed line marks the uniform 0.3 cut. Layers 0 and 2 go far past it, layer 3 stops well short.

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.

Pro: direct speedup on any hardware, because the pruned network simply has fewer channels and runs with dense kernels. Con: smaller compression ratio, because a whole channel is a coarse unit and its weak weights survive with it.

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

ModelMMACsTop-1Pixel 1 latencySpeedup
MobileNet 1.0 (full width)56970.6%123.3 ms1.00x
MobileNet 0.75 (uniform shrink)32568.4%72.3 ms1.7x
AMC, 50% FLOPs budget28570.5%68.3 ms1.81x
AMC, 50% latency budget27270.2%63.3 ms1.95x
MobileNet on ImageNet, latency measured on a Google Pixel 1 with TensorFlow Lite (AMC, Table 4; the 0.75 row's 1.7x is computed here as 123.3 / 72.3)
AMC's curve sits above and left of the uniform width-multiplier line. At about 68 ms the vertical gap is roughly two points of ImageNet accuracy.

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.

CurveLatencyTop-1
Uniformabout 52 msabout 67.5%
Uniformabout 90 msabout 69.1%
AMCabout 52 msabout 69.2%
Approximate points read off AMC Figure 5b (slide 25)

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.

On a Pixel 1, the 0.75 MobileNet gives 68.4% at 72.3 ms. AMC gives 70.5% at 68.3 ms and 70.2% at 63.3 ms, the latter 1.95x faster than the 123.3 ms full model at 70.6%.

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

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

  1. State the principle behind every pruning criterion and apply it to a single neuron.
  2. Compute element-wise importances |W| and produce the pruned matrix for a target sparsity.
  3. Score rows or channels with L1, L2 and general Lp norms and say which row is pruned.
  4. Show with numbers when L1 and L2 rank structural sets differently.
  5. 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.

y=f(iwixi+b)y = f\Big(\sum_i w_i x_i + b\Big)
One neuron: a weighted sum of inputs, a bias, then a nonlinearity f such as ReLU

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

The two strong connections light up and the output survives; the 0.1 connection is cut because it moves the sum least

Worked example

Three candidate deletions

  1. 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.
  2. 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.
  3. 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.
  4. 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?

The 0.1, because it has the smallest absolute value. The answer assumes x_0, x_1 and x_2 have similar scale, since the removed term is really |w_i| |x_i|.

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

Importance=W\text{Importance} = |W|
Element-wise magnitude: each weight is scored by its own absolute value
The minus signs drop away, the two largest magnitudes fill in, and the pruned matrix keeps 3 and -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

  1. Take absolute values

    |W| = [[3, 2], [1, 5]]. The -2 becomes 2 and the -5 becomes 5.
  2. Count how many survive

    Four weights at 50 percent sparsity means 4 × (1 - 0.5) = 2 survivors.
  3. Rank and keep

    Sorted importances are 5, 3, 2, 1. Keep the entries scoring 5 and 3, which are the original -5 and 3.
  4. 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.

Importances [[3, 2], [1, 5]]. Two survivors: 3 and -5. Pruned matrix [[3, 0], [0, -5]].

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

ImportanceL1=iSwi\text{Importance}_{L1} = \sum_{i \in S} |w_i|
Row-wise L1: the sum of absolute values over the structural set S
ImportanceL2=iSwi2\text{Importance}_{L2} = \sqrt{\sum_{i \in S} |w_i|^2}
Row-wise L2: the Euclidean length of the row
The two rows collapse to their L1 scores 5 and 6; the lower score loses and its whole row becomes zeros

Worked example

Row-wise scores, both norms

  1. Absolute values first

    Row 0 is [3, 2] in magnitude, row 1 is [1, 5].
  2. L1: add

    Row 0: 3 + 2 = 5. Row 1: 1 + 5 = 6.
  3. L2: square, add, root

    Row 0: sqrt(9 + 4) = sqrt(13) = 3.61. Row 1: sqrt(1 + 25) = sqrt(26) = 5.10.
  4. Compare and zero the loser

    Under both norms row 0 scores lower, so every entry of row 0 becomes zero.
  5. 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.
CriterionRow 0 scoreRow 1 scoreRow prunedPruned matrix
Element-wise |w|not a row scorenot a row scorenone (two smallest elements)[[3, 0], [0, -5]]
Row-wise L156row 0[[0, 0], [1, -5]]
Row-wise L2sqrt(13) = 3.61sqrt(26) = 5.10row 0[[0, 0], [1, -5]]
Three criteria on [[3, -2], [1, -5]] at 50 percent sparsity

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.

W(S)p=(iSwip)1/p\big\lVert W^{(S)} \big\rVert_p = \Big(\sum_{i \in S} |w_i|^p\Big)^{1/p}
The Lp norm of a structural set; p = 1 and p = 2 recover the two criteria above

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.

RowL1 scoreL2 score
[3, 3]3 + 3 = 6sqrt(9 + 9) = 4.24
[0, 5]0 + 5 = 5sqrt(0 + 25) = 5
Row kept[3, 3][0, 5]
Two rows, two norms, two different survivors
The L1 diamond of radius 6 passes through a = [3, 3] with b inside it; the L2 circle of radius 5 passes through b = [0, 5] with a inside it

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.

SimulatorMagnitude criterion explorer: element-wise or row-wise, L1 or L2
any p gives |w| on one element
Weight W
Editable weight matrix
Importance |W|
3215
Pruned W
300-5

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.

L1: 5 and 6. L2: sqrt(13) = 3.61 and sqrt(26) = 5.10. Row 0 is pruned under both, giving [[0, 0], [1, -5]].

Recall

Give two rows where L1 and L2 disagree, with the numbers.

[3, 3] against [0, 5]. L1: 6 against 5, keeps [3, 3]. L2: 4.24 against 5, keeps [0, 5].

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.

Hovering raises the threshold to 0.30; the channels with gamma 0.10 and 0.29 fade out and the survivors close the gap

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.

L=(x,y)(f(x,W),y)+λγΓγL = \sum_{(x, y)} \ell\big(f(x, W), y\big) + \lambda \sum_{\gamma \in \Gamma} |\gamma|
Network slimming: the usual loss plus an L1 penalty that pushes every channel scaling factor toward zero

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.

zo=γziμBσB2+ϵ+βz_o = \gamma \, \frac{z_i - \mu_{\mathcal{B}}}{\sqrt{\sigma^2_{\mathcal{B}} + \epsilon}} + \beta
Batch normalization for one channel: mini-batch statistics normalize z_i, then gamma rescales and beta shifts

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?

Gamma is already a per-channel trainable scale, so no new parameters or layers are needed. A standalone scaling layer after a linear convolution is meaningless because the scale could be moved into the weights, but batch normalization fixes the normalized activation's scale, so gamma alone measures the channel.

Recall

Factors 1.17, 0.10, 0.29, 0.82 and 0.56 with a threshold of 0.3: which filters go?

Filters 1 and 2, with factors 0.10 and 0.29. Their input channels in the next layer are removed as well.

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

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

  1. Derive the OBD importance 1/2 h_ii w_i^2 from the Taylor expansion and name the assumption that removes each term.
  2. Explain why magnitude pruning is OBD with a constant Hessian diagonal, and show a case where the two rankings disagree.
  3. Compute APoZ for a channel from its activation maps and decide which channel to prune.
  4. State the regression-based channel pruning objective, its L0 constraint and the two alternating LASSO and least-squares steps.
  5. 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.

δL=L(x;W+δW)L(x;W)=igiδwi+12ihiiδwi2+12ijhijδwiδwj+O ⁣(δW3)\delta L = L(x; W + \delta W) - L(x; W) = \sum_i g_i\,\delta w_i + \frac{1}{2}\sum_i h_{ii}\,\delta w_i^2 + \frac{1}{2}\sum_{i \neq j} h_{ij}\,\delta w_i\,\delta w_j + O\!\left(\lVert \delta W \rVert^3\right)
Second-order Taylor expansion of the loss change under a weight perturbation, new loss minus old
gi=Lwi,hij=2Lwiwjg_i = \frac{\partial L}{\partial w_i}, \qquad h_{ij} = \frac{\partial^2 L}{\partial w_i\,\partial w_j}
The gradient entries and the Hessian entries

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.

δL = L(W + δW) - L(W) = Σ g_i δw_i + ½ Σ h_ii δw_i² + ½ Σ_{i ≠ j} h_ij δw_i δw_j + O(||δW||³). The first sum is the slope along each weight, the second is the curvature along each weight's own axis, the third is the cross-curvature between pairs of weights, and the remainder collects every term of third order and higher.

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.

Three assumptions cross out three terms: the converged gradient, the cross-curvature and the cubic remainder. Only the diagonal curvature term survives.
OBD nameSlide wordingTerm removedWhy it is allowed
QuadraticL is nearly quadraticO(||δW||³)Near the minimum the loss surface is well described by its curvature alone, so the cubic remainder is negligible.
ExtremalTraining 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.
DiagonalDeletion 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 three OBD approximations and what each removes

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.

δLi=L(x;W)L(x;WPwi=0)12hiiwi2\delta L_i = L(x; W) - L(x; W_P \mid w_i = 0) \approx \frac{1}{2} h_{ii} w_i^2
Loss change from deleting a single weight under the three OBD assumptions
importancewi=δLi=12hiiwi2\text{importance}_{w_i} = \lvert \delta L_i \rvert = \frac{1}{2} h_{ii} w_i^2
OBD saliency. Remove the weights with the smallest values first.

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.

Weightwᵢhᵢᵢ|wᵢ|½ hᵢᵢ wᵢ²MagnitudeOBD
A1.50.21.50.225keepprune
B1.01.01.00.5keepkeep
C-0.64.00.60.72keepkeep
D0.58.00.51.0prunekeep
E0.22.00.20.04pruneprune
Magnitude and OBD disagree on which two of five weights to prune
Two weights rest on two loss valleys. Sliding each to zero raises the loss by half the curvature times the weight squared. The smaller weight in the steep valley costs twice as much as the larger weight on the flat one.

Worked example

Five weights, two rankings, prune two

  1. 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|.
  2. 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.
  3. Rank by each criterion, lowest first

    Magnitude: E, D, C, B, A. Saliency: E, A, B, C, D.
  4. 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.
InteractiveMagnitude versus OBD: same weights, two rankings
Weightw_ih_ii|w_i|½ h_ii w_i²mag rankmagnitudeobd rankobd
A1.50.2255keep2prune
B10.54keep3keep
C0.60.723keep4keep
D0.512prune5keep
E0.20.041prune1prune
Disagreements2weightsrows with a stripe are pruned by one criterion and kept by the other
Rank 1 meanslowestpruned firstset every h_ii equal and the two rankings coincide: magnitude is OBD with constant curvature

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

  1. Choose a reasonable network architecture.
  2. Train the network until reasonable convergence.
  3. Compute the second derivatives h_kk for each parameter.
  4. Compute the saliencies s_k = h_kk w_k² / 2.
  5. Sort the parameters by saliency and delete some low-saliency parameters.
  6. 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?

If every h_ii equals the same constant h, importance becomes (h/2) w_i², and ranking by that value is the same as ranking by |w_i|. OBD differs only by letting the curvature vary from weight to weight.

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 removedSlice deletedWeights deletedShape after
Output neuron of a linear layerW[o, :]One row: all incoming weights of that neuron[c_o - 1, c_i]
Output channel (filter) of a conv layerW[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 layerW[:, o, :, :]c_o kernels, one per filter, that read the removed map[c_o, c_i - 1, k_h, k_w]
What one removed unit takes with it

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?

Each output neuron owns one row of 16 weights, so 3 × 16 = 48 weights disappear and the matrix becomes [5, 16]. The next layer also loses three input columns.

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.

LayerMean APoZ
CONV1-147.07%
CONV3-369.93%
CONV4-387.30%
CONV5-393.19%
FC675.26%
FC774.14%
Mean APoZ per layer of VGG-16 on ImageNet validation (Hu et al., 2016, Table 1)

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.

APoZc=k=1Nj=1Mf ⁣(Oc,j(k)=0)N×M,f(true)=1, f(false)=0\mathrm{APoZ}_c = \frac{\sum_{k=1}^{N}\sum_{j=1}^{M} f\!\left(O_{c,j}(k) = 0\right)}{N \times M}, \qquad f(\text{true}) = 1,\ f(\text{false}) = 0
Average Percentage of Zeros for channel c, with M = H x W positions and N images (Hu et al., 2016, eq. 1)

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

  1. Count zeros per channel in batch 1

    Channel 0: 5. Channel 1: 5. Channel 2: 6.
  2. Count zeros per channel in batch 2

    Channel 0: 6. Channel 1: 7. Channel 2: 8.
  3. 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.
  4. 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
The zero positions of batch 1 light up in each channel's map, then the three APoZ bars grow. The tallest bar, channel 2, is crossed out.
SimulatorAPoZ trimmer: click activations to zero and watch the ranking move
channel 0
channel 1
channel 2

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.

Channelzeros b1zeros b2totalAPoZbardecision
Channel 05611/3234.4%
keep
Channel 15712/3237.5%
keep
Channel 26814/3243.8%
prune
Denominator32positionsbatch 2 × height 4 × width 4
Pruned channel2APoZ 43.8%highest APoZ loses; a tie goes to the higher channel index

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
CriterionReadsCostGranularityScore
Magnitude (part 05)Weight values onlyNone, read the tensorAny|w|, Lp norm of a structural set
OBDWeights and hᵢᵢ from a second backward passAbout one gradient computationWeight½ hᵢᵢ wᵢ²
APoZReLU outputs on a validation setOne forward pass over N imagesNeuron or channelFraction of zero activations
RegressionSampled layer inputs and outputsLASSO plus least squares per layerInput channelReconstruction error of Z
The criteria of parts 05 and 06 compared by what they read

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?

Trim every neuron whose APoZ is more than one standard deviation above the layer's mean, which under a Gaussian assumption on APoZ values removes about 16% of the neurons in that layer. Retraining is initialized from the trimmed network's surviving weights because training the same architecture from scratch leaves more zero-activation neurons behind and recovers less accuracy.

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.

Z=XWT=c=0ci1XcWcTZ = X W^{T} = \sum_{c=0}^{c_i - 1} X_c W_c^{T}
Layer output as a sum of per-input-channel contributions

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.

argminW,β ZZ^F2=Zc=0ci1βcXcWcTF2subject toβ0Nc\underset{W,\,\beta}{\arg\min}\ \lVert Z - \hat{Z} \rVert_F^2 = \Bigl\lVert Z - \sum_{c=0}^{c_i - 1} \beta_c\, X_c W_c^{T} \Bigr\rVert_F^2 \quad \text{subject to} \quad \lVert \beta \rVert_0 \le N_c
Regression-based channel pruning objective (He, Zhang and Sun, ICCV 2017)

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.

Setting one beta to zero removes a column of X and the matching row of W^T together. Z keeps its b by c_o shape and is rebuilt as Z hat from the surviving channels.

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.

StepFixedSolvedSolverOutput
1WβLASSO (L1-relaxed selection)Which input channels survive
2βWLeast squares (closed form)Weights that best rebuild Z from the survivors
The two alternating steps

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
speedup with 1.0% increase in top-5 error; with tensor factorization at 0.3%
ResNet-50 and Xception-50
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.

Minimize over W and β the value ||Z - Σ_c β_c X_c W_c^T||_F² subject to ||β||₀ ≤ N_c. Step one fixes W and solves for β by LASSO, which selects channels. Step two fixes β and solves for W by least squares, which rebuilds the output.

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.

CriterionWhat it readsRefPaperWhere taught
MagnitudeWeight values4Han et al., NeurIPS 2015Part 05
Scaling factorTrainable γ per channel11Liu et al., Network Slimming, ICCV 2017Part 05
Second orderLoss curvature hᵢᵢ3LeCun, Denker, Solla, NeurIPS 1989This part
Second order, modernHessian of a layer-wise reconstruction18Frantar and Alistarh, SparseGPT, 2023Pointer
ActivationZero fraction after ReLU14Hu et al., Network Trimming, 2016This part
RegressionLayer output reconstruction16He, Zhang, Sun, ICCV 2017This part
Next-layer statisticsNext layer's reconstruction17Luo, Wu, Lin, ThiNet, ICCV 2017Pointer
First-order TaylorGradient times value on mini-batches15, 13Molchanov et al., ICLR 2017 and CVPR 2019Pointer
Criteria mapped onto the reference list of slide 43

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.

Magnitude: Han et al. 2015, weight values. OBD: LeCun, Denker and Solla 1989, the diagonal of the Hessian times the squared weight. APoZ: Hu et al. 2016, the fraction of zero ReLU activations on validation data. Regression: He, Zhang and Sun 2017, the reconstruction error of the layer output.

Recall

Which of the criteria in this part need data pushed through the network, and which read only the parameters?

APoZ needs activations from a forward pass and regression needs sampled layer inputs and outputs, so both are data-driven. Magnitude reads only the weights. OBD reads the weights and h_ii; computing that diagonal does use training data through a second backward pass, but no activations are stored or scored.

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