Majid Al-RaimiWhy prune: energy, definition and formulation

COE 592Lecture 4.1Part 01

Why prune: energy, definition and formulation

Memory access dominates the energy bill of deep learning, so fewer weights means less data movement; pruning removes synapses and neurons and is posed as minimizing loss under an L0 budget, echoing synaptic pruning in the human brain.

Concepts
5
Slides
1-6
Reading
30 min
Understood
0/5 concepts

Why this part matters

Every model you want on an embedded board is limited first by how many weights must be moved, not by how many multiplies the chip can do. One number from this part, 640 pJ for a DRAM access against 3.1 pJ for an integer multiply, justifies the pruning, quantization and sparse-hardware lectures that follow.

This part gives you three tools. A roadmap of the pruning pipeline, which doubles as the checklist for any pruning experiment in your research. The energy argument, which is the answer to the exam question "why is memory rather than arithmetic the bottleneck?". And the formulation of pruning as constrained optimization, which is the standard way to write down what pruning optimizes and why it cannot be solved by gradient descent alone. The part closes with the biological curve that inspired the whole idea.

By the end you can

  1. Name the four decisions of the pruning pipeline and say which ones this lecture covers.
  2. Reproduce the 45 nm energy ladder and argue with numbers why DRAM traffic, not arithmetic, dominates.
  3. Distinguish synapse pruning from neuron pruning and state what each does to a layer's weight matrix.
  4. Write the pruning formulation with a less-or-equal budget, name every symbol, and explain why the L0 constraint forces heuristic criteria.
  5. Describe the brain's overprovision-then-prune curve and use it as motivation, not as proof, for network pruning.

Pruning is a pipeline of four decisions

Suppose you have a trained object detector that is accurate on your validation set but will not fit on the board you are targeting. Before you touch a single weight, four questions need answers, and the outline slide of this lecture is exactly that checklist. It reappears on slides 14 and 26 as a progress marker, so treat it as the map you return to as each section closes.

Pruning makes a network smaller by removing the synapses and neurons whose removal hurts performance least. That one sentence hides a sequence of design decisions. First you must formulate the problem: what exactly is being minimized, and under what budget. Then you choose the granularity, the pattern in which weights are removed, from single scattered weights up to whole channels. Then a criterion, the rule that scores which synapses or neurons are least important. Then a ratio, the target sparsity for each layer. Finally you fine-tune or retrain the pruned network so the accuracy you lost comes back.

Formulate
This part

Loss under an L0 budget

Granularity
Parts 03 to 04

What pattern to remove

Criterion
Parts 05 to 06

Which synapses or neurons

Ratio
Lecture 04-2

Sparsity per layer

Fine-tune
Lecture 04-2

Recover the accuracy

The pruning pipeline: the formulation plus four decisions, taught across two lectures
DecisionQuestion the slide asksWhere it is taught
FormulateWhat is pruning? How should we formulate pruning?This part
GranularityIn what pattern should we prune the neural network?Parts 03 and 04
CriterionWhat synapses or neurons should we prune?Parts 05 and 06
RatioWhat should target sparsity be for each layer?Lecture 04-2
Fine-tune or trainHow should we improve performance of pruned models?Part 02 previews it; Lecture 04-2
The outline slide as a table: each decision, the question the slide attaches to it, and where it is taught

This lecture, Pruning and Sparsity I, covers the formulation, the granularity and the criteria. The ratio and the fine-tuning belong to Pruning and Sparsity II, the next lecture. The split mirrors the two pruning lectures of the MIT course the deck is built on, and it explains why the outline slide is highlighted only at the top: the yellow marker moves down as the lecture proceeds.

Recall

What are the four decisions that follow the formulation of pruning, and which of them belong to Lecture 04-2?

Granularity (in what pattern to prune), criterion (which synapses or neurons to prune), ratio (what target sparsity each layer gets), and fine-tuning or training the pruned network. Ratio and fine-tuning are Lecture 04-2.

Take one weight of a fully connected layer. It is fetched from off-chip DRAM and multiplied by an activation. The fetch costs 640 pJ. The 32-bit integer multiply costs 3.1 pJ. Divide them: 640 / 3.1 ≈ 206. Fetching the weight costs as much energy as about two hundred multiplies. That single ratio is the reason this lecture exists.

