AmoebaNet refers both to a method that searches for the architecture of building blocks (cells) of image classification networks through evolutionary search, gradually mutating a population of architectures and selecting good ones as parents to produce children, and to the networks found this way. It was presented by Real, Aggarwal, Huang, and Le at AAAI in 2019. The search method is Regularized Evolution, named in the paper's title, also known as Aging Evolution.
Evolutionary methods for searching network architectures have a long history, but the image classification architectures they found had not matched human-designed ones in accuracy. This paper made a small change to tournament selection, a standard evolutionary method, by removing the oldest member of the population, and found AmoebaNet-A, the first image classification architecture found this way to surpass human designs.
The search space is the same as that of NASNet (stacked cells). This allows a comparison with NASNet's reinforcement learning approach in which all conditions except the search method are held equal. In the paper's comparison, evolution found architectures as good as reinforcement learning did and, especially early in the search, reached good architectures faster.
On ImageNet, it matched the accuracy of NASNet-A at a similar size (top-1 82.8%), and a scaled-up model achieved a then state-of-the-art top-1 accuracy of 83.9%.
Theory: Aging Evolution
Aging evolution maintains a population of trained models (of size P) and repeats the following steps (Algorithm 1 in the paper; left side of the figure above).
Create the initial population: Train P architectures sampled uniformly at random from the search space and add them to the population.
Sample candidates: Draw S models uniformly at random (with replacement) from the population. The sampled models remain in the population.
Select a parent: Among the candidates, the model with the highest validation accuracy becomes the parent.
Create a child: Apply one mutation (a small random change) to the parent's architecture to create the child's architecture.
Train and add the child: Train and evaluate the child and add it to the newest end of the population.
Remove the oldest: Remove the model that was trained earliest from the population, keeping the population size at P.
Steps 2–6 are repeated until C models have been evaluated, and the architecture with the highest accuracy among all evaluated models is returned. The paper uses P=100 and S=25.
The only difference from standard tournament selection (called "non-aging evolution" in the paper) is step 6. Non-aging evolution removes the candidate with the lowest accuracy among those sampled, so good models stay in the population indefinitely. Aging evolution removes the oldest model regardless of accuracy, so every model leaves the population after a fixed number of iterations.
Each iteration applies exactly one of the following two kinds of mutation (lower right of the figure above).
Hidden-state mutation: Choose either the normal cell or the reduction cell, uniformly pick one of its five pairwise combinations and one of that combination's two elements, and replace that element's input hidden state with another hidden state within the cell. The choice is made so that no loops are formed.
Op mutation: Pick an element in the same way and replace its operation with a random operation from a fixed set of candidates.
There is also an identity mutation that changes nothing, fixed at probability 0.05 in the paper. The candidate operations are identity, 3×3, 5×5, and 7×7 separable convolutions, 3×3 average pooling and max pooling, 3×3 dilated separable convolution, and a 1×7 followed by 7×1 convolution.
The paper describes evolution as "random search plus selection." The part that creates new architectures through mutation is fully random and handles breadth (exploration). The part that selects only good models as parents handles probing deeply around good architectures (exploitation). S controls the strength of this selection: with S=1 the method becomes a form of random search, and larger S makes it increasingly select only good models as parents.
Why Removing by Age Helps
Training neural networks involves variance from factors such as random seeds. The same architecture can occasionally reach a high accuracy by chance. The paper conjectures that aging evolution works because it is robust to this variance, as follows.
In non-aging evolution, a model that happened to get a lucky high accuracy stays in the population forever. It is selected as a parent again and again and produces many children, so the search becomes biased around that model and cannot explore broadly.
In aging evolution, every model leaves the population quickly. The only way for an architecture to persist is to be inherited from parent to child, and each time it is inherited the child is retrained. Only architectures that achieve good accuracy when retrained survive, so architectures that are good when retrained, rather than lucky ones, are selected.
As an analogy, instead of keeping a player on the national team forever after one high score, the team is reshuffled every time, and the traits of players who perform well no matter how many times they are selected are carried forward. The paper regards this as a kind of regularization that prevents overfitting to training noise, hence the name "regularized evolution."
This explanation is the paper's conjecture. In supplementary experiments, the paper confirms that aging evolution is better even in a simple search space where evaluations are merely noisy, and leaves further verification to future work. In addition, small-scale comparisons run on CPUs showed a tendency for aging evolution to outperform non-aging evolution across many settings of the population size P and the sample size S.
Experimental Results
The search was performed on CIFAR-10, training and evaluating small models (N=3, F=24) for 25 epochs each. A single search evaluated 20,000 models on 450 GPUs (K40) and took about 7 days. Evolution, reinforcement learning, and random search were each run 5 times with the same code and compared.
Search speed: Evolution found models with higher accuracy than reinforcement learning early in the search. When continued to 20,000 models, evolution and reinforcement learning reached similar accuracy. Both outperformed random search.
Compute of the found models: Comparing top models scaled up and retrained, evolution's models had accuracy similar to reinforcement learning's models with fewer FLOPs.
The architecture with the highest validation accuracy found in the search is called AmoebaNet-A. The CIFAR-10 results are as follows (Table 1 in the paper).
Because AmoebaNet-A was found on CIFAR-10, it is not an architecture overfit to ImageNet. The paper reports that it matches the accuracy of NASNet-A at the same size and, when scaled up, set the state of the art at the time.
Practical Considerations
Evolutionary search also trains a model for every candidate, so it is computationally expensive. A single search in the paper took about 7 days on 450 GPUs (20,000 models). To search with modest compute, shrink the evaluated models and reduce the number of training epochs, or consider ENAS, which shares weights, or DARTS, which searches with gradients.
The results are comparisons on this search space and data. The paper itself states that whether the same conclusions hold for other search spaces, data, and tasks is future work. In small supplementary experiments, across combinations of 3 search spaces and 3 datasets, evolution performed as well as or better than reinforcement learning.
Few meta-parameters need tuning. The paper tuned only P and S, trying five combinations (100/2, 100/50, 20/20, 100/25, 64/16) and choosing 100/25. Reinforcement learning, by contrast, requires tuning parameters such as the controller's learning rate.
Evolution is easy to parallelize. Unlike generational methods that wait for all models to finish training, aging evolution can move to the next iteration each time a single child finishes training, so many machines can be kept busy.
Tricks in the final training also contribute to accuracy. Training the scaled-up AmoebaNet-A uses RMSProp, label smoothing, an auxiliary classifier, NASNet's ScheduledDropPath, and more.
Comparison with Other Methods
AmoebaNet uses the same search space as NASNet and changes only the search method. The CIFAR-10 error rates are the values reported in each paper, and conditions such as the use of Cutout are not the same.
When many machines are available and a simple search with little tuning is preferred, aging evolution is a good fit. There is no controller to train with backpropagation, and the implementation is short.
The paper also notes that when compute is limited and the search may be stopped early, evolution has an advantage because it tends to find good architectures early.
To search with around a single GPU, choose ENAS or DARTS, which do not train each candidate.
Separately from architecture search, Population Based Training evolves training hyperparameters within a population.
PyTorch example
▶Show code
python
import collections
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.utils.data import DataLoader, Subset
"""
Image classification task using MNIST data
Search for NASNet-search-space cells with aging evolution (Algorithm 1 in the paper).
To keep computation light, only the normal cell is searched, and each child is trained for one epoch on a small subset of the data
"""
P, S, C = 10, 3, 30 # population size, sample size, total number of architectures evaluated (paper: P=100, S=25, C=20,000)
NUM_COMB = 5 # number of pairwise combinations in a cell
OPS = ['identity', 'sep_3x3', 'sep_5x5', 'avg_3x3', 'max_3x3'] # a subset of the paper's candidates
device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))])
full_train = datasets.MNIST(root='./data', train=True, download=True, transform=transform)
train_loader = DataLoader(Subset(full_train, range(0, 3000)), batch_size=64, shuffle=True)
val_loader = DataLoader(Subset(full_train, range(55000, 60000)), batch_size=256)
def random_architecture():
"""Combination i picks two of hidden states 0..i+1, applies an op to each, and adds them (hidden states 0 and 1 are the cell inputs)"""
return [(random.randrange(i + 2), random.choice(OPS), random.randrange(i + 2), random.choice(OPS)) for i in range(NUM_COMB)]
def mutate(arch):
"""Apply exactly one hidden-state mutation or op mutation (identity mutation that changes nothing with probability 0.05)"""
arch = [list(c) for c in arch]
r = random.random()
if r < 0.05:
return [tuple(c) for c in arch]
i = random.randrange(NUM_COMB) # pick one combination
k = random.randrange(2) # one of its two elements
if r < 0.525: # hidden-state mutation: choose only from earlier hidden states, so no loops form
arch[i][2 * k] = random.randrange(i + 2)
else: # op mutation
arch[i][2 * k + 1] = random.choice(OPS)
return [tuple(c) for c in arch]
def make_op(name, ch):
if name == 'identity':
return nn.Identity()
if name.startswith('sep'):
k = int(name[-1])
return nn.Sequential(nn.ReLU(), nn.Conv2d(ch, ch, k, padding=k // 2, groups=ch, bias=False),
nn.Conv2d(ch, ch, 1, bias=False), nn.BatchNorm2d(ch))
pool = nn.AvgPool2d if name.startswith('avg') else nn.MaxPool2d
return pool(3, stride=1, padding=1)
class Cell(nn.Module):
def __init__(self, arch, ch):
super().__init__()
self.arch = arch
self.ops = nn.ModuleList([nn.ModuleList([make_op(o1, ch), make_op(o2, ch)]) for _, o1, _, o2 in arch])
used = {i for i1, _, i2, _ in arch for i in (i1, i2)}
self.outputs = [i for i in range(2, 2 + NUM_COMB) if i not in used] # concatenate unused hidden states
self.proj = nn.Conv2d(ch * len(self.outputs), ch, 1)
def forward(self, h0, h1):
states = [h0, h1]
for (i1, _, i2, _), (op1, op2) in zip(self.arch, self.ops):
states.append(op1(states[i1]) + op2(states[i2]))
return self.proj(torch.cat([states[i] for i in self.outputs], dim=1))
class Net(nn.Module):
def __init__(self, arch, ch=16):
super().__init__()
self.stem = nn.Sequential(nn.Conv2d(1, ch, 3, padding=1, bias=False), nn.BatchNorm2d(ch))
self.cell1, self.cell2 = Cell(arch, ch), Cell(arch, ch)
self.head = nn.Sequential(nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(ch, 10))
def forward(self, x):
s = self.stem(x)
c1 = self.cell1(s, s) # the first cell receives the same input twice
c2 = self.cell2(s, c1) # later cells receive the outputs of the previous two cells
return self.head(c2)
def train_and_eval(arch):
model = Net(arch).to(device)
opt = optim.SGD(model.parameters(), lr=0.05, momentum=0.9)
model.train()
for x, y in train_loader:
opt.zero_grad()
F.cross_entropy(model(x.to(device)), y.to(device)).backward()
opt.step()
model.eval()
correct = 0
with torch.no_grad():
for x, y in val_loader:
correct += (model(x.to(device)).argmax(1) == y.to(device)).sum().item()
return correct / len(val_loader.dataset)
# Aging evolution (Algorithm 1)
population = collections.deque() # left is oldest, right is newest
history = []
while len(population) < P: # initial population: random architectures
arch = random_architecture()
model = (arch, train_and_eval(arch))
population.append(model)
history.append(model)
while len(history) < C:
sample = [random.choice(population) for _ in range(S)] # sampled models stay in the population (with replacement)
parent = max(sample, key=lambda m: m[1])
child_arch = mutate(parent[0])
child = (child_arch, train_and_eval(child_arch))
population.append(child) # add to the newest end
history.append(child)
population.popleft() # remove the oldest (regardless of accuracy)
best = max(history, key=lambda m: m[1])
print(f"best val acc: {best[1]:.4f}")
print(best[0])
FAQ
Q. What is the difference between aging evolution and standard tournament selection?
A.
The only difference is what gets removed from the population. Standard tournament selection (non-aging evolution) removes the model with the lowest accuracy among the sampled candidates, so good models stay forever. Aging evolution removes the oldest model in the population regardless of accuracy. As a result, the search is less likely to become biased toward models that happened to get high accuracy due to training noise.
Q. Why is it called "regularized evolution"?
A.
Because the paper regards removal by age as a mechanism that prevents overfitting to training noise. Since models leave quickly, an architecture can persist only by being inherited from parent to child and continuing to achieve good accuracy when retrained. The paper views adding the information that "an architecture should be good when retrained" to the search as regularization in a broad sense. The paper presents this, however, as a conjecture.
Q. Which is better, evolution or reinforcement learning?
A.
In the paper's comparison (NASNet search space, CIFAR-10), both reached similar accuracy when the search was run to completion, while evolution found good architectures earlier and its models required less compute. On the other hand, the paper also notes that reinforcement learning might do better with careful tuning and that the results may be limited to this search space and data. Simplicity and less tuning are the advantages of evolution.