Majid Al-RaimiNetAdapt: platform-aware pruning to a latency budget

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

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

  1. 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.
  2. Explain why a measured per-layer latency lookup table beats counting FLOPs, using the 19 percent fewer MACs but 29 percent slower example.
  3. Run three iterations by hand on a four-layer network and bring it from 10.0 ms under a 7.0 ms budget.
  4. Contrast NetAdapt with AMC on who decides the ratios, the cost model, the fine-tuning and what comes out.
  5. 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.

maxNet  Acc(Net)subject toResj(Net)Budj,  j=1,,m\max_{\text{Net}} \; \text{Acc}(\text{Net}) \quad \text{subject to} \quad \text{Res}_j(\text{Net}) \le \text{Bud}_j,\; j = 1, \dots, m
NetAdapt, Eq. 1: the global problem

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.

maxNeti  Acc(Neti)subject toResj(Neti)Resj(Neti1)ΔRi,j\max_{\text{Net}_i} \; \text{Acc}(\text{Net}_i) \quad \text{subject to} \quad \text{Res}_j(\text{Net}_i) \le \text{Res}_j(\text{Net}_{i-1}) - \Delta R_{i,j}
NetAdapt, Eq. 2: the per-iteration problem

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 layer thinned per candidate column, the ring lands on the candidate with the highest accuracy, and the loop returns to the model

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.

Measure
Res_0 on the device

Time the pretrained network on the target once. Everything after this reads tables.

tighten
Set the constraint
Con = Res minus ΔR

The target for this round is only ΔR below the current latency.

for each layer k
Propose
K candidates

Pick the largest filter count whose summed table latency meets Con, keep the largest-l2 filters, short-term fine-tune, measure.

The NetAdapt loop body, first half: measure once, tighten by Delta R, propose one cut per layer
Pick
highest holdout accuracy

Net_(i+1) is the proposal with the best accuracy. Its latency becomes Res_(i+1).

Res > Bud
Repeat
until Res <= Bud

Every iteration starts from the previous winner and moves the wall in by ΔR again.

Res <= Bud
Long-term fine-tune
once, to convergence

Recover accuracy on the final architecture. This is the number you report.

After the K proposals: pick one, loop while over budget, then fine-tune for real
  1. Set the constraint for this round: Con = Res_i minus ΔR_i.
  2. 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.
  3. Short-term fine-tune that proposal (the slides say about 10k iterations) and measure its accuracy on a holdout set.
  4. Keep the proposal with the highest accuracy; it becomes the starting point of the next iteration.
  5. Repeat while the latency is still above the budget.
  6. 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.

NetworkTop-1MACsLatency
25% MobileNetV1 (128)45.1%13.6 M (100%)4.65 ms (100%)
MorphNet46.0%15.0 M (110%)6.52 ms (140%)
NetAdapt guided by MACs46.3%11.0 M (81%)6.01 ms (129%)
Table 1 of the NetAdapt paper: fewer MACs does not mean faster (Pixel 1 CPU, 128 by 128 input)

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

  1. Check the starting point

    3.0 + 3.0 + 2.5 + 1.5 = 10.0 ms at 71.0%. Above budget, so the loop runs.
  2. 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.

    LayerFilters keptLayer msTotal msShort-term acc
    A16 of 321.88.861.0%
    B32 of 641.68.668.2%
    C (kept)32 of 641.59.069.3%
    D16 of 1280.48.967.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%.

  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.

    LayerFilters keptLayer msTotal msShort-term acc
    A16 of 321.87.859.2%
    B (kept)32 of 641.67.666.4%
    C8 of 640.58.065.0%
    D16 of 1280.47.965.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%.

  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.

    LayerFilters keptLayer msTotal msShort-term acc
    A16 of 321.86.456.4%
    B8 of 640.56.559.6%
    C8 of 640.56.662.2%
    D (kept)16 of 1280.46.562.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.

  5. 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.
  6. 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.
Each iteration cuts latency by at least Delta R until the third step lands under the 7.0 ms budget line

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.

SimulatorNetAdapt stepper: four layers, one latency budget
  • A32/32
  • B64/64
  • C64/64
  • D128/128
Current latency10.0msA32 B64 C64 D128
Next constraint9.0msRes minus ΔR = 1.0 ms
Iterations0so farone layer thinned each
Models produced0networksequals the iteration count

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.

10987654msiterationbudget 7.0 ms0
Latency is above the budget of 7.0 ms. Press Next iteration to tighten the constraint by ΔR and try every layer.

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.

AspectAMC (part 04)NetAdapt
Who decides the ratiosA DDPG agent learns a policy from rewardsA greedy rule: the proposal with the highest accuracy wins
Search unitThe agent visits every layer once per episodeOne layer changed per iteration, all layers tried
Cost modelFLOPs or latency in the reward, optionally a lookup tablePer-layer latency lookup table measured on the device and summed
Fine-tuningOne fine-tune of the final networkShort-term per proposal, long-term once at the end
OutputOne model per targetA model at every iteration, the whole frontier
InterpretabilityA learned policyEvery pick is explainable from measurements
PaperHe et al., ECCV 2018Yang et al., ECCV 2018
AMC versus NetAdapt

Recall

List the NetAdapt steps of one iteration in order.

Set Con = Res minus ΔR. For each layer k: choose from the lookup table the largest filter count whose summed latency meets Con, keep the filters with the largest l2 norm, short-term fine-tune, measure holdout accuracy. Pick the proposal with the highest accuracy. Repeat while the latency is above the budget. Long-term fine-tune once at the end.

Recall

Why does NetAdapt use a measured per-layer lookup table instead of counting FLOPs or MACs?

MACs are an indirect metric whose relation to latency is non-linear and platform dependent; the paper shows a network with 19% fewer MACs running 29% slower. Per-layer tables are cheap to build (layers of the same shape are measured once), sum to the network latency, and avoid timing every proposal on the device inside the loop, which is slow and hard to parallelize.

Recall

What is the short-term fine-tune for, and which accuracy is reported for the final model?

It only makes candidates comparable: without it, accuracy collapses to near zero and the pick is noise. The reported accuracy comes after the long-term fine-tune, which adds 1.8 to 4.5 points in the paper.

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.

#models=#iterations\#\text{models} = \#\text{iterations}
Every iteration's winner is a deployable network
The NetAdapt curve is drawn point by point from about 43 percent at 3.5 ms to about 57 percent at 11 ms, while the width-multiplier triangles stay below and to the right of it

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.

MethodLatencyTop-1
NetAdapt, smallest pointabout 3.5 msabout 43.0%
NetAdapt, matched to MorphNetabout 4.4 msabout 46.3%
MorphNetabout 7.0 ms (6.52 ms in Table 1)46.0%
NetAdapt, matched to the multiplierabout 7.3 msabout 53.1%
Width multiplier baselineabout 12.1 msabout 52.7%
NetAdapt, largest pointabout 11.1 msabout 56.8%
Points behind the two arrows on slide 40 (values read from the chart are marked about)

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 ΔRDecayIterationsTop-1Latency
0.5 ms0.962847.7%4.63 ms
0.5 ms1.02047.4%4.71 ms
0.8 ms0.952046.7%4.65 ms
Table 2 of the NetAdapt paper: resource reduction schedules for the small MobileNetV1

Recall

Why does one NetAdapt run give a series of models, and how many?

Every iteration's winner already meets its own tighter constraint, so Net_1 to Net_i form a valid accuracy versus latency frontier. The number of models equals the number of iterations, 28 for the 0.5 ms, 0.96 schedule in the paper.

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