COE 592Lecture 4.2Part 06
Fine-tuning, iterative pruning and regularization
Pruning costs accuracy, fine-tuning at a much smaller learning rate recovers it, repeating prune and fine-tune pushes AlexNet from 5x to 9x compression, and L1 or L2 regularization during training makes weights easier to prune.
- Concepts
- 4
- Slides
- 41-52
- Reading
- 24 min
Why this part matters
Every pruning method in this course, magnitude pruning, AMC, NetAdapt and the 2:4 sparsity of part 10, only reaches its quoted ratio because a fine-tuning step follows the cut. The EIE numbers in the next part assume the roughly 89% weight sparsity that this part explains how to obtain.
This is the fifth of the five questions the lecture opened with, and for embedded research it is the recipe you will actually run: cut, retrain the survivors gently, cut again. Two hyperparameters decide whether the loop works, the learning rate during fine-tuning and the regularizer used during training, and both are favorite exam questions because each has a single number or a single formula attached.
By the end you can
- Explain why accuracy drops after pruning and why fine-tuning at 1/10 to 1/100 of the original learning rate recovers it.
- Draw the Train Connectivity, Prune Connections, Train Weights pipeline with its loop arrow, and define one iteration.
- Read the three accuracy-loss curves and quote the 5x to 9x AlexNet result with its parameter counts.
- Write the L1 and L2 regularized losses, say which yields exact zeros, and explain why L2 still won for magnitude pruning.
- Connect Network Slimming's penalty on batch norm scaling factors to scaling-based channel pruning from lecture 04-1.
Take the AlexNet that Han, Pool, Tran and Dally started from in 2015: 61 million parameters, five convolution layers and three fully connected ones, 57.2% top-1 accuracy. They kept roughly one weight in nine and ended with a network that was not measurably worse. That is the headline of this part, and the whole trick behind it is what happens after the cut.
AlexNet before and after prune plus retrain (Han et al. 2015, Table 1 and section 4.2)
- Parameters
- 61M to 6.7M (9x)
- Top-1 error
- 42.78% to 42.77%
- Top-5 error
- 19.73% to 19.67%
- Original training time
- 75 hours on a Titan X
- Retraining time after pruning
- 173 hours at 1/100 of the initial learning rate
Now look at what those hours say. Retraining took more than twice as long as training. The authors did not treat it as optional polish; section 3 of the paper calls the final retraining step critical and states that if the pruned network is used without retraining, accuracy is significantly impacted. So the answer to the outline's fifth question, how to fine-tune a pruned network, is a method, not a footnote: the Pruning mask decides which weights exist, and Fine-tuning decides whether the survivors can still do the job.
Why the survivors are wounded, and why the wound heals
A trained layer is a set of weights that were optimized together. Zeroing the smallest of them, the magnitude criterion from lecture 04-1, is a small perturbation to any one output, but a large Pruning ratio removes so many small contributions that the outputs shift and the accuracy drops, more steeply the higher the ratio (this is what the chart on the slide shows for the dashed curve). The survivors are still near a good solution, though. Nothing about them was wrong; the function they were tuned to complete simply lost some of its terms. Fine-tuning continues gradient descent on exactly those survivors, with the removed weights held at zero, so they can absorb the work of the missing ones.
This is why the learning rate matters so much. The slide states the rule: the fine-tuning learning rate is usually 1/100 or 1/10 of the original learning rate. In the paper, LeNet was retrained at 1/10 of the original rate (section 4.1) and AlexNet at 1/100 of the initial rate (section 4.2). A large step would throw the weights out of the basin in which the magnitude ranking was measured, undoing the very judgement the pruning made. Small steps walk the network back down the loss surface from where the cut left it.
Slide 41 makes the same point as an optimization statement. Pruning poses the problem as minimizing the loss over the pruned weights W_P subject to a budget N on the L0 norm, the count of nonzero weights. The mask chooses which entries of W_P may be nonzero at all (the constraint), and fine-tuning is the argmin over the survivors with that mask fixed: the best values the kept weights can take.
The paper adds a second reason to keep the survivors instead of re-initializing them. Section 3.3 observes that networks contain fragile co-adapted features: gradient descent finds a good solution when the network is first trained, but not after re-initializing some layers and retraining them. Fine-tuning starts from the co-adapted weights and preserves that structure. The paper also notes that during retraining it can help to fix the convolution parameters while the fully connected ones retrain, and vice versa, to avoid vanishing gradients through the sparse layers.
The three-box pipeline
The figure on the slide is Figure 2 of the paper. The first box, Train Connectivity, is ordinary training, but its purpose is reframed: it learns which connections are important, not their final values. The second box, Prune Connections, applies the magnitude threshold. The third box, Train Weights, retrains the sparse network. In Han et al.'s implementation the threshold was a quality parameter multiplied by the standard deviation of each layer's weights, and Caffe was modified to add a mask that disregards pruned parameters during network operation for each weight tensor.
Learn which connections matter, not just their values.
Zero weights below the threshold and fix the mask.
Retrain the sparse network to recover accuracy.
Reading the chart on slide 43
The chart plots accuracy loss against the fraction of parameters pruned away for AlexNet. The dashed purple curve is pruning with no retraining; the green curve adds fine-tuning. Reading the points off the figure gives the following.
| Pruned away | Pruning only | Pruning + fine-tuning |
|---|---|---|
| 50% | about -0.1 | about 0.0 |
| 67% | about -0.9 | about +0.2 |
| 75% | about -2.1 | about +0.2 |
| 80% | about -4.0 | about 0.0 |
| 85.5% | off the chart | about -0.5 |
| 90% | off the chart | about -1.7 |
| 93% | off the chart | about -3.8 |
The paper summarizes the same curves in section 5: without retraining, accuracy begins dropping much sooner, at one third of the original connections rather than one tenth. It describes a free lunch of removing half the connections with no loss even without retraining, while with retraining the connections can be reduced by 9x. Read that 9x carefully: it is reached with the iterative scheme of the next two concepts. A single prune and retrain, the green curve, is already at about -1.7% by 90% pruned. Two green points (at about 67% and 75% pruned) sit slightly above zero, which the authors attribute to pruning finding the right capacity of the network and thereby reducing overfitting. Because sparsity and compression ratio are two ways of saying the same thing, keep the conversion at hand: ratio = 1 / (1 - s).
| Ratio | Pruned away |
|---|---|
| 2x | 50% |
| 3x | 66.7% |
| 5x | 80% |
| 9x | 88.9% |
| 10x | 90% |
| 13x | 92.3% |
Quick check
Fine-tuning a pruned network usually uses which learning rate, relative to the original?
Recall
What learning rate does fine-tuning a pruned network usually use, and why?
Once retraining is part of the recipe, a natural question follows: why cut to the final sparsity in one go? The slides tell the story as a sequence. Prune to 30%, retrain the weights. Prune to 50%, retrain. Prune to 70%, retrain. The only change to the pipeline figure is a single arrow from Train Weights back up to Prune Connections, and that arrow is the whole idea of Iterative pruning.
Define the unit first: one iteration is a prune followed by a fine-tune. Iterative pruning repeats that unit while gradually increasing the target sparsity in each iteration, instead of jumping to the final sparsity in one step. Han et al. put it plainly in section 3.4: learning the right connections is an iterative process, pruning followed by retraining is one iteration, and after many such iterations the minimum number of connections can be found. Each iteration is a greedy search for the best connections. They also tried pruning parameters probabilistically by absolute value and found it gave worse results.
Why gradual beats one-shot
The magnitude criterion ranks weights on the network as it is right now. After a 30% cut and a fine-tune, the survivors have re-settled: some grew to cover the removed terms, some shrank because their job was taken over. The ranking for the next cut is therefore measured on a network that has adapted, and the weights it marks as small really are the least needed. A one-shot cut to 90% ranks all 90% on a network that has never adapted to any loss, so it discards weights that would have become important once their neighbors were gone. Zhu and Gupta describe the same principle in the general form of a sparsity schedule: the binary mask is updated every few hundred steps to gradually increase the sparsity of the network while allowing the training steps to recover from any pruning-induced loss in accuracy. Their cubic schedule prunes quickly at first, when redundant connections are abundant, and slowly near the end.
The schedule in this part uses five hand-picked targets rather than a closed form, but the shape is the same: larger cuts early, smaller ones late. On a 6 x 6 matrix of 36 weights, rounding 36 s gives the following zero counts, which are also what the simulator below shows.
| Target | Zeros | Nonzeros left | Actual sparsity | Ratio |
|---|---|---|---|---|
| 30% | 11 | 25 | 30.6% | 1.4x |
| 50% | 18 | 18 | 50.0% | 2.0x |
| 70% | 25 | 11 | 69.4% | 3.3x |
| 80% | 29 | 7 | 80.6% | 5.1x |
| 90% | 32 | 4 | 88.9% | 9.0x |
Illustrative only. Fine-tuning is stood in for by letting each surviving weight in a row absorb 0.5 of the magnitude its row just lost, an echo of the surviving weights spreading outward in Han et al. Figure 7. The two loss curves are shape fits to the green and red curves of slide 51, not measured data. Cells with a teal border were zeroed in the latest step; survivors with a bright border moved up the magnitude ranking.
The loop also connects backwards to part 05. NetAdapt runs a short-term fine-tune after every layer it thins and a long-term fine-tune at the end, which is the same prune-then-fine-tune loop driven by a latency budget instead of a sparsity schedule. Whatever criterion or granularity you choose, the outer loop looks like this figure.
Quick check
In iterative pruning, what exactly counts as one iteration?
Recall
Define one iteration of iterative pruning and say what changes between iterations.
Slide 51 adds one bullet and one curve, and together they carry the number you will be asked for: Iterative pruning boosts the Pruning ratio from 5x to 9x on AlexNet compared to single-step aggressive pruning. The red curve is what that sentence looks like.
| Curve | Within 0.5% loss up to | Reaches about -4% at |
|---|---|---|
| Pruning only | about 60% | about 80% (5x) |
| Pruning + fine-tuning | about 85% | about 93% (14x) |
| Iterative pruning + fine-tuning | about 92% (12.5x) | about 95.5% (22x) |
| Pruned away | Accuracy loss |
|---|---|
| 87.5% | +0.1 |
| 89% | +0.05 |
| 90% | 0.0 |
| 91.5% | -0.3 |
| 92.5% | -0.6 |
| 93.5% | -1.0 |
| 94.5% | -2.0 |
| 95.5% | -4.1 |
Notice where the curve begins. It does not start at 40% like the others. The paper explains why in section 5: the biggest gain comes from iterative pruning, where the pruned and retrained network of the green curve is pruned and retrained again. The leftmost red dot corresponds to the point on the green line at 80% (5x) pruned further to 8x. There is no accuracy loss at 9x, and not until 10x does the accuracy begin to drop sharply.
Worked example
The 5x to 9x claim in parameters
Single-step tolerance
5x of 61M leaves 12.2M weights, which is 80% pruned away.Iterative result
9x leaves about 6.8M; the paper's measured count is 6.7M (61 / 6.7 = 9.1x, quoted as 9x), at about 89% pruned away.What the extra iterations removed
12.2M - 6.8M = 5.4M further weights, 44% of what single-step pruning had kept, at no accuracy cost.Where it stops
10x would be 6.1M weights, and there the paper reports the accuracy beginning to drop sharply.
The same paper reaches 13x on VGG-16 with five iterations of pruning and retraining, shrinking it to 7.5% of its original size with fc6 and fc7 each pruned to less than 4% of their original size. These pruned networks are the starting point of Deep Compression, which quantizes the surviving weights to 8 bits in convolution layers and 5 bits in fully connected layers and Huffman codes the result to reach 35x on AlexNet (240 MB to 6.9 MB) and 49x on VGG-16. The roughly 90% Weight sparsity that EIE assumes in the next part is this number.
Quick check
On AlexNet, iterative pruning raised the achievable pruning ratio from what to what?
Recall
Quote the AlexNet number for iterative versus single-step pruning and convert both to percent pruned.
Fine-tuning repairs the network after the cut. Regularization (for pruning) prepares it before the cut. Follow one weight w = 0.05 through training with a penalty coefficient lambda = 0.01 and a learning rate eta = 0.1, ignoring the data loss for the moment so only the penalty acts.
Worked example
One weight under an L1 and an L2 penalty
L1 pull
The gradient of lambda |w| is lambda sign(w), so each step subtracts eta lambda = 0.001 regardless of how small w is. From 0.05 the weight reaches exactly zero in 50 steps and stays there.L2 pull
The gradient of lambda w^2 is 2 lambda w, so each step subtracts eta 2 lambda w = 0.002 w. The weight is multiplied by 0.998 every step: after 50 steps 0.05 x 0.998^50 = 0.0452, after 1000 steps 0.0068, never zero.Two different destinations
L1 subtracts a constant and lands on zero. L2 multiplies by a constant and only approaches it.
| Steps | L1 | L2 |
|---|---|---|
| 0 | 0.0500 | 0.0500 |
| 50 | 0.0000 | 0.0452 |
| 200 | 0.0000 | 0.0335 |
| 1000 | 0.0000 | 0.0068 |
The two regularized losses
The slide states the general rule. During training, or during the fine-tuning of a pruned network, a penalty is added to the loss to penalize nonzero parameters and to encourage smaller ones. The two common choices are the L1 and L2 penalties on the weights W, with lambda setting how strongly the penalty competes with the data loss L(x; W).
Goodfellow, Bengio and Courville make both halves precise. L2 regularization, commonly known as weight decay, drives the weights closer to the origin; its update multiplicatively shrinks the weight vector by a constant factor on each step (their equation 7.5). L1 regularization, in comparison, results in a solution that is more sparse, where sparsity means that some parameters have an optimal value of exactly zero, and this property is why L1 has been used extensively for feature selection (LASSO). The gradient forms above are the reason. Near zero the L1 gradient lambda sign(w) keeps its full size, so the weight is pushed onto zero and pinned there. The L2 gradient 2 lambda w shrinks with the weight, so the push fades before it arrives.
| L1 | L2 | |
|---|---|---|
| Gradient of the penalty | lambda sign(w), constant | 2 lambda w, shrinks with w |
| Effect per step | Subtract a fixed amount | Multiply by a factor below one |
| Where weights end | Exactly zero, then stay | Small but never zero |
| Accuracy before retraining (Han et al.) | Better | Worse |
| Accuracy after retraining (Han et al.) | Worse | Better, best overall |
Why both help pruning, and why L2 won anyway
Either penalty shrinks the weights the data loss does not defend. That does two things for magnitude pruning. The ranking becomes a cleaner signal, because a weight that stayed large did so against a constant pull, and the mass of the distribution near zero grows, so more weights fall under the threshold at a given accuracy. L1 goes further and parks weights on exactly zero, so removing them changes nothing at all.
It is tempting to conclude that L1 must be the better choice for pruning, and this is the classic trap. Han et al. (section 3.1) report that L1 regularization does give better accuracy after pruning but before retraining, since more parameters sit near zero. However, the remaining connections are not as good as with L2, resulting in lower accuracy after retraining, and overall L2 regularization gives the best pruning results. They also tried L1 for the pruning phase followed by L2 for retraining and found it did not beat using L2 for both, because parameters from one mode do not adapt well to the other. That is why the slide says magnitude-based fine-grained pruning applies L2 regularization on weights.
Network Slimming: the same penalty on channel scaling factors
The second example on the slide moves the penalty from weights to channels, which connects back to the scaling-based criterion of lecture 04-1. Network Slimming (Liu et al., ICCV 2017) notes that every batch normalization layer already computes z_out = gamma z_hat + beta per channel, so gamma is a free scaling factor for that channel. Their training objective adds a sparsity penalty on those factors.
Channels whose gamma has been pushed toward zero contribute almost nothing and are removed with a global percentile threshold (pruning 70% of channels means choosing the 70th percentile of all gamma values), followed by fine-tuning. Because a whole channel goes, this is Channel pruning, the coarse end of Pruning granularity, and the resulting network stays dense. On VGGNet the method reports a 20x smaller model and 5x fewer computing operations. The paper also describes a multi-pass scheme that repeats train, prune and fine-tune, the same loop as the previous concepts, now driven by gamma instead of |w|.
Quick check
Why does an L1 penalty drive weights exactly to zero while L2 only shrinks them?
Quick check
Network Slimming applies its sparsity penalty to which quantity?
Recall
Write the L1 and L2 regularized losses and say which one produces exact zeros.
Recall
Which regularizer did Han et al. find best overall for pruning, and what does Network Slimming penalize?
Recap
If you remember nothing else
- Pruning without retraining starts losing accuracy once only one third of the original connections remain (about 67 percent pruned). One prune plus fine-tune holds to about 80 percent, and the full retraining scheme reaches one tenth remaining (Han et al.).
- Fine-tuning retrains only the survivors, with the mask fixed, at 1/10 to 1/100 of the original learning rate. AlexNet took 173 hours to retrain versus 75 hours to train.
- One iteration is prune then fine-tune. Iterative pruning raises the target sparsity each round and lifted AlexNet from 5x to 9x (61M to 6.7M parameters, top-5 error 19.73 to 19.67 percent).
- On the curve, iterative pruning stays within 0.5 percent loss to about 92 percent pruned and reaches -4 percent only near 95.5 percent; single prune plus fine-tune holds zero loss only to 80 percent (5x).
- L1 (lambda |W|) parks weights at exact zero; L2 (lambda ||W||^2) shrinks every weight multiplicatively. Both make small weights cheaper to remove.
- Han et al. found L2 best overall for magnitude pruning; Network Slimming puts an L1 penalty on batch norm scaling factors to select channels, and its multi-pass scheme is the same loop.
- Deep Compression and EIE (next part) start from exactly this 9x to 13x pruned network.
Sources
- Learning both Weights and Connections for Efficient Neural NetworksPaperNeurIPS 2015, Han, Pool, Tran and DallyThree-step pipeline, 1/10 and 1/100 learning rates, 5x to 9x iterative result, L1 versus L2 (3.1), dropout adjustment (3.2), Figures 5 and 7, Table 1(opens in a new tab)
- Learning Efficient Convolutional Networks through Network SlimmingPaperICCV 2017, Liu, Li, Shen, Huang, Yan and ZhangEquation 1 with g(s) = |s|, batch norm gamma as scaling factor, smooth-L1 as an alternative, percentile threshold, 20x size and 5x compute on VGGNet, multi-pass scheme(opens in a new tab)
- Deep Learning, chapter 7: Regularization for Deep LearningBookMIT Press, Goodfellow, Bengio and Courville7.1.1 weight decay shrinks multiplicatively (equation 7.5); 7.1.2 L1 yields sparse solutions (equation 7.18) and LASSO feature selection(opens in a new tab)
- To prune, or not to prune: exploring the efficacy of pruning for model compressionPaperarXiv 2017, Zhu and GuptaGradual sparsity schedule (equation 1), masks updated every delta t steps so training recovers between cuts(opens in a new tab)
- The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural NetworksPaperICLR 2019, Frankle and CarbinIterative magnitude pruning over n rounds; winning tickets at 10 to 20 percent of size; related reading only, not in the deck(opens in a new tab)
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman CodingPaperICLR 2016, Han, Mao and DallyPruning at 9x to 13x feeds 35x on AlexNet and 49x on VGG-16(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Fall 2024, Lecture 4: Pruning and Sparsity Part IIDocsMIT HAN Lab, Song HanSource of slides 43 to 52 (MIT slides 44 to 53), including the inherited wording errata(opens in a new tab)