TL;DR
Once-for-All (OFA) trains one large image classifier and then carves out smaller networks from it for each device, without retraining any of them. The large network is trained so that every smaller version inside it stays accurate, using a schedule called progressive shrinking. On ImageNet, the authors report 80.0% top-1 accuracy under 600 million multiply-accumulate operations, a new best for that mobile budget at the time.
Builds on: Neural Architecture Search, Weight Sharing, Pruning, Knowledge Distillation · Compares with: MobileNetV3 and EfficientNet, the mobile baselines it is measured against
Why it mattered
The paper changed the question from "which network should this device run?" to "how do we build one network that can answer that for every device?" Before it, each deployment target needed its own architecture search and its own training run. Phones, GPUs and embedded FPGAs all had different limits, and the cost grew with every new target.
The authors released the code and 50 pre-trained models for many devices and latency limits, and they report that OFA won the DSP classification track of the 3rd Low Power Computer Vision Challenge and both the classification and detection tracks of the 4th.
The problem
Suppose an app ships to dozens of phone models, each with a different chip, and a server also needs a model. The best architecture for a fast phone is not the best for a slow one. A conventional pipeline runs a neural architecture search for each device and trains the winner from scratch. The authors put the cost at roughly one full search-and-train per scenario, so scenarios cost about times as much, and the models share no weights, so the download grows with too.
The natural fix is to train one network that contains many smaller networks. That is not easy. The number of sub-networks is huge, and they all share the same weights. A naive method, updating the big network using a random sample of sub-networks at each step, makes the sub-networks fight over the shared weights, and accuracy drops. Exact training that enumerates all sub-networks at every step is far too expensive. The paper's contribution is a training order that avoids both problems.
How it works
The method runs in pipeline order: train one big network, shrink it in stages, then pick a specialist for a device.
-
Define the search space. A network is a sequence of five units. Each unit has a number of layers (its depth), and each layer has a width (its channel expansion ratio) and a kernel size (the side length of its convolution filter). The input image size is also a choice. In the paper, depth is 2, 3 or 4 layers, width expansion is 3, 4 or 6, kernel size is 3, 5 or 7, and the image side runs from 128 to 224 pixels in steps of 4. Check: a sub-network is one choice for every unit, layer and resolution, and all of them are slices of one stored network.
-
Train the largest network. Start with the full depth, full width and kernel size 7 everywhere. Train it normally on ImageNet with stochastic gradient descent. This is the teacher for the later stages. Check: this single run is the only full-size training in the whole procedure.
-
Shrink the kernel size. Let each layer's kernel be 3, 5 or 7 while depth and width stay at maximum. The 5 by 5 kernel is the centre of the 7 by 7 kernel, and the 3 by 3 is the centre of the 5 by 5, so the smaller ones reuse the weights of the big one. Fine-tune with knowledge distillation: the big network's soft predictions are a second target next to the true labels. Check: the sub-networks at this stage are already initialised from the trained large network, so they start close to good.
-
Shrink the depth. Keep the first layers of each unit and skip the rest. Fine-tune with depths drawn from 2, 3 and 4 layers. Keeping the first layers, rather than any layers, means each depth corresponds to exactly one set of layers, so the weights of early layers are shared.
-
Shrink the width. Sort each layer's channels by importance, measured by the L1 norm of their weights, meaning the sum of the absolute values. A smaller layer keeps the most important channels, which reuse the big network's weights. Fine-tune with widths drawn from 3, 4 and 6. Check: a layer that keeps 3 of 4 channels starts from the three best channels, not from random values.
-
Build the accuracy predictor. Sample 16,000 sub-networks, measure their accuracy on 10,000 validation images taken from the training set, and fit a predictor that maps an architecture and image size to a predicted accuracy. Build a latency lookup table for each target device too. Check: the sampling and predictor cost is paid once, and it does not grow with the number of devices.
-
Specialise for a device. Given a latency or MAC budget, run an evolutionary search, which keeps the best candidates and mutates them, scored by the two predictors instead of by real training or measurement. The winner is cut from the trained network and evaluated directly. For the Pixel 1 phone, the paper reports a 76.0% top-1 model at 58 ms, with no training of the chosen sub-network.
flowchart TD A[Train largest network] --> B[Shrink kernel size] B --> C[Shrink depth] C --> D[Shrink width] D --> E[Sample 16K sub-networks and fit predictors] E --> F[Search for a device budget] F --> G[Cut out specialist, no retraining]
The math
Step 1 in symbols: the objective
Let denote the weights of the once-for-all network and an architecture configuration. A selection scheme picks out the sub-network with that configuration, using the shared weights. The training problem is
where is the validation loss, and the sum runs over the sub-networks. The paper's goal is that each sub-network reaches the same accuracy it would reach if it were trained alone. Summing over all sub-networks in every update is the exact gradient, but it costs as much as training every sub-network, which is why the authors reject it.
Step 2 in symbols: how many sub-networks
For one unit, a depth gives layers, and each layer has combinations of width and kernel. So one unit has choices:
Five units make architectures, matching the paper's count of more than . Each can be run at 25 image sizes. The paper stores all of them in million parameters because they share weights.
Step 3 in symbols: the kernel transformation
The kernel is the centre of the kernel, and the kernel is the centre of the . Each shared centre is passed through a learned matrix that adapts it to the role it plays at size . A separate matrix is kept for each layer and shared across its channels. The paper counts extra parameters per layer, which is negligible next to the convolution weights.
Step 4 in symbols: channel importance
For a layer with channels and weights for channel , the importance score is
To keep of channels, sort by and keep the largest. The kept channels' weights are the ones shared with the larger layer.
Results
- ImageNet accuracy of sub-networks. For the sub-network with depth 4, width expansion 3 and kernel 3 in every layer, progressive shrinking reaches 74.8% top-1 at 226 million MACs, on par with MobileNetV3-Large. Without it, the same architecture reaches 71.5%, which is 3.3 points lower.
- Mobile phone (Pixel 1). OFA without any search or retraining reaches 76.0% top-1 at 230 million MACs and 58 ms, 0.8 points above MobileNetV3-Large at 219 million MACs and 58 ms. Fine-tuning the specialist for 25 epochs gives 76.4%, and for 75 epochs gives 76.9%.
- Progressive shrinking helps. The authors report that OFA with progressive shrinking is 3.6 points more accurate than the same method trained without it in the mobile setting.
- Under 600 million MACs. The large variant reaches 80.0% top-1, which the paper describes as a new state of the art for that budget. At 389 million MACs it reaches 79.1%, 2.8 points above EfficientNet-B0 at similar cost.
- Latency. At 143 ms on the Pixel 1, the paper reports 80.1% top-1, 0.3 points more accurate and 2.6 times faster than EfficientNet-B2.
- Design cost. Assuming 40 deployment scenarios, the paper reports total CO emissions 16 times lower than ProxylessNAS, 19 times lower than FBNet and 1,300 times lower than MnasNet. The training cost is about 1,200 GPU hours on V100s, and the search cost is about 40 GPU hours.
The limits are equally important. Numbers are for ImageNet classification at the stated budgets and on the listed devices. The search depends on the accuracy and latency predictors being good, and the paper reports latency with fixed batch sizes and framework versions, which will differ elsewhere. Fine-tuning for extra epochs buys accuracy at a cost the table makes visible.
Reading guide
- Section 1, Introduction. The cost argument: deployment scenarios, trainings, and the proposal to pay once. Read Figure 1 for the picture of the cost.
- Section 2, Related Work. Compare with NAS (see Neural Architecture Search), with compression by Pruning and Quantization, and with width-only slimmable networks. The contrast with pruning is the core of the method.
- Section 3.1, Problem formalization. The objective in Step 1 of the math. Needs Weight Sharing and the idea of a sub-network.
- Section 3.2, Architecture space. The units, layers and choices. Needs MBConv Block and Depthwise Separable Convolution for what a layer is.
- Section 3.3, Progressive shrinking. The four stages. Needs Knowledge Distillation for the teacher signal and Stochastic Gradient Descent for the optimiser. Read the kernel, depth and width bullets in order.
- Section 3.4, Specialised deployment. The predictors and the evolutionary search. Needs Genetic Algorithm for the evolutionary search, which the paper takes from regularized evolution.
- Section 4, Experiments. Read Table 1 for the design-cost comparison, and Figure 9 for accuracy against MACs.
Check yourself
QuestionWhy does the cost of covering many devices stay roughly constant with OFA but grow linearly with conventional NAS?Show answer
OFA pays one training run and one predictor-building phase, then each device's search only queries predictors and cuts out a sub-network. Conventional NAS repeats the search and the training for each device, so its total cost is proportional to the number of deployment scenarios.
QuestionIn the paper's search space, one unit has depth 2 or 3 or 4, with 9 combinations of width and kernel per layer. How many architectures does one unit offer?Show answer
. Each depth contributes one term, because a depth of means layers, each choosing one of 9 combinations.
QuestionWhy does progressive shrinking shrink the largest network first, rather than training all sub-networks together from the start?Show answer
Training all sub-networks from scratch lets them interfere through shared weights, and random sampling loses accuracy. Starting from the largest network gives well-trained weights, and each smaller stage then initialises from them, which avoids most of the interference.
QuestionA layer has 4 channels with L1 importance scores , , and . If the layer shrinks to 3 channels, which channel is dropped?Show answer
The channel with score is dropped, because it is the least important. The 3 kept channels have scores , and .
QuestionWhy is the reported 76.0% model at 58 ms not the result of a new training run?Show answer
The sub-network is cut from the once-for-all network, which was trained once. The paper states that OFA reaches the 76.0% result without retraining, and fine-tuning is an optional extra that improves it to 76.4% and 76.9%.
Sources
- Han Cai, Chuang Gan, Tianzhe Wang, Zhekai Zhang, Song Han, "Once-for-All: Train One Network and Specialize it for Efficient Deployment", arXiv:1908.09791: https://arxiv.org/abs/1908.09791
- Code and pre-trained models: https://github.com/mit-han-lab/once-for-all