COE 592Lecture 4.2Part 05
NetAdapt: platform-aware pruning to a latency budget
A rule-based automatic method that removes latency in fixed steps, tries pruning each layer with a measured latency lookup table, keeps the layer whose short fine-tune loses the least accuracy, and produces a whole series of models.
- Concepts
- 2
- Slides
- 33-40
- Reading
- 12 min
Why this part matters
Your edge deployments do not start from a FLOPs target. They start from a latency spec on a specific board: the camera pipeline must answer in 7 ms on this phone, or the classifier must fit one frame period on that microcontroller. NetAdapt is the pruning method built for that situation. It takes a pretrained network, a measured latency budget and the device itself, and hands back a network that meets the budget.
It is also the rule-based counterpart to AMC from part 04, so exam questions like to contrast the two, and it is the finishing step inside MobileNetV3. This part walks the loop once in words, once as a worked example you can redo by hand, and once in a simulator, then shows why a single run leaves you with a whole family of models rather than one.
By the end you can
- Write the NetAdapt loop from memory: Delta R, one proposal per layer, lookup table, short-term fine-tune, pick the highest accuracy, repeat, long-term fine-tune.
- Explain why a measured per-layer latency lookup table beats counting FLOPs, using the 19 percent fewer MACs but 29 percent slower example.
- Run three iterations by hand on a four-layer network and bring it from 10.0 ms under a 7.0 ms budget.
- Contrast NetAdapt with AMC on who decides the ratios, the cost model, the fine-tuning and what comes out.
- Explain why one run yields a whole accuracy versus latency frontier and read the slide 40 chart.
Suppose a pretrained MobileNet runs in 10.0 ms on one core of a Pixel 1 and the product needs 7.0 ms. The Sensitivity analysis of part 03 cannot help directly, because its curves are in accuracy versus Pruning ratio, not milliseconds, and it ignores Layer interaction. AMC (AutoML for Model Compression) from part 04 could be pointed at latency, but it needs a reinforcement learning agent and a training loop of its own. NetAdapt asks a much simpler question, and asks it many times: which single layer can I thin right now so that latency falls by a fixed step while accuracy falls the least?
The slides call it a rule-based iterative, or progressive, method, and every word matters. Rule-based means no learned policy: the decision each round is a comparison of measured numbers. Iterative means the budget is reached in many small steps rather than one cut. Progressive means each step starts from the winner of the previous one. It is Automated pruning in the sense of part 04, because nobody hand-picks per-layer ratios, but the automation is a loop you could run with a spreadsheet.
The problem, and the trick of tightening it slowly
Yang et al. state the goal as a constrained optimization. Accuracy should be as high as possible while every resource of interest (latency, energy, model size) stays under its budget.
Solving that in one shot is hopeless, so the paper breaks it into a chain of easier problems. At iteration i the constraint is not the final budget but the previous network's resource use minus a step ΔR.
The paper calls ΔR the resource reduction schedule and compares it to a learning-rate schedule. In the small MobileNetV1 experiments it starts at 0.5 ms and decays by 0.96 every iteration; for larger networks the initial step is scaled with the network's latency. The slides simplify this to a manually defined constant, and the worked example below does the same. Think of it as a progressive barrier: each round the wall moves in a little, and the network only has to squeeze past the new wall, never the final one.
One iteration, step by step
Read slides 34 to 39 as a single loop body. The paper's Algorithm 1 has the same shape, with K equal to the number of convolutional and fully connected layers, so a network with K such layers produces K proposals per iteration.
Time the pretrained network on the target once. Everything after this reads tables.
The target for this round is only ΔR below the current latency.
Pick the largest filter count whose summed table latency meets Con, keep the largest-l2 filters, short-term fine-tune, measure.
Net_(i+1) is the proposal with the best accuracy. Its latency becomes Res_(i+1).
Every iteration starts from the previous winner and moves the wall in by ΔR again.
Recover accuracy on the final architecture. This is the number you report.
- Set the constraint for this round: Con = Res_i minus ΔR_i.
- For each layer L_k, choose the number of filters to keep, from the lookup table, so the whole network meets Con; then choose which filters to keep by l2 magnitude.
- Short-term fine-tune that proposal (the slides say about 10k iterations) and measure its accuracy on a holdout set.
- Keep the proposal with the highest accuracy; it becomes the starting point of the next iteration.
- Repeat while the latency is still above the budget.
- Long-term fine-tune the final network until convergence.
Why a lookup table and not FLOPs
The constraint in Eq. 2 is a latency, so the loop needs to know the latency of every proposal, and there are K of them per iteration. Timing each one on the phone is slow and hard to parallelize. NetAdapt instead builds a Latency lookup table per layer before the loop starts: for every shape a layer might take (input channels, output channels, resolution), measure it once on the device and store the number. Layers that share a shape share an entry. The latency of a whole proposal is then the sum of its layers' entries. The paper's own illustration is a two-layer network where layer 1 with 4 filters on a 3-channel input costs 6 ms, and layer 2 with 6 filters on the 4 channels that layer 1 now produces costs 4 ms, so the network is estimated at 6 + 4 = 10 ms. Notice that the second entry is indexed by the first layer's filter count, which is how the table accounts for the removed input channels. A table indexed by whole networks would grow exponentially with depth; a table per layer grows linearly.
Why not skip the measurement and count multiply-accumulates? Because MACs are an indirect metric, and their relation to latency is neither linear nor the same across devices. The paper makes the point with a striking table: a network guided by MACs ended up with 19% fewer MACs than the baseline and 29% longer latency on a Pixel 1 CPU.
| Network | Top-1 | MACs | Latency |
|---|---|---|---|
| 25% MobileNetV1 (128) | 45.1% | 13.6 M (100%) | 4.65 ms (100%) |
| MorphNet | 46.0% | 15.0 M (110%) | 6.52 ms (140%) |
| NetAdapt guided by MACs | 46.3% | 11.0 M (81%) | 6.01 ms (129%) |
The lesson carries over to your own boards. Memory traffic, kernel launch overheads, cache behaviour and how well a library tiles a particular layer shape all change latency without changing the MAC count. The honest number is the one the device reports, and the lookup table is a cheap way to have that number on hand for every candidate. The paper checks the approximation on a Pixel 1 and finds the summed estimate highly correlated with the real measurement. Part 04 noted that AMC can also use a pre-built lookup table to optimize latency; NetAdapt makes it the default rather than an option.
Why fine-tune twice
There are two kinds of Fine-tuning in the loop and they serve different purposes. The short-term fine-tune happens once per proposal, so K times per iteration. Its only job is to make the K accuracies comparable. The paper reports that without it, the accuracy of a small network after pruning rapidly drops to nearly zero, and the algorithm then picks the best proposal solely based on noise. With 10k iterations the accuracy stays above 20% and the ranking becomes meaningful.
The long-term fine-tune happens once, after the loop has stopped, and runs until convergence. This is the step that repairs the damage of all the cuts on the final architecture. In the paper it adds between 1.8 and 4.5 points, 3.4 on average, on top of the last short-term number.
A run you can redo by hand
Take a four-layer network with 32, 64, 64 and 128 filters (layers A to D), a measured latency of 10.0 ms and a budget of 7.0 ms. Fix ΔR = 1.0 ms, ten percent of the starting latency. The lookup tables below are illustrative, the accuracies are synthetic, and the effect of one layer's cut on the next layer's input channels is ignored so the sums stay readable. The paper decays ΔR and accounts for the next layer.
Illustrative latency lookup tables, filters kept: ms
- Layer A (32 filters)
- 32: 3.0, 24: 2.4, 16: 1.8, 8: 1.2
- Layer B (64 filters)
- 64: 3.0, 48: 2.3, 32: 1.6, 16: 1.0, 8: 0.5
- Layer C (64 filters)
- 64: 2.5, 48: 2.0, 32: 1.5, 16: 1.0, 8: 0.5
- Layer D (128 filters)
- 128: 1.5, 96: 1.2, 64: 0.9, 32: 0.6, 16: 0.4
Worked example
Three iterations from 10.0 ms to a 7.0 ms budget
Check the starting point
3.0 + 3.0 + 2.5 + 1.5 = 10.0 ms at 71.0%. Above budget, so the loop runs.Iteration 1, Con = 10.0 minus 1.0 = 9.0 ms
For each layer, read the largest filter count whose sum meets 9.0 ms, short-term fine-tune the proposal and measure it.
Layer Filters kept Layer ms Total ms Short-term acc A 16 of 32 1.8 8.8 61.0% B 32 of 64 1.6 8.6 68.2% C (kept) 32 of 64 1.5 9.0 69.3% D 16 of 128 0.4 8.9 67.3% All four proposals meet the constraint, and NetAdapt does not reward going further below it (the 8.6 ms proposal earns nothing for its extra margin), so accuracy alone decides: layer C loses the least. Net_1 = A32 B64 C32 D128, 9.0 ms, 69.3%.
Iteration 2, Con = 9.0 minus 1.0 = 8.0 ms
Start from Net_1. Layer C already sits at 32, so its next table entry that saves a full millisecond is 8 filters, a much deeper cut.
Layer Filters kept Layer ms Total ms Short-term acc A 16 of 32 1.8 7.8 59.2% B (kept) 32 of 64 1.6 7.6 66.4% C 8 of 64 0.5 8.0 65.0% D 16 of 128 0.4 7.9 65.5% Thinning C again would now cost more than thinning B for the first time, so the greedy rule switches layers. Net_2 = A32 B32 C32 D128, 7.6 ms, 66.4%.
Iteration 3, Con = 7.6 minus 1.0 = 6.6 ms
7.6 ms is still above 7.0 ms, so one more round. Note that the constraint is set from the current latency, not from the budget.
Layer Filters kept Layer ms Total ms Short-term acc A 16 of 32 1.8 6.4 56.4% B 8 of 64 0.5 6.5 59.6% C 8 of 64 0.5 6.6 62.2% D (kept) 16 of 128 0.4 6.5 62.7% Layer D, the widest and least sensitive, wins. Net_3 = A32 B32 C32 D16, 6.5 ms, which is at or below 7.0 ms. The loop stops.
Long-term fine-tune
Train Net_3 to convergence. Short-term 62.7% becomes 65.2%, a gain of 2.5 points, inside the paper's 1.8 to 4.5 range.Result
Three iterations, three valid networks along the way (9.0, 7.6 and 6.5 ms), a final model at 6.5 ms and 65.2%. Layer A, the first layer, was never chosen, because the synthetic model gives it the highest Layer sensitivity by construction, mirroring the part 03 intuition that early layers are expensive to prune.
Now run it yourself. The simulator uses the same tables and the same synthetic accuracy model, so its default run reproduces the example above. Then change the budget or the step and watch which layer gets picked: a smaller ΔR takes more iterations, produces more intermediate models, and tends to end slightly higher in accuracy, which is what the paper's schedule study found.
- A32/32
- B64/64
- C64/64
- D128/128
The network starts dense at 10.0 ms and 71.0%. Each press builds one proposal per layer from the lookup table and keeps the one with the highest short-term accuracy.
Lookup tables and accuracies are synthetic. Accuracy is 71.0 minus a per-layer penalty that grows with the fraction of filters removed, so early layer A is expensive to cut and layer C is cheap. The latency effect on the next layer's input channels is ignored for readability.
NetAdapt against AMC
Both methods answer the question of part 02, which Pruning ratio for which layer, without a human in the loop, and both were published at the same conference. They differ in almost every mechanism, and the NetAdapt paper even uses AMC (under its earlier name, ADC) as a baseline, beating it by 1.2x in latency on the large MobileNetV1.
| Aspect | AMC (part 04) | NetAdapt |
|---|---|---|
| Who decides the ratios | A DDPG agent learns a policy from rewards | A greedy rule: the proposal with the highest accuracy wins |
| Search unit | The agent visits every layer once per episode | One layer changed per iteration, all layers tried |
| Cost model | FLOPs or latency in the reward, optionally a lookup table | Per-layer latency lookup table measured on the device and summed |
| Fine-tuning | One fine-tune of the final network | Short-term per proposal, long-term once at the end |
| Output | One model per target | A model at every iteration, the whole frontier |
| Interpretability | A learned policy | Every pick is explainable from measurements |
| Paper | He et al., ECCV 2018 | Yang et al., ECCV 2018 |
Recall
List the NetAdapt steps of one iteration in order.
Recall
Why does NetAdapt use a measured per-layer lookup table instead of counting FLOPs or MACs?
Recall
What is the short-term fine-tune for, and which accuracy is reported for the final model?
Quick check
In one NetAdapt iteration, what decides which layer's pruned proposal is carried to the next iteration?
Quick check
Why does NetAdapt read a pre-measured lookup table instead of counting FLOPs?
Quick check
Which accuracy number describes the final NetAdapt model reported in the paper?
Look back at the worked example. The run was aiming for one network at 7.0 ms, but on the way it produced Net_1 at 9.0 ms and Net_2 at 7.6 ms, and neither took any extra work. Each was the best of its round and each already satisfied its own, slightly looser, constraint. Slide 40 is that observation at full scale: the number of models equals the number of iterations.
The paper states it directly. Besides the final network, NetAdapt can generate a sequence of simplified networks, the highest-accuracy network from each iteration Net_1 to Net_i, which together provide the efficient frontier of accuracy and resource consumption trade-offs. The authors call it a family of simplified networks that allows dynamic network selection. With the 0.5 ms initial step and 0.96 decay, the small MobileNetV1 run in Table 2 took 28 iterations, so it delivered 28 networks. The red dots on slide 40 are a series of the same kind plotted the same way, one dot per iteration winner, from about 3.5 ms to 11 ms.
Reading the chart
The horizontal axis is latency on a single large core of a Pixel 1 CPU, measured with TensorFlow Lite as the median of eleven runs. The vertical axis is ImageNet top-1 accuracy. The red dots are the NetAdapt model series for the small MobileNetV1; the green triangles are MobileNetV1 shrunk with the width and resolution multipliers, which is Uniform shrinking from part 02; the blue diamond is MorphNet. The two arrows pick a multiplier point and the MorphNet point and slide left along a horizontal line to the NetAdapt curve, which is where the speedups on the slide come from.
| Method | Latency | Top-1 |
|---|---|---|
| NetAdapt, smallest point | about 3.5 ms | about 43.0% |
| NetAdapt, matched to MorphNet | about 4.4 ms | about 46.3% |
| MorphNet | about 7.0 ms (6.52 ms in Table 1) | 46.0% |
| NetAdapt, matched to the multiplier | about 7.3 ms | about 53.1% |
| Width multiplier baseline | about 12.1 ms | about 52.7% |
| NetAdapt, largest point | about 11.1 ms | about 56.8% |
From about 12.1 ms to about 7.3 ms is 1.7x faster with 0.3% higher accuracy than the multiplier baseline. From about 7.0 ms to about 4.4 ms is 1.6x faster with 0.3% higher accuracy than MorphNet. Across the whole curve the paper summarises it as up to 1.7x faster with the same or higher accuracy. On a mobile GPU (Samsung Galaxy S8 through SNPE) the gain drops to about 1.2x, because about 6.2 ms of that pipeline's latency is overhead that no amount of pruning can remove.
Why does the frontier beat the multipliers at all? A width multiplier thins every layer by the same factor, so it cannot express that some layers matter more. NetAdapt's greedy picks build a non-uniform architecture: the paper's Fig. 10 shows it keeping more filters in layer 6, where the feature map resolution drops, and in the last convolution that feeds the 1000-class classifier, while cutting layers 7 to 10 harder. That is the same lesson as part 02, now discovered by measurement rather than by a sensitivity sweep.
What the schedule does to the series
Because the series is a by-product of the loop, the step size shapes it. The paper compares three schedules for the same target latency.
| Initial ΔR | Decay | Iterations | Top-1 | Latency |
|---|---|---|---|---|
| 0.5 ms | 0.96 | 28 | 47.7% | 4.63 ms |
| 0.5 ms | 1.0 | 20 | 47.4% | 4.71 ms |
| 0.8 ms | 0.95 | 20 | 46.7% | 4.65 ms |
Recall
Why does one NetAdapt run give a series of models, and how many?
Quick check
A NetAdapt run needs 28 iterations to reach its latency budget. How many trade-off models does it produce along the way?
Quick check
Compared with the width-multiplier baseline on slide 40, what does the NetAdapt model series achieve?
Recap
If you remember nothing else
- NetAdapt solves maximize Acc(Net) subject to Res(Net) <= Bud by tightening the constraint by Delta R every iteration, a progressive barrier rather than one big cut.
- Each iteration thins exactly one layer: for every layer, read the filter count that meets Res minus Delta R from the lookup table, keep the largest-l2 filters, short-term fine-tune, measure holdout accuracy; keep the best proposal.
- Latency comes from summed per-layer lookup tables measured on the target device. MACs are an indirect metric: the paper shows 19 percent fewer MACs running 29 percent slower.
- The short-term fine-tune only ranks candidates; one long-term fine-tune at the end recovers 1.8 to 4.5 points and is the accuracy that gets reported.
- Delta R is a schedule: 0.5 ms decaying by 0.96 per iteration gave 28 iterations and 47.7 percent for the small MobileNetV1; larger steps finish sooner at a cost in accuracy, and for the same iteration count a smaller initial step with slower decay is preferable.
- Number of models equals number of iterations, so one run traces the accuracy versus latency frontier: 1.7x faster than width multipliers and 1.6x faster than MorphNet at equal or 0.3 percent higher accuracy on a Pixel 1 CPU.
- Versus AMC: a greedy rule instead of an RL agent, one layer per iteration, a measured lookup table, and a model at every iteration.
Sources
- NetAdapt: Platform-Aware Neural Network Adaptation for Mobile ApplicationsPaperECCV 2018, Yang, Howard, Chen, Zhang, Go, Sandler, Sze and Adam (arXiv)Eq. 1 and 2, Algorithm 1, lookup tables, Table 1 (MACs versus latency), Table 2 (schedules), Fig. 5 (slide 40), fine-tuning ablations.(opens in a new tab)
- NetAdapt, ECCV 2018 open-access PDFPaperEuropean Computer Vision AssociationCamera-ready version with the figures reproduced on slides 33 to 40.(opens in a new tab)
- 6.5940 TinyML and Efficient Deep Learning Computing, Fall 2023, Lecture 4: Pruning and Sparsity Part IIDocsMIT HAN LabThe source deck for slides 33 to 40 of this lecture.(opens in a new tab)
- AMC: AutoML for Model Compression and Acceleration on Mobile DevicesPaperECCV 2018, He, Lin, Liu, Wang, Li and Han (arXiv)The reinforcement learning counterpart, used as the ADC baseline in the NetAdapt paper.(opens in a new tab)
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision ApplicationsPaperHoward et al., 2017 (arXiv)Width and resolution multipliers, the uniform-shrinking baseline on slide 40.(opens in a new tab)
- MorphNet: Fast and Simple Resource-Constrained Structure Learning of Deep NetworksPaperCVPR 2018, Gordon et al. (arXiv)The MorphNet baseline point on slide 40.(opens in a new tab)
- Searching for MobileNetV3PaperICCV 2019, Howard et al. (arXiv)NetAdapt as the finishing step after hardware-aware architecture search.(opens in a new tab)