COE 592Lecture 4.2Part 02
Why every layer needs its own pruning ratio
Uniform shrinking loses to non-uniform pruning, so each layer needs its own ratio. Sensitivity analysis measures how much accuracy each layer loses as it is pruned harder.
- Concepts
- 3
- Slides
- 8-17
- Reading
- 18 min
Why this part matters
Every embedded deployment you will ship in this course, and every exam question on this lecture, starts from one decision: how much to prune each layer. Get it wrong by treating all layers alike and you pay accuracy at the same latency, about 2.1 points on MobileNet at roughly 70 ms. Get it right per layer and you have the foundation that AMC, NetAdapt and the threshold method in the next part all build on.
Part 01 left two questions open, and this part answers the first: what pruning ratio should each layer get? The answer comes in three moves. First the evidence that one ratio for all layers is a bad idea. Then the reason, which is that layers differ in sensitivity. Then the measurement, a sweep that prunes one layer at a time and records how much accuracy it costs, producing the family of curves that the next part reads ratios from.
By the end you can
- Explain, with the MobileNet numbers, why non-uniform pruning dominates uniform shrinking on accuracy versus latency.
- Define layer sensitivity and Delta Acc, and give three reasons the first layer is usually the most sensitive.
- Carry out the four-step sensitivity sweep and read a sensitivity chart for VGG-11 on CIFAR-10.
- Compute the evaluation cost of a sweep as layers times ratios, and explain why it is evaluation only, not training.
- State what the sweep cannot tell you (interactions between layers), preparing for the threshold and automated methods that follow.
Start with a measurement, not a principle. Take MobileNet on ImageNet and run it on a Google Pixel 1 CPU with TensorFlow Lite. The dense network scores 70.6% top-1 at 123.3 ms per image. Now shrink it two different ways to roughly half the work. The first way multiplies every layer's width by 0.75, the built-in MobileNet knob. The second way, AMC, lets every layer keep a different fraction of its channels (He et al., ECCV 2018, Table 4). MMACs counts millions of multiply-accumulate operations per image, a hardware-neutral measure of compute; a FLOPs target asks AMC to halve that compute, while a latency target asks it to halve measured time on the phone.
| Model | Top-1 | MMACs | Pixel 1 latency |
|---|---|---|---|
| 1.0 MobileNet (dense) | 70.6% | 569 | 123.3 ms |
| 0.75 MobileNet (uniform width multiplier) | 68.4% | 325 | 72.3 ms |
| AMC, 50% FLOPs target | 70.5% | 285 | 68.3 ms |
| AMC, 50% latency target | 70.2% | 272 | 63.3 ms |
Read the middle two rows against each other. At nearly the same latency, 72.3 ms versus 68.3 ms, the per-layer version keeps 2.1 points more accuracy. Read the first and third rows together and the gap is even more striking: AMC's 68.3 ms model loses only 0.1 points against the full network at 123.3 ms. Slide 9 plots the same story as a chart (AMC Figure 5b), and the values read off it land in one table.
| Series | Latency | Top-1 |
|---|---|---|
| Uniform (width or resolution multiplier) | 52 ms | 67.4% |
| Uniform (width or resolution multiplier) | 72 ms | 68.4% |
| Uniform (width or resolution multiplier) | 91 ms | 69.1% |
| Uniform (width or resolution multiplier) | 123 ms | 70.6% |
| AMC (per-layer pruning) | 52 ms | 69.2% |
| AMC (per-layer pruning) | 63 ms | 70.2% |
| AMC (per-layer pruning) | 68 ms | 70.5% |
Every AMC point sits above every uniform point. The uniform line on that chart mixes MobileNet's width multiplier with its input-resolution multiplier, which is why it has four points while Table 4 lists two; either knob shrinks every layer by the same factor.
The two stacks of bars on the slide are the whole idea in one picture. Uniform shrinking keeps every layer the same shape, just thinner: MobileNet's width multiplier alpha "thins a network uniformly at each layer" (Howard et al. 2017, section 3.3). Per-layer channel pruning ends with a ragged stack, some layers barely touched and others cut hard, because each layer got its own pruning ratio.
Why the ragged stack wins
Uniform shrinking rests on a hidden assumption: that every layer has the same slack. It does not. Han et al. (NeurIPS 2015, section 5) found that "the first convolutional layer, which interacts with the input image directly, is most sensitive to pruning", and suspected this sensitivity is "due to the input layer having only 3 channels and thus less redundancy than the other convolutional layers". The AMC paper records the standard hand-crafted rule of thumb that grew from such findings, one it then argues is non-optimal because layers are not independent: "prune less parameters in the first layer which extracts low level features and have the least amount of parameters". To see how little the first layer has to give, count the weights of the first six convolution layers of VGG-11 configuration A (Simonyan and Zisserman 2015, Table 1), each a 3 x 3 kernel over its input channels.
| Layer | Shape | Weights | Left at r = 0.9 |
|---|---|---|---|
| L0 | 3 x 3 x 3 x 64 | 1,728 | 173 |
| L1 | 3 x 3 x 64 x 128 | 73,728 | 7,373 |
| L2 | 3 x 3 x 128 x 256 | 294,912 | 29,491 |
| L3 | 3 x 3 x 256 x 256 | 589,824 | 58,982 |
| L4 | 3 x 3 x 256 x 512 | 1,179,648 | 117,965 |
| L5 | 3 x 3 x 512 x 512 | 2,359,296 | 235,930 |
Prune 90% of L0 and 173 weights are left to describe every edge and colour detector that the rest of the network depends on. Prune 90% of L5 and 235,930 weights remain. A uniform rule takes the same 90% from a 1,728-weight layer and a 2.36-million-weight layer as if both had the same room to spare. This difference in slack is what the lecture calls sensitivity, and the next concept defines it precisely.
Quick check
On slide 9, what does uniform shrinking do to a network?
Recall
Give the MobileNet numbers that show non-uniform pruning beating uniform shrinking at about the same latency.
Here is the same experiment on a network you can count by hand. Train VGG-11 on CIFAR-10 until it reaches about 93% test accuracy. Prune 90% of the weights in L0, the first convolution, and touch nothing else: accuracy falls to about 32%, a drop of about 61 points. RestoreL0, prune 90% of L1 instead: accuracy falls only to about 85%, a drop of about 8. Same ratio, roughly eight times the damage.
That difference is what layer sensitivity measures: how much accuracy the network loses when one layer alone is pruned at a given ratio, with every other layer left dense. Write the dense accuracy as Acc_dense and the accuracy after pruning only layer L_i at ratio r as Acc_r^i. The degradation is their difference.
Plot Acc_r^i against r and a sensitive layer gives a steep curve while a redundant layer gives a flat one. Slide 10 states the two ends of the spectrum: some layers are more sensitive, the first layer being the usual example, and some are more redundant. The word "usual" matters, because sensitivity is measured, not assumed, and the reasons the first layer tends to top the list are worth spelling out rather than memorizing.
Three reasons the first layer is usually most sensitive
- Fewest parameters. VGG-11's L0 has 1,728 weights against 73,728 in L1 and millions further in (VGG Table 1 arithmetic). Every weight removed from L0 is a larger share of what the layer knows.
- Only three input channels. The layer sees raw RGB, so there is little redundancy to absorb a loss. This is the explanation Han et al. (2015) give for AlexNet, where the first convolution was the most sensitive layer in their per-layer sweep (Figure 6).
- Everything downstream depends on it. Every feature in L1 through the classifier is a function of L0's output, so an error introduced there is inherited by every later layer rather than corrected.
Recall
Why is the first layer usually the most sensitive to pruning?
Recall
Write the definition of Delta Acc_r^i in words and as a formula.
If sensitivity is a curve per layer, the procedure to obtain it is fixed by the definition: isolate one layer, vary its ratio, measure, repeat. Slides 12 to 17 build that chart one curve at a time for VGG-11 on CIFAR-10. Here is the procedure as a whole, carried out on L0, then generalized.
Worked example
Sensitivity analysis of VGG-11 on CIFAR-10
Pick a layer L_i in the model
Start with L0, the first convolution, 3 x 3 x 3 x 64 with 1,728 weights. Every other layer stays exactly as trained.Prune only L_i with ratio r in {0, 0.1, 0.2, ..., 0.9}
For each r, apply magnitude-based fine-grained pruning to that one tensor: zero the smallest r fraction of its weights by absolute value. The slide allows "other strides", for example steps of 0.05, at proportionally more cost.Observe the accuracy degradation Delta Acc_r^i for each ratio
Evaluate the pruned model on the CIFAR-10 test set, 10,000 images, 1,000 per class (Krizhevsky). For L0 the readings are about 2 points lost at r = 0.5, 10 at 0.7, 22 at 0.8 and 61 at 0.9.Restore L_i and repeat the process for all layers
Copy the saved dense tensor back so the next sweep starts from the same model, then move to L1, L2 and onward. Plot every layer's curve on the same axes.A family of curves, one per layer
All curves share an x axis (pruning rate) and a y axis (accuracy). Slide 21, in the next part, reads per-layer ratios from this chart by drawing a horizontal threshold across it.
The completed chart on slide 17 is the payoff. Every layer stays close to 93% until about 50% pruning, which tells you that any one layer can lose half its weights while the rest stay dense; whether every layer can lose half at once is a different question, taken up below. Past that point the layers separate. Values below are read off the slide to the nearest point.
| Layer | r = 0.5 | r = 0.6 | r = 0.7 | r = 0.8 | r = 0.9 |
|---|---|---|---|---|---|
| L0 (first conv, blue) | 92 | 88 | 83 | 71 | 32 |
| L1 (green) | 93 | 93 | 93 | 92 | 85 |
| L2 (red, added on slide 15) | 93 | 93 | 92 | 90 | 79 |
| L3 (orange) | 93 | 93 | 91 | 86 | 51 |
| L4 (red, added on slide 17) | 93 | 93 | 90 | 77 | 39 |
Try the sweep yourself. The simulator holds the chart values, lets you pick the layer being pruned and slide its ratio, and reports the accuracy, the drop and how many of that layer's weights are gone. Leave the ratio at 0.9 and switch between L0 and L1 to feel the difference in one click.
Leave the slider at r = 0.9 and switch between L0 and L1: the first layer loses about 61 points, the second about 8. Every point on every curve comes from one evaluation with only that layer pruned and nothing retrained. Values are read from the slide chart to the nearest point, so treat them as approximate.
Why each layer is swept alone
Sweeping one layer while the rest stay dense is what makes the curve interpretable. If two layers were pruned together and accuracy fell, the drop could not be attributed to either one. Isolation buys attribution. It also has a price, which the next part turns into a whole discussion: it assumes the damage from pruning several layers adds up. AMC's authors put it bluntly, the single-layer approach "assumes that errors of different pruned layers can be summed up linearly, which does not stand according to our experiments" (He et al. 2018, section 4). Keep that interaction in mind: the sweep tells you which layers are fragile, not what happens when you prune them all at once.
What the sweep costs
No gradient step runs during a sweep, but every point on every curve is one full pass over the evaluation set. The number of evaluations is the number of layers times the number of ratios, and each evaluation is a forward pass over every test image.
| Network | Layers | Ratios | Evaluations | Images per evaluation | Forward passes |
|---|---|---|---|---|---|
| VGG-11 on CIFAR-10 | 9 | 10 | 90 | 10,000 | 900,000 |
| 50-layer network on ImageNet | 50 | 10 | 500 | 50,000 | 25 million |
The CIFAR-10 VGG-11 behind this chart has 9 weight layers (8 convolutions plus a 1-layer classifier), so ten ratios mean 90 evaluations over the 10,000-image CIFAR-10 test set, about 900,000 forward passes. One small saving: r = 0 is the same dense model for every layer, so it only needs to be evaluated once. A 50-layer ImageNet network evaluated on the 50,000 ILSVRC validation images (Russakovsky et al. 2015) needs 25 million. The cost is linear in depth, which is tolerable for VGG-11 and painful for deep networks, and it is one of the reasons the automated methods later in this lecture, AMC and NetAdapt, search the ratios instead of sweeping them.
The sweep in four lines
- Input
- A trained dense model and a held-out evaluation set
- Loop
- for each layer L_i, for each r: prune only L_i, evaluate, restore
- Output
- one curve per layer, Delta Acc_r^i against r
- Cost
- layers x ratios evaluations, no training
Quick check
In the sensitivity sweep, which layers are pruned while layer L_i is being measured?
Quick check
What happens to weights during a sensitivity sweep?
Quick check
VGG-11 on CIFAR-10: pruning L0 to 90 percent gives about what accuracy?
Recall
State the four steps of sensitivity analysis.
Recall
During the sweep, what state are the other layers in, and why?
Recall
How many evaluations does a sweep cost, and what is it for VGG-11 with ten ratios? Does any training happen?
Recap
If you remember nothing else
- Uniform shrinking gives every layer the same factor. AMC's per-layer ratios reach 70.5% at 68.3 ms, while 0.75 MobileNet reaches 68.4% at 72.3 ms.
- Layers differ in sensitivity. The first layer of VGG-11 has only 1,728 weights and 3 input channels, and every later feature depends on its output.
- Sensitivity analysis: pick L_i, prune only L_i at r in {0, 0.1, ..., 0.9}, record Delta Acc for each r, restore the layer, repeat for all layers.
- On VGG-11 CIFAR-10 every layer stays near 93% up to about 50% pruning. At 90%, L0 falls to about 32, L4 to 39 and L3 to 51, while L1, L2 and L5 stay near or above 80.
- The sweep is evaluation only, with no fine-tuning, and costs layers times ratios evaluations: 90 for the CIFAR-10 VGG-11 with ten ratios.
- Sweeping one layer at a time isolates causes but ignores interactions between layers, which is the limitation the next parts address.
Sources
- AMC: AutoML for Model Compression and Acceleration on Mobile DevicesPaperECCV 2018, He, Lin, Liu, Wang, Li and HanTable 4 MobileNet numbers on Pixel 1, Figure 5b accuracy versus latency, section 1 first-layer heuristic, section 4 critique of single-layer sensitivity.(opens in a new tab)
- Learning both Weights and Connections for Efficient Neural NetworksPaperNeurIPS 2015, Han, Pool, Tran and DallyFigure 6 per-layer sensitivity of AlexNet; first conv layer most sensitive, attributed to its 3 input channels.(opens in a new tab)
- Pruning Filters for Efficient ConvNetsPaperICLR 2017, Li, Kadav, Durdanovic, Samet and GrafSection 3.2 prune each layer independently and evaluate; section 4.1 first layer robust under filter pruning on CIFAR-10.(opens in a new tab)
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision ApplicationsPaperHoward et al., 2017Section 3.3 width multiplier thins a network uniformly at each layer; Table 6: 0.75 MobileNet 68.4 percent, 325 MMACs.(opens in a new tab)
- Very Deep Convolutional Networks for Large-Scale Image RecognitionPaperICLR 2015, Simonyan and ZissermanTable 1 configuration A: 11 weight layers and the channel widths used for the weight counts.(opens in a new tab)
- The CIFAR-10 datasetDocsAlex Krizhevsky, University of Toronto60,000 32x32 images in 10 classes; 10,000 test images with 1,000 per class.(opens in a new tab)
- ImageNet Large Scale Visual Recognition ChallengePaperIJCV 2015, Russakovsky et al.50 thousand validation images across 1,000 classes, used for the sweep-cost example.(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Fall 2023DocsMIT HAN LabLecture 4, Pruning and Sparsity Part II: the sensitivity analysis slides and VGG-11 on CIFAR-10 chart this part is built on. The linked Lab 1 notebook implements the sweep as prune one tensor, evaluate, copy the saved clone back, with no training step.(opens in a new tab)