The numbers come from Mark Horowitz's ISSCC 2014 keynote, measured for a 45 nm process at 0.9 V, and reproduced in Han et al. (2015), which the slide follows. The full ladder is worth knowing by heart, because it is the quantitative case for every compression technique in this course. Read it top to bottom as an ordering of operations by cost, and notice that the four arithmetic rows and the register file all sit below 4 pJ while the two memory rows, SRAM and DRAM, close the table at 5 pJ and 640 pJ.

OperationEnergyRelative to int ADD
32-bit int ADD0.1 pJ1x
32-bit float ADD0.9 pJ9x
32-bit register file1 pJ10x
32-bit int MULT3.1 pJ31x
32-bit float MULT3.7 pJ37x
32-bit SRAM cache5 pJ50x
32-bit DRAM memory640 pJ6400x
Rough energy per 32-bit operation, 45 nm, 0.9 V (Horowitz 2014 via Han et al. 2015)
Seven energies on a log axis: six short bars for arithmetic and on-chip storage, one bar nearly four decades long for DRAM. The arrow reads off 640 / 3.1, about 206x.

Han et al. summarize the ladder in one sentence: memory access is three orders of magnitude more energy expensive than simple arithmetic. Sze et al. make the same point in their survey: DRAM accesses require up to several orders of magnitude more energy than computation, and DRAM consumes two orders of magnitude more energy per access than a small on-chip memory of a few kilobytes. Measured against the rows of the ladder, one DRAM access costs as much as each of the following.

One 640 pJ DRAM access costs as much as one...

One 32-bit int ADD
6400x
One register file read
640x
One SRAM cache read
128x
One 32-bit int MULT
206x
EDRAMEint MULT=640 pJ3.1 pJ206\frac{E_{\text{DRAM}}}{E_{\text{int MULT}}} = \frac{640\ \text{pJ}}{3.1\ \text{pJ}} \approx 206
One weight fetch buys about two hundred multiplies

The slide's icon line, one DRAM stick equals 200 ×+, rounds the chart's arrow: that arrow runs from the DRAM bar to the 32-bit int MULT bar, so the 200 is 640 / 3.1 ≈ 206 rounded down. Pricing one MAC instead (3.1 + 0.1 = 3.2 pJ) gives 640 / 3.2 = 200. Either way the answer is about two hundred.

The chain from weights to watts

The slide states the consequence as a chain: data movement, more memory references, more energy. Every weight that does not fit on chip is a DRAM reference on every inference. A network with more weights moves more bytes, more bytes mean more DRAM references, and each reference costs 640 pJ. The compute, the MACs that the earlier lectures counted so carefully, turns out to be the cheap part. This is the memory access energy problem, and pruning attacks it at the root by reducing the number of weights that have to move at all.

Worked example

A billion connections at 20 frames per second (Han et al. 2015)

  1. Count the fetches

    A network with 1,000,000,000 connections run at 20 Hz fetches every weight twenty times a second: 2 × 10^10 DRAM references per second.
  2. Price each fetch

    2 × 10^10 × 640 pJ = 12.8 J every second, so 12.8 W.
  3. Result

    12.8 W for DRAM traffic alone, before a single multiply is counted. Han et al. call this well beyond the power envelope of a typical mobile device.

Worked example

One layer of a million fp32 weights, before and after 90 percent pruning

  1. Dense: memory

    10^6 weights fetched once each from DRAM: 10^6 × 640 pJ = 640 µJ.
  2. Dense: arithmetic

    One float multiply and one float add per weight: 10^6 × (3.7 + 0.9) pJ = 4.6 µJ.
  3. Dense: share

    640 / 644.6 ≈ 0.993. Memory is 99.3% of the layer's energy, and the ratio of memory to arithmetic is 640 / 4.6 ≈ 139.
  4. Pruned: keep 100,000 weights

    Fetch 10^5 × 640 pJ = 64 µJ, compute 10^5 × 4.6 pJ = 0.46 µJ.
  5. Result

    Total drops from 644.6 µJ to 64.46 µJ, about 10x, ignoring the index overhead of a sparse format, which Part 03 reintroduces.
QuantityDense, 10^6 weightsPruned, 10^5 weights
DRAM fetch energy640 µJ64 µJ
MAC energy4.6 µJ0.46 µJ
Total per inference644.6 µJ64.46 µJ
Share from memory99.3%99.3%
The same layer dense and 90 percent pruned

There is a second payoff hiding in the ladder. Once a pruned model is small enough, its weights stop living in DRAM at all and sit in on-chip SRAM, where an access costs 5 pJ instead of 640 pJ. That is the argument of Deep Compression: pruning plus quantization shrinks both networks to a few megabytes, small enough to fit in on-chip SRAM cache rather than off-chip DRAM.

