TL;DR
Neural architecture search, or NAS, is the automatic design of a neural network's structure. A controller program proposes an architecture, the architecture is trained and scored on a held-out validation set, and that score is used to change how the controller proposes the next architecture. The problem it solves is that the layout of a network, such as how many layers it has and which filter sizes it uses, is usually chosen by hand, and that work is slow and depends on expert intuition.
Builds on: Feedforward Neural Network, Policy Gradient, Genetic Algorithm, Hyperparameter Optimization · Leads to: DARTS, NAS with reinforcement learning
Where it's used
Image classifiers. In 2018 a team at Google used a search of this kind to find convolutional cells, small blocks that are stacked to build a full image network. The result, NASNet, was built from cells that the search had discovered rather than from a layout a person had written. The search itself was very expensive: the DARTS paper reports that NASNet's search cost 2000 GPU days.
Language models. The 2016 paper by Zoph and Le applied the same idea to recurrent networks. Instead of a convolutional layer, the controller designed a recurrent cell, the small unit that is repeated across a sequence. The cell it found reached a test perplexity of 62.4 on the Penn Treebank, which the authors report as 3.6 perplexity better than the previous best model. Lower perplexity means the model predicts the next word more easily.
Fitting a model to a budget. A team that must ship a network within a fixed amount of computing time or memory can use a search to explore designs that fit that budget. DARTS, a later method, was designed to make this cheaper. Its paper reports a search of about 1.5 to 4 GPU days for a CIFAR-10 cell, against thousands of GPU days for the earlier RL and evolution searches.
How it works
Take a tiny search space. Each architecture has two decisions: a depth, which is 1 or 2 layers, and a width, which is 4 or 8 units. So there are four possible architectures. The controller keeps a probability for each option. At the start, every option has probability 0.5.
- The controller samples an architecture. It draws the depth from its probabilities, and then the width. Suppose it draws depth 2 and width 8. Check: the draw is random, so a different run could pick depth 1 and width 4.
- Build and train the child network. The chosen architecture is built and trained on the training data. After training, it is scored on the validation set. Suppose it reaches 0.80 validation accuracy. This is a made-up number for this toy example. Check: the score comes from data the training never used, so the controller cannot cheat by memorising.
- Turn the score into a reward. The score is the reward. A higher validation accuracy is a better reward. Check: the reward is a single number per architecture, and the controller never sees how the network was trained.
- Update the controller. The controller's probabilities are nudged so that the decisions it just made become more likely if the reward was high, and less likely if it was low. The size of the nudge is the reward times how much each decision was a surprise. This is the policy gradient step from Policy Gradient, using a small step size. Check: a high reward raises the probability of the chosen options; a low reward lowers them.
- Repeat. The controller samples again. Over many rounds, the options that score well become more likely to be sampled, and the search concentrates on good regions.
flowchart LR C["Controller proposes architecture"] --> T["Train child network"] T --> V["Score on validation data"] V --> R["Reward"] R --> U["Update controller probabilities"] U --> C
The math
A controller with parameters defines a probability for each architecture . The quantity to maximise is the expected reward, the average score of the architectures it proposes:
Here is the validation accuracy of the child network built from . The notation means that is drawn from the controller's distribution.
Step 2 in symbols: the score function
The controller cannot differentiate through the accuracy, because accuracy comes from a whole training run. The trick is the score function identity, which rewrites the gradient of the expected reward as an average of rewards times gradients of log-probabilities:
Each term needs only the reward and the controller's own probabilities, so the accuracy can stay a black box.
Step 3 in symbols: the gradient for one softmax decision
Take one decision with two options and logits . The probability of option is . The gradient of its log-probability with respect to the logits is
where is a vector that is 1 in the position of the chosen option and 0 elsewhere, and is the vector of probabilities. For a chosen option , the update therefore adds times this vector, scaled by the step size.
Step 4 in symbols: the batch estimate
The paper updates the controller after a batch of architectures. Each architecture has decisions, its reward is , and the estimate is
Here is decision of architecture . The controller then moves its parameters a small step in the direction of , which is ordinary gradient ascent, the same idea as Gradient Descent.
Worked examples
Start with two options and logits , so . The controller samples option 1 and the child network scores . Use a step size of .
- The gradient of the log-probability for option 1 is .
- Multiply by the reward: .
- Multiply by the step size: .
- Add to the logits: the new logits are .
- Convert to probabilities. and , which sum to . So and .
Interpretation: option 1 was sampled and scored well, so it gained probability, from 0.50 to 0.57.
The controller samples four architectures from the same toy space, with before the update. Each decision is listed with its reward.
- Sample A: option 2 with reward . Its gradient is . Times the reward: .
- Sample B: option 1 with reward . Its gradient is . Times the reward: .
- Sample C: option 2 with reward . Times the reward: .
- Sample D: option 1 with reward . Times the reward: .
- Add the four vectors. The first entries give , and the second entries are the negatives, .
- Divide by the batch size . The estimate is .
Interpretation: option 2 was sampled twice and option 1 twice, but the option 1 samples had higher rewards. So the estimate points toward option 1, even though option 2 appeared just as often.
The 2016 paper searched for convolutional networks for the CIFAR-10 image dataset. Its controller chooses, for each layer, a filter height from 1, 3, 5 or 7, a filter width from 1, 3, 5 or 7, and a number of filters from 24, 36, 48 or 64. The paper gives the following setup for the search.
- Options per layer, from the filter height, filter width and filter count choices: .
- For an illustrative 6-layer network, with the stride choices left out: , which is about networks. The paper's own search space is larger and includes strides, so this is a rough size, not the paper's figure.
- Architectures trained: the paper reports that the controller trained 12,800 architectures.
- Epochs of training: each child network is trained for 50 epochs, so the search used epochs in total.
- Concurrency: the paper trains 800 child networks at a time, on 800 GPUs.
- Interpretation: 12,800 networks out of about is a tiny fraction of the space, so the controller has to generalise from the few it sees.
Try it: with 800 child networks trained at a time, how many batches of training does it take to train all 12,800 architectures? Answer: batches, if every batch runs in parallel and no architecture is retried.
Common mistakes and tradeoffs
It is tempting to think NAS is just random sampling of architectures. In fact the controller's probabilities change after every reward, so the sampling distribution moves toward good designs. A random search keeps a fixed distribution, and that is the difference that the controller is meant to exploit.
It is tempting to think the reward is test accuracy. In fact the reward is accuracy on a validation set, held out from training, because test accuracy must be measured only once on the final choice. Using test accuracy to guide the search would leak the test data into the design.
It is tempting to think one search gives one correct answer. In fact a single run of a search is one sample, and rerunning it with a different random seed can find a different design. A careful report says how much the result varies across runs, not just one number.
It is tempting to think a reported search cost is the whole cost. In fact some papers exclude the final training of the chosen design. The DARTS table notes that its search cost excludes both a selection step and the final training from scratch.
When to use it: when the space of designs is well defined, a fixed compute budget is available, and a good hand-made design is not already known for the task.
When not to use it: when the budget is small, when a proven architecture already fits the task, or when the search space is so large that the controller sees too few samples to learn from.
Alternatives: designing the network by hand, random search over a small grid, Bayesian Optimization over a few numeric settings, evolutionary search, or the gradient-based relaxation used by DARTS. Hyperparameter search from Hyperparameter Optimization tunes settings such as the Learning Rate of a fixed network, and NAS changes the network's structure itself.
History
Before 2016, network designs such as AlexNet and later residual networks were chosen by researchers. Hyperparameter search, including random search and Bayesian optimization, was already common for settings such as the learning rate, but it did not change the structure of the network.
In 2016 Barret Zoph and Quoc Le showed that a recurrent controller trained with reinforcement learning could propose convolutional networks and recurrent cells, and that the best of them matched or beat human designs on CIFAR-10 and Penn Treebank. Their paper, posted to arXiv that November, made the idea concrete and gave NAS its name in the form used today. The search was very costly, which led to a line of work on cheaper methods.
ENAS, by Pham and colleagues in 2018, shared weights between candidate architectures so that each candidate did not have to be trained from scratch. DARTS, by Liu, Simonyan and Yang in 2018, replaced the discrete choice with a continuous mixture over options, so that the architecture could be improved by gradient descent. DARTS reports its search at a few GPU days, against thousands for the RL and evolution searches it compares with.
Recap
- NAS is a loop: a controller proposes an architecture, the architecture is trained, its validation score becomes a reward, and the controller is updated.
- The controller is a probability distribution over design choices, and the update is a policy gradient step, so good choices become more likely.
- The validation score is the reward, because using test data in the search would leak it into the design.
- The search is expensive, which is why later work such as ENAS and DARTS aimed to reduce the cost.
Read next: the 2016 NAS paper, DARTS, and REINFORCE, the simplest policy gradient method used in the update.