Majid Al-RaimiWhere we are: the pruning problem so far

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

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

  1. Write the pruning formulation and define L, x, W, W_P, ||W_P||_0 and N.
  2. Explain why the L0 count is neither a norm nor differentiable, and why that forces heuristic criteria.
  3. Reproduce the 2x2 magnitude example and state the pruned matrix and its sparsity.
  4. Place fine-grained through channel pruning on the flexibility versus hardware-friendliness axis.
  5. 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.

argminWPL(x;WP)subject toWP0N\arg\min_{W_P} L(x;\, W_P) \quad \text{subject to} \quad \|W_P\|_0 \le N
Pruning as loss minimization under a nonzero budget

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.

Sixteen weights, a budget of eight. Cells whose magnitude falls below the threshold fade to zero until the nonzero count meets N.

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.

ModelBeforeAfterReduction
AlexNet61M6.7M9x
VGG-16138M10.3M13x
Han et al. 2015 compression results

Recall

Write the pruning formulation and name every symbol.

arg min 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, ||W_P||_0 the number of nonzeros in W_P, and N the target number of nonzeros.

Recall

Why can you not just run gradient descent on the constraint ||W_P||_0 <= N?

The count of nonzeros is piecewise constant, so its gradient is zero almost everywhere and undefined at zero. It is not a norm either. So we rank weights by a heuristic importance, keep the top N, and then fine-tune to recover the loss.

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?

Magnitude scores and the granularity ladder

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%

  1. Start from the weights

    W = [[3, -2], [1, -5]], four weights, two of which must go.
  2. Score every weight by its absolute value

    Element-wise |W| = [[3, 2], [1, 5]]. The sign is discarded; only distance from zero counts.
  3. 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.
  4. 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.

LevelWhat is removedFlexibilityHardware friendliness
Fine-grainedSingle weights at arbitrary positionsHighestNeeds stored indices and sparse kernels
Pattern-basedWeights in a fixed pattern, such as M:N (for example 2:4)HighRegular enough for special hardware support
Vector-levelOne 1-D row of a kernel, W[o, i, r, :]MediumModerate, fewer indices per block
Kernel-levelOne whole k x k kernelLowerGood, whole blocks disappear
Channel-levelA whole filter and its output channelLowestBest, the layer simply gets narrower
The granularity ladder, from lecture 04-1 parts 03 and 04

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?

Importances are 3, 2, 1, 5. The two largest are 5 and 3, so -5 and 3 survive. W_P = [[3, 0], [0, -5]], ||W_P||_0 = 2, sparsity 50%.

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.

Deleting output neuron 2 removes its four incoming edges on the left and strikes out row 2 of W on the right. The other rows survive intact.

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.

WorkModel and dataResult
Li et al., ICLR 2017VGG-16, CIFAR-10Up to 34% fewer FLOPs
Li et al., ICLR 2017ResNet-110, CIFAR-10Up to 38% fewer FLOPs
He et al., ICCV 2017VGG-165x speed-up, +0.3% error
Channel pruning results on dense kernels

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.

QuestionAsksAnswered in
IntroductionWhat is pruning and how do we formulate it?Lecture 04-1, part 01, and this part
GranularityIn what pattern should weights be removed?Lecture 04-1, parts 03 and 04
CriterionWhich synapses or neurons should go?Lecture 04-1, parts 05 and 06
RatioWhat target sparsity should each layer get?This lecture, parts 02 to 05
Fine-tune or trainHow do we recover the accuracy we lost?This lecture, part 06
The five pruning questions and where they are answered
The three questions settled in 04-1 are ticked. Ratio is lit and marked in focus because the outline highlights it next, and fine-tuning waits behind it.

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?

It deletes one whole row of W. Removing a conv channel deletes one whole filter, all C_in of its kernels. Both remove a structured block of many weights at once, so both are coarse-grained weight pruning.

Recall

Which of the five questions did 04-1 answer, and which does 04-2 answer?

04-1 answered formulation, granularity and criterion. 04-2 answers the pruning ratio per layer and fine-tuning, then goes beyond the outline to sparse hardware.

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