ModelBeforeAfterRatio
AlexNet240 MB6.9 MB35x
VGG-16552 MB11.3 MB49x
Model size before and after Deep Compression (Han, Mao and Dally 2016)

Separately, benchmarking the pruned fully connected layers on CPU, GPU and mobile GPU measured 3x to 7x less energy per layer. Fewer weights is the first win; crossing the SRAM boundary is the second.

SimulatorMemory energy budget: weights, sparsity and where they live
Presets
each kept weight is fetched once per inference and used in one MAC (4.6 pJ)
Energy per inference39.32mJ61 M kept weights × (640 pJ + 4.6 pJ)
Power at 20 Hz786.41mWmemory alone 780.8 mW
Share spent on memory99.3%39.04 mJ of 39.32 mJ
Model size (fp32)244MBvs dense in DRAM: 1x less energy

Figures are the slide's 45 nm, 0.9 V numbers from 2014 and ignore activation traffic and the index overhead of storing a sparse matrix. The 1 B at 20 Hz preset reproduces Han et al.'s memory-only estimate of 12.8 W (the total adds 0.09 W of MACs).

Quick check

Using the slide's 45 nm figures, about how many 32-bit integer multiplies cost the same energy as one 32-bit DRAM access?

Quick check

According to slide 3, what is the primary motivation for pruning a network?

Recall

One DRAM access versus one 32-bit integer multiply in 45 nm: give the two energies and the ratio. What is the ratio against an integer add?

640 pJ versus 3.1 pJ, so 640 / 3.1 ≈ 206, about 200x. Against the 0.1 pJ integer add it is 6400x.

The slide's before-and-after picture, taken from Han et al. (2015), is a small fully connected network with layers of 5, 4, 3 and 2 nodes. Count the edges: 5 × 4 + 4 × 3 + 3 × 2 = 20 + 12 + 6 = 38 synapses and 14 neurons. After pruning the layers read 5, 3, 2, 2. One hidden neuron is gone from the second layer, one from the third, and most of the remaining edges have vanished. Two different things were removed, and the slide labels them with two different arrows.

First the synapses: thirteen of the 38 edges fade while every node stays. Then the neurons: one node in each hidden layer collapses and the thirteen edges still attached to them go with it, leaving exactly the slide's 5-3-2-2 network with its twelve edges.

A synapse is one weight w_ij, one edge between neuron j of one layer and neuron i of the next. Synapse pruning sets that single entry to zero, and the neurons at both ends survive with one fewer connection. A neuron is a node. Neuron pruning removes the node and therefore every edge incident to it at once: all of its incoming weights and all of its outgoing weights. Nothing about the neuron remains, so nothing that fed it or read from it needs to exist either.

The matrix view makes the difference concrete. A linear layer holds its weights in a matrix W of shape [out, in], one row per output neuron and one column per input neuron. Synapse pruning zeroes scattered entries of that matrix, and the matrix keeps its shape; the result is a sparse matrix that must be stored with indices to say where the survivors are. Neuron pruning deletes a whole row of this layer's W(the neuron's inputs) and the matching column of the next layer's W (its outputs); both matrices become smaller dense matrices with no bookkeeping at all. This is the seed of the granularity spectrum in Part 03: fine-grained pruning lives at the synapse end and coarse-grained pruning at the neuron end.

Worked example

Same number of weights removed, two different results

  1. The setup

    Layer one has 4 inputs and 3 outputs, so W_1 is 3 × 4 = 12 weights. Layer two takes those 3 outputs to 2, so W_2 is 2 × 3 = 6 weights.
  2. Option A: prune 6 synapses

    Zero six entries of W_1. It still has 3 rows and 4 columns, with six zeros scattered inside. Every neuron still exists.
  3. Option B: prune neuron 2 of layer one

    Delete row 2 of W_1 (4 weights) and column 2 of W_2 (2 weights): 4 + 2 = 6 weights gone.
  4. Result

    Both options remove six weights. Option A leaves a sparse 3 × 4 matrix. Option B leaves dense 2 × 4 and 2 × 2 matrices that any hardware multiplies at full speed.
ChoiceWeights removedShapes afterSparse or dense
Prune 6 synapses63 × 4 and 2 × 3, unchangedSparse: 6 zeros scattered inside a 3 × 4 matrix
Prune neuron 24 + 2 = 62 × 4 and 2 × 2Dense: both matrices simply got smaller
Six weights removed, two ways

