COE 592Lecture 4.2Part 01
Where we are: the pruning problem so far
A compact recap of lecture 04-1: pruning as constrained optimization, the granularity spectrum, magnitude as the default criterion and neuron or channel pruning as coarse-grained weight pruning, setting up the two open questions this lecture answers.
- Concepts
- 3
- Slides
- 1-7
- Reading
- 18 min
Why this part matters
Every method in this lecture, from sensitivity curves and AMC to NetAdapt, iterative fine-tuning, EIE and 2:4 tensor cores, is either a way of choosing how many nonzeros each layer may keep or a way of exploiting the zeros that choice creates. None of it makes sense unless the pruning problem itself is crisp in your head.
This part is a bridge, not a second lecture. The first seven slides of the deck repeat lecture 04-1 almost word for word, so the aim here is to compress what that lecture settled into one page you can reproduce under exam conditions: the formulation with every symbol defined, the reason the constraint cannot be optimized directly, the magnitude criterion on a 2 x 2 matrix, and the granularity ladder from single weights to whole channels. Expect to be asked for the formulation and for what ||W_P||_0 means, and the edge deployment in your research project starts by deciding a nonzero budget per layer, which is exactly the symbol N below.
By the end you can
- Write the pruning formulation and define L, x, W, W_P, ||W_P||_0 and N.
- Explain why the L0 count is neither a norm nor differentiable, and why that forces heuristic criteria.
- Reproduce the 2x2 magnitude example and state the pruned matrix and its sparsity.
- Place fine-grained through channel pruning on the flexibility versus hardware-friendliness axis.
- Say which of the five questions 04-1 answered and which two this lecture answers.
Take one layer with 16 weights and suppose the deployment budget allows you to keep only 8 of them. Which eight? That single question is the whole of Pruning. Every answer in lectures 04-1 and 04-2 is a different way of choosing those eight, and every hardware trick at the end of this lecture is a way of profiting from the eight zeros that remain.
The general rule states the question as a constrained optimization. Among all weight tensors that have at most N nonzero entries, pick the one that makes the training loss smallest.
Every symbol in the formulation
- L
- The training objective, the same loss the network was trained with, for example cross-entropy
- x
- The input data the loss is evaluated on
- W
- The original dense weights of the trained network
- W_P
- The pruned weights: the same shape as W, with some entries forced to exactly zero
- ||W_P||_0
- The number of nonzero entries in W_P, the L0 norm
- N
- The target number of nonzeros, the budget the pruned network must respect
Read the formula from the inside out. L(x; W_P) asks how badly the network with weights W_P does on the data. The arg min says we want the W_P that makes that number smallest. The constraint says we may only search among tensors whose nonzero count fits the budget. The budget is what connects this formula to the Pruning ratio of the next part: with M weights in the layer and N survivors, the fraction removed is 1 - N / M, so for M = 16 and N = 8 the layer is 50% sparse. The weight count is written M rather than |W|, because |W| below means the element-wise absolute value.
Why nobody solves this formula directly
The formula looks like something you could hand to gradient descent, and that is the trap. The nonzero count is a step function: nudge a weight from 0.30 to 0.31 and the count does not move, set it to exactly zero and the count drops by one. Its gradient is zero almost everywhere and undefined at zero, so no gradient flows through the constraint. Louizos, Welling and Kingma open their ICLR 2018 paper on this exact point: the L0 norm of the weights is non-differentiable, which is why it cannot simply be added to the training objective. Without a gradient, the exact problem is a combinatorial search, choosing which N of the M positions to keep, and for a layer with millions of weights that search is hopeless.
The heuristics are not arbitrary. Every one of them is a proxy for the same quantity: how much would L change if this weight were removed. The constraint side of the formula only fixes the budget; the loss side is what actually decides the answer, so the best criterion is the one whose ranking best tracks the change in loss. That is why the slide on selection later in this part says that the less useful the removed neurons are, the better the pruned network performs. Useful means low loss change, nothing else.
| Model | Before | After | Reduction |
|---|---|---|---|
| AlexNet | 61M | 6.7M | 9x |
| VGG-16 | 138M | 10.3M | 13x |
Recall
Write the pruning formulation and name every symbol.
Recall
Why can you not just run gradient descent on the constraint ||W_P||_0 <= N?
Quick check
In the pruning formulation, what does the term ||W_P||_0 measure?
Quick check
Why do all pruning criteria rank weights by an importance score instead of solving the arg min directly?
The formulation says nothing about how to find good survivors. Lecture 04-1 gave two practical answers, a shape and a score, and slides 4 to 6 of this deck replay them in the space of one minute. Start with the score on the smallest example that still teaches something: a 2 x 2 weight matrix that must lose half of its entries.
Worked example
Magnitude pruning on a 2 x 2 matrix at 50%
Start from the weights
W = [[3, -2], [1, -5]], four weights, two of which must go.Score every weight by its absolute value
Element-wise |W| = [[3, 2], [1, 5]]. The sign is discarded; only distance from zero counts.Keep the N = 2 highest scores
Sorted importances are 5, 3, 2, 1. The top two are 5 and 3, which belong to -5 and 3. The entries scored 2 and 1 are set to zero.Result
W_P = [[3, 0], [0, -5]], with ||W_P||_0 = 2 and sparsity 50%. Notice that -5 survives although it is the most negative weight in the matrix.
This is Magnitude-based pruning, and the slide is honest about its status: it is a heuristic criterion. The assumption is that a weight far from zero contributes more to the output, and therefore to the loss, than a weight near zero. Han et al. (NeurIPS 2015) used exactly this threshold rule to produce the 9x and 13x reductions quoted in the first concept, which is strong evidence that the assumption is usually good enough. It is not the only score. Lecture 04-1, part 05, adds scaling factors such as batch-norm gammas for whole channels, and part 06 adds second-order saliency from Optimal Brain Damage, the percentage of zero activations, and regression-based selection. All of them plug into the same three steps: score, sort, keep the top N.
The shape of what is removed
Scoring weights one at a time and zeroing the smallest gives the pattern the slide calls fine-grained: zeros scattered wherever the small weights happened to be. The pruned network figure on that slide, again from Han et al., shows synapses vanishing at arbitrary positions and whole neurons disappearing once every synapse into them, or every synapse out of them, is gone. Fine-grained removal has the most freedom, since any index may be pruned, and that freedom is what buys it the highest compression ratios. The cost is that the survivors no longer form a dense block. Their positions must be stored as indices, and the hardware needs a sparse kernel that skips the holes. Mao et al. (2017) measured the other end of the trade: coarse-grained pruning reaches a sparsity similar to unstructured pruning without losing accuracy, needs far fewer indices, and saves about 2x the memory references compared with fine-grained sparsity.
| Level | What is removed | Flexibility | Hardware friendliness |
|---|---|---|---|
| Fine-grained | Single weights at arbitrary positions | Highest | Needs stored indices and sparse kernels |
| Pattern-based | Weights in a fixed pattern, such as M:N (for example 2:4) | High | Regular enough for special hardware support |
| Vector-level | One 1-D row of a kernel, W[o, i, r, :] | Medium | Moderate, fewer indices per block |
| Kernel-level | One whole k x k kernel | Lower | Good, whole blocks disappear |
| Channel-level | A whole filter and its output channel | Lowest | Best, the layer simply gets narrower |
That ladder is the Pruning granularity axis, and the two ends pull against each other. Irregular patterns give the criterion freedom and therefore compression; regular patterns give the hardware dense blocks and therefore speed. Every design choice later in this lecture sits somewhere on this axis, and the 2:4 pattern of the tensor-core part is the industry's attempt to sit in both places at once.
Recall
Weights 3, -2, 1, -5, keep half by magnitude: what survives and what is ||W_P||_0?
Quick check
Applying Importance = |W| to 3, -2, 1, -5 and keeping half, which weights survive?
The coarse end of the ladder deserves one concrete picture, because it explains a sentence that students often quote without understanding: Neuron pruning is coarse-grained weight pruning. Slide 6 draws both cases, the linear layer and the convolution layer, and the same picture in matrix form makes the sentence obvious.
Removing a neuron is removing a row
A linear layer computes y = W x with W of shape out x in. Output neuron i is nothing more than row i of W: its incoming weights are the entries of that row, and its output is that row's dot product with x. Deleting the neuron therefore deletes the whole row at once, which is the white stripe in the slide's weight matrix, and the next layer loses the matching column because that input no longer exists. That is neuron pruning, and it is weight pruning where the removed set is a structured block of in weights chosen together rather than one weight at a time. Lecture 04-1, part 06, first drew this equivalence next to Optimal Brain Damage.
The convolution version is the same idea one dimension up. A conv layer holds weights of shape C_out x C_in x k x k. Output channel j is produced by filter j, which is the slice of all C_in kernels that feed it. Deleting a channel deletes that entire filter, the two dashed blocks in the slide's stack of six filters and the two white rows of kernels in its weight grid (two of six output channels removed). That is Channel pruning, and its reward is that nothing sparse is left behind: the layer simply has C_out minus the pruned count of channels and runs on the same dense kernels as before.
| Work | Model and data | Result |
|---|---|---|
| Li et al., ICLR 2017 | VGG-16, CIFAR-10 | Up to 34% fewer FLOPs |
| Li et al., ICLR 2017 | ResNet-110, CIFAR-10 | Up to 38% fewer FLOPs |
| He et al., ICCV 2017 | VGG-16 | 5x speed-up, +0.3% error |
Five questions, three answered
The outline that opens this deck on slide 2, and returns on slide 7 to close this part, lists five questions, and the same outline appeared three times in lecture 04-1. It is the map of both lectures, so it is worth knowing where each question was answered. The formulation above answers the first. Granularity, the pattern of removal, was answered in 04-1. Criterion, the score used to rank weights, was also answered in 04-1. What remains open is how many weights each layer should lose, and how to recover the accuracy once they are gone.
| Question | Asks | Answered in |
|---|---|---|
| Introduction | What is pruning and how do we formulate it? | Lecture 04-1, part 01, and this part |
| Granularity | In what pattern should weights be removed? | Lecture 04-1, parts 03 and 04 |
| Criterion | Which synapses or neurons should go? | Lecture 04-1, parts 05 and 06 |
| Ratio | What target sparsity should each layer get? | This lecture, parts 02 to 05 |
| Fine-tune or train | How do we recover the accuracy we lost? | This lecture, part 06 |
On slide 2 both open questions, ratio and fine-tuning, are highlighted in yellow. On slide 7, which closes this part, ratio turns green while fine-tuning stays yellow: ratio is being opened now, fine-tuning is still queued. The outline also under-sells the deck. After the five questions, parts 07 onward add a story the list never mentions, how EIE, 2:4 sparse tensor cores and sparse convolution engines turn the zeros produced by pruning into real speed and energy savings on hardware.
Quick check
Removing one neuron from a linear layer deletes what from its weight matrix?
Recall
What does removing one neuron of a linear layer do to W, and one channel of a conv layer?
Recall
Which of the five questions did 04-1 answer, and which does 04-2 answer?
Recap
If you remember nothing else
- Pruning: minimize L(x; W_P) subject to ||W_P||_0 <= N, where N is a budget on nonzeros.
- ||.||_0 counts nonzeros. It is not a norm and has no gradient, so every criterion is a heuristic proxy for the change in L.
- Slide 3 mixes < N with <= N and W_p with W_P. Read <= N and one matrix.
- Magnitude criterion: Importance = |W|. Weights 3, -2, 1, -5 at 50% keep 3 and -5.
- Granularity runs from fine-grained (flexible, index heavy) to channel (regular, dense-friendly).
- Neuron pruning removes a row of W. Channel pruning removes a filter. Both are coarse-grained weight pruning.
- 04-1 settled formulation, granularity and criterion. 04-2 answers ratio and fine-tuning, then adds sparse hardware.
Sources
- Learning both Weights and Connections for Efficient Neural NetworkPaperNeurIPS 2015, Han, Pool, Tran and DallyMagnitude threshold pruning with the train, prune, retrain loop; AlexNet 61M to 6.7M (9x), VGG-16 138M to 10.3M (13x).(opens in a new tab)
- Deep Learning, chapter 2: Linear Algebra, section 2.5 NormsBookMIT Press, Goodfellow, Bengio and CourvilleThe so-called L0 norm is incorrect terminology: the nonzero count does not scale with its argument, so it is not a norm.(opens in a new tab)
- Learning Sparse Neural Networks through L0 RegularizationPaperICLR 2018, Louizos, Welling and KingmaStates that the L0 norm of the weights is non-differentiable, the reason it cannot be optimized by gradient descent.(opens in a new tab)
- Optimal Brain DamagePaperNIPS 1989, LeCun, Denker and SollaSecond-derivative saliency as a criterion for removing weights.(opens in a new tab)
- Exploring the Regularity of Sparse Structure in Convolutional Neural NetworksPaperarXiv 2017, Mao et al.Granularity spectrum, index saving, and about 2x fewer memory references for coarse-grained sparsity.(opens in a new tab)
- Pruning Filters for Efficient ConvNetsPaperICLR 2017, Li, Kadav, Durdanovic, Samet and GrafWhole filters removed with their feature maps; FLOP reductions of up to 34% on VGG-16 and 38% on ResNet-110 for CIFAR-10 with dense BLAS.(opens in a new tab)
- Channel Pruning for Accelerating Very Deep Neural NetworksPaperICCV 2017, He, Zhang and SunLASSO-based channel selection; 5x speed-up on VGG-16 with a 0.3% increase in error.(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Fall 2024DocsMIT HAN Lab, Song HanLectures 3 and 4, Pruning and Sparsity parts I and II, the deck these COE 592 slides follow.(opens in a new tab)