Majid Al-RaimiWhy every layer needs its own pruning ratio

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

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

  1. Explain, with the MobileNet numbers, why non-uniform pruning dominates uniform shrinking on accuracy versus latency.
  2. Define layer sensitivity and Delta Acc, and give three reasons the first layer is usually the most sensitive.
  3. Carry out the four-step sensitivity sweep and read a sensitivity chart for VGG-11 on CIFAR-10.
  4. Compute the evaluation cost of a sweep as layers times ratios, and explain why it is evaluation only, not training.
  5. 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.

ModelTop-1MMACsPixel 1 latency
1.0 MobileNet (dense)70.6%569123.3 ms
0.75 MobileNet (uniform width multiplier)68.4%32572.3 ms
AMC, 50% FLOPs target70.5%28568.3 ms
AMC, 50% latency target70.2%27263.3 ms
MobileNet on ImageNet, Pixel 1 CPU (AMC Table 4, He et al. 2018)

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.

SeriesLatencyTop-1
Uniform (width or resolution multiplier)52 ms67.4%
Uniform (width or resolution multiplier)72 ms68.4%
Uniform (width or resolution multiplier)91 ms69.1%
Uniform (width or resolution multiplier)123 ms70.6%
AMC (per-layer pruning)52 ms69.2%
AMC (per-layer pruning)63 ms70.2%
AMC (per-layer pruning)68 ms70.5%
Values read from slide 9 (AMC Figure 5b)

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.

From the same dense outline, uniform shrink scales every layer by one factor while channel pruning gives each layer its own width, and at a similar latency the ragged stack keeps about 2.1 points more accuracy

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.

LayerShapeWeightsLeft at r = 0.9
L03 x 3 x 3 x 641,728173
L13 x 3 x 64 x 12873,7287,373
L23 x 3 x 128 x 256294,91229,491
L33 x 3 x 256 x 256589,82458,982
L43 x 3 x 256 x 5121,179,648117,965
L53 x 3 x 512 x 5122,359,296235,930
VGG-11 conv layers: weights before pruning and weights left at r = 0.9

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.

0.75 MobileNet (uniform): 68.4% top-1 at 72.3 ms. AMC with a 50% FLOPs target: 70.5% at 68.3 ms. Same latency band, 2.1 points more accuracy, and only 0.1 points below the dense model at 123.3 ms.

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.

ΔAccri=AccdenseAccri\Delta \mathrm{Acc}_r^{\,i} = \mathrm{Acc}_{\text{dense}} - \mathrm{Acc}_r^{\,i}
Accuracy lost when only layer i is pruned at ratio r

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

  1. 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.
  2. 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).
  3. 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.
Three input channels feed a first layer of 1,728 weights, and every wider stage after it is a function of that narrow bottleneck

Recall

Why is the first layer usually the most sensitive to pruning?

It has the fewest parameters (1,728 in VGG-11), it sees only 3 input channels so it has little redundancy, and every later feature depends on its output, so any damage there propagates through the whole network.

Recall

Write the definition of Delta Acc_r^i in words and as a formula.

The accuracy lost when only layer L_i is pruned at ratio r and every other layer stays dense: Delta Acc_r^i = Acc_dense minus Acc_r^i.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
Prune L0 only while the other five layers stay dense, and the L0 curve draws itself; then the L1 curve shows how differently a redundant layer behaves

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.

Layerr = 0.5r = 0.6r = 0.7r = 0.8r = 0.9
L0 (first conv, blue)9288837132
L1 (green)9393939285
L2 (red, added on slide 15)9393929079
L3 (orange)9393918651
L4 (red, added on slide 17)9393907739
Accuracy (%) read from slide 17, VGG-11 on CIFAR-10, one layer pruned at a time

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.

SimulatorSensitivity explorer: prune one layer of VGG-11, keep the rest dense
r = 0.9, 90% of L0 pruned away
100867258443010%20%30%40%50%60%70%80%90%pruning rate of the chosen layer alone, VGG-11 on CIFAR-10 accuracy (%)dense 93%L1L2L3L4L5L0 at 90%: 32%
Accuracy at r32%dense model: 93%
Delta Acc61points lost93 minus 32
Weights removed1,555of 1,728173 left in 3x3x3x64
Verdictcollapsesdrop of 10 points or more: this layer cannot lose that much

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.

NetworkLayersRatiosEvaluationsImages per evaluationForward passes
VGG-11 on CIFAR-109109010,000900,000
50-layer network on ImageNet501050050,00025 million
Sweep cost = layers x ratios evaluations, each over the whole evaluation set

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.

Pick a layer L_i. Prune only that layer at r in {0, 0.1, ..., 0.9} (or other strides). Record Delta Acc_r^i for each r. Restore the layer and repeat for every layer.

Recall

During the sweep, what state are the other layers in, and why?

Dense and untouched. Because only one layer changes, any accuracy change can be attributed to that layer alone.

Recall

How many evaluations does a sweep cost, and what is it for VGG-11 with ten ratios? Does any training happen?

Layers times ratios: 9 x 10 = 90 evaluations, each a full pass over the 10,000 CIFAR-10 test images. No training: it is prune, evaluate, restore, with no gradient step.

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