Han et al. describe the effect of synapse pruning on a layer in one line: this pruning converts a dense, fully-connected layer to a sparse layer. They also stress that retraining the surviving weights is critical, because zeroing connections drops accuracy immediately. Part 02 shows that curve and how fine-tuning recovers it.

  • Synapse pruning: unit is one weight, neurons survive, the matrix keeps its shape but becomes sparse.
  • Neuron pruning: unit is one node, all incident weights go, a row and a column disappear, matrices stay dense.
  • Both reduce the number of weights that must be fetched; only the second reduces it in a shape hardware likes.

Quick check

Which statement about pruning one hidden neuron is correct?

Recall

A 3 × 4 linear layer feeds a 2 × 3 layer. You prune neuron 2 of the first layer. How many weights vanish, and what shapes remain?

Row 2 of the first matrix (4 weights) and column 2 of the second (2 weights): 6 weights. The layers become 2 × 4 and 2 × 2, both still dense.

Start with a weight vector small enough to see whole: W = [0.8, -0.05, 0.3, -0.01]. It has four nonzero entries. Give yourself a budget of two. One candidate is W_P = [0.8, 0, 0.3, 0], which has exactly two nonzeros. Is it the best candidate? That depends on the training loss it produces, and the pruning formulation on the slide is precisely the question: among all weight vectors with at most two nonzeros, which one makes the loss smallest?

argminW  L(x;W)\underset{\mathbf{W}}{\arg\min}\; L(\mathbf{x};\, \mathbf{W})
Ordinary training: minimize the loss with no constraint on the weights
argminWP  L(x;WP)s.t.WP0N\underset{\mathbf{W}_P}{\arg\min}\; L(\mathbf{x};\, \mathbf{W}_P) \quad \text{s.t.} \quad \lVert \mathbf{W}_P \rVert_0 \le N
Pruning: the same loss, but only weight vectors with at most N nonzeros are admissible

The left half of the slide figure is ordinary training: pick W to minimize L, with the whole dense network available. The right half adds one line. The search variable becomes W_P, the pruned weights, and a constraint limits how many of its entries may be nonzero. Everything else, the loss, the data, the architecture, is unchanged. Pruning is training with a budget.

Every symbol in the formulation

L
The training objective (the loss), unchanged from ordinary training
x
The input data the loss is evaluated on
W
The original dense weights the network was trained with
W_P
The pruned weights, the thing we search over
||W_P||_0
The count of nonzero entries in W_P, the L0 pseudo-norm
N
The target number of nonzeros, the budget the pruned model must respect
A 4 × 6 weight matrix under a budget of N = 8. The sixteen smallest magnitudes are zeroed one rank at a time, the eight largest survive, and the counter drops from 24 nonzeros to 8: a hard count constraint being met, not a soft shrink.

Why the constraint needs heuristics

The L0 norm counts nonzeros, and despite its name it is not a norm at all. A norm must scale with its argument, so that doubling the vector doubles the norm. Doubling our example gives ||2W||_0 = 4 = ||W||_0, not 8. Worse, as a function of the weights it is piecewise constant: nudge any nonzero weight and the count does not change, so the gradient is zero almost everywhere and undefined exactly at zero. Louizos, Welling and Kingma state it plainly: the L0 norm of weights is non-differentiable, so it cannot be incorporated directly as a regularization term. Gradient descent, the only tool that scales to millions of weights, gets no signal from the constraint.

The constraint is also combinatorial. Choosing which N of the |W| entries survive is a subset selection. With 16 weights and a budget of 8 there are C(16, 8) = 12,870 masks to compare, each requiring a retrained loss to evaluate. With a million weights and a budget of a hundred thousand the count is astronomically large. Exact search is out of the question.

So the field replaces the exact problem by the pipeline of the first concept. A criterion assigns each weight or neuron an importance score, such as its magnitude |w|, and the least important are zeroed; that is a greedy stand-in for the search over masks. A ratio fixes N for each layer; that is the budget. Fine-tuning then re-minimizes L over the surviving entries, which is the only part gradient descent can do. The formulation is exact; everything after it is an approximation, and the quality of the approximation is what the rest of this lecture and the next are about.

From N to sparsity

sparsity=1NW\text{sparsity} = 1 - \frac{N}{|\mathbf{W}|}
The fraction of weights that are zero, equal to the pruning ratio when everything below the budget is removed

Worked example

AlexNet under Han et al. (2015)

  1. Count

    AlexNet has |W| = 61 M parameters. Han et al. prune it to N = 6.7 M.
  2. Sparsity

    1 - 6.7 / 61 = 1 - 0.11 = 0.89, so 89% of the weights are zero.
  3. Result

    89% sparsity, a pruning ratio of 89%, and 61 / 6.7 ≈ 9x fewer parameters, with no loss of accuracy after retraining.

In the tiny example, keeping 2 of 4 entries is 50% sparsity; the mask visual above keeps 8 of 24, which is 67%. The glossary defines the pruning ratio as the percentage of parameters pruned away, and when every zero comes from pruning the two quantities coincide.

Quick check

In argmin over W_P of L(x; W_P) subject to ||W_P||_0 <= N, what does N stand for?

Recall

Why can gradient descent not handle the L0 constraint directly, and what replaces it in practice?

||W||_0 is piecewise constant, so its gradient is zero almost everywhere and undefined at zero, and it is not a true norm since ||2W||_0 = ||W||_0. Practical methods score importance with a criterion and fix N per layer with a ratio, then fine-tune the survivors.

Recall

Write the pruning formulation and name each symbol.

argmin 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, ||.||_0 the count of nonzeros, and N the target number of nonzeros.

The brain overprovisions and then prunes

A newborn's cortical neuron carries about 2,500 synapses. By the age of two to four the figure is near 15,000. An adult settles around 7,000. The brain grows to six times its newborn connection count, then removes more than half of that peak. Growth to a peak, then elimination: the curve on the slide is the shape of train-dense-then-prune, drawn by biology decades before anyone pruned a neural network.

Synapses per neuron against age, using the slide's figures: 2,500 at birth, a peak of 15,000 at two to four years, 7,000 in adulthood. The shaded region is what pruning removed.

The three numbers on the slide

Newborn
about 2,500 synapses per neuron
2 to 4 years
peak, about 15,000 synapses per neuron
Adult
about 7,000 synapses per neuron

Worked example

How much the brain overprovisions and removes

  1. Growth

    15,000 / 2,500 = 6x more synapses per neuron at the peak than at birth.
  2. Elimination

    (15,000 - 7,000) / 15,000 = 8,000 / 15,000 ≈ 0.53, so about 53% of the peak is pruned away.
  3. Result

    Adults keep roughly 47% of their peak synapses. Using the slide's illustrative figures, in the vocabulary of the previous concept the brain runs at about 53% sparsity relative to its own dense peak.

This is synaptic pruning, and Han et al. invoke it in the introduction of the paper the slide follows: their method learns the network connectivity in addition to the weights, much as in the mammalian brain, where synapses are created in the first few months of a child's development, followed by gradual pruning of little-used connections, falling to typical adult values. The parallel to the pipeline is exact in shape. Overprovision (train a large dense network), score by use (the criterion), remove the weak connections (prune), and let the remaining ones strengthen (fine-tune).

Quick check

Using slide 6's figures, roughly what fraction of the peak synapses per neuron is eliminated by adulthood?

Recall

Give the synapses per neuron at birth, at the peak and in adulthood from slide 6, and the fraction eliminated between peak and adult.

About 2,500 at birth, 15,000 at two to four years, 7,000 in adults. 8,000 / 15,000 ≈ 53% eliminated.

Recap

If you remember nothing else

  • Pruning is a pipeline: formulate, choose granularity, choose criterion, choose ratio, fine-tune. This lecture covers the first three, Lecture 04-2 the last two.
  • In 45 nm at 0.9 V a 32-bit DRAM access costs 640 pJ against 3.1 pJ for an int multiply and 0.1 pJ for an int add: about 200x and 6400x.
  • Data movement drives memory references, memory references drive energy, so fewer weights means fewer fetches and, once the model fits SRAM, 128x cheaper accesses.
  • A 1-billion-connection network at 20 Hz spends 12.8 W on DRAM fetches alone.
  • Synapse pruning zeroes single weights and leaves neurons in place; neuron pruning deletes a node with all incident edges, a row here and a column in the next layer.
  • Pruning is argmin over W_P of L(x; W_P) subject to ||W_P||_0 <= N; the slide bullet's strict less-than is a typo inherited from the MIT deck.
  • ||.||_0 counts nonzeros, is not a true norm and has no useful gradient, so practical pruning uses importance criteria and per-layer ratios.
  • Sparsity equals 1 - N/|W|; AlexNet at 61 M to 6.7 M parameters is 89 percent sparsity, 9x fewer weights.
  • The brain grows from about 2,500 to 15,000 synapses per neuron and prunes to about 7,000: overprovision, then remove the little-used.

Sources