Designing a fresh network for every phone, GPU and chip costs 40,000 GPU hours each. Train one once-for-all network instead, and pick a sub-network for each device in seconds.
Learn how a search can judge a design cheaply, measure real speed on real hardware, and serve many devices from one training run.
Drag the number of devices. Compare one search per device with one once-for-all network. Then we build, piece by piece, the tricks that make this possible: shared weights, latency tables, elastic layers, and searches that skip training.
You need the idea of a search space (a menu of possible networks) and a little Python for the code. We build the rest from zero.
Based on Lecture 8 of MIT 6.5940: TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Course page and slides. Every idea is re-taught here in our own words and devices; it follows Lecture 7, Neural Architecture Search I in this series.
The lecture gives 40K GPU hours for one device, 160K for four and 1,600K for many (40 here). The slide gives no figure for the once-for-all run, so its 40K bar is illustrative.
Chapter 0
See why the best network depends on where it runs, and why finding it must not cost a data center
You finish a photo app. It must run on a new phone, an old phone and a camera chip with 256 KB of memory. One network cannot serve all three: it is too slow for the chip and too small to use the new phone well.
Neural architecture search, or NAS, is a program that designs a network for you. This lecture is Part II of the story. It asks one question: for each device, which network is the best one that still fits?
The lecture opens with four goals that pull against each other. A bigger network is usually more accurate. It is also slower, uses more battery and takes more memory.
Part I covered the first two parts. This lecture covers the third, and then puts the hardware inside the search.
Cloud AI runs at about 1012 FLOPS, mobile AI at about 109 and tiny AI at about 106. A factor of one million separates the largest device from the smallest. So the device is an input to the search, and each device gets its own answer.
Each dot below is one candidate network, placed by its latency and its accuracy. You are the search strategy. Set a latency budget and take the most accurate dot to the left of the line.
Each dot is a candidate network. The purple ring marks the most accurate one that fits the budget. Drag the budget.
Illustrative: 40 made-up candidates drawn from a smooth trade-off curve plus noise, so you can see every one. Real search spaces hold billions of networks.
Move the line left and the pick gets faster and less accurate. A dot under the curve loses to another dot that is both faster and more accurate, so a good search never returns it.
Each dot costs two measurements. Its accuracy needs a training run, and its latency needs a run on the device. If either is slow, the search never ends. Each chapter below removes one of those two costs.
Chapter 1
Compare three ways to estimate accuracy: train every design, inherit weights from a parent, or let a second network write the weights
The accuracy estimation strategy scores one candidate network. The lecture gives three answers, from the most expensive to the cheapest.
A controller, a small recurrent network, writes down an architecture. The system trains that child network and measures its validation accuracy R. R is the reward that teaches the controller (Zoph and Le, ICLR 2017).
On CIFAR-10 the lecture counts 12,800 trained architectures and 22,400 GPU-hours: 1.75 GPU-hours per design, on a small dataset. ImageNet and COCO cost far more. The drawback is prohibitive training cost.
Copy a trained parent's weights into a child that is a small edit of it, then train a little: weight inheritance. The child must start out computing the parent's function. Net2Net (Chen et al., ICLR 2016) gives two such edits. Net2Wider adds neurons, and Net2Deeper adds an identity layer.
Take one input x and two hidden neurons, h1 = ReLU(2x) and h2 = ReLU(3 − x). The output is y = 1.0 h1 + 0.8 h2, so at x = 1, y = 2 + 1.6 = 3.6. Now copy neuron 2. Call its outgoing weight before the edit a-old, the number of copies after the edit r, and the weight each copy gets a-new.
A-new equals a-old divided by r.
Make r copies of the neuron. Give each copy the weight a-old divided by r. Together the copies add exactly the old neuron's share.
A-old is 0.8 and r is 2, so a-new is 0.4. At x = 1 both copies output 2, so y = 2 + 0.4 × 2 + 0.4 × 2 = 3.6, as before. Keeping 0.8 on both copies gives 5.2.
Turn on Widen to copy neuron 2. Turn off Halve to see a careless copy. Drag x to test other inputs.
A toy network built for this lesson, after Net2Wider in Net2Net (Chen et al., ICLR 2016).
With Halve off, y at x = 1 jumps from 3.6 to 5.2, so the child starts far from its parent. Exact copies also get identical gradients, so Net2Net adds a little noise to let them drift apart.
Cai et al. (AAAI 2018) turned this into a search: the controller outputs edits, such as "make this layer wider", instead of whole architectures.
A hypernetwork is a network whose output is another network's weights. In SMASH (Brock et al., ICLR 2018), it writes weights for a random architecture at each step. Gradient descent updates the hypernetwork, never the child.
After that one run, scoring a design is cheap: generate its weights, run the validation set, read the accuracy.
pythondef net2wider(W1, b1, W2, j): # W1 (H,D) in, b1 (H,), W2 (O,H) out; copy hidden unit j W1n = np.vstack([W1, W1[j:j+1]]) # (H+1, D): the copy sees the same inputs b1n = np.append(b1, b1[j]) # (H+1,) W2n = np.hstack([W2, W2[:, j:j+1]]) # (O, H+1) W2n[:, j] /= 2; W2n[:, -1] /= 2 # split the outgoing weight over r = 2 copies return W1n, b1n, W2n # same function, wider layer
Chapter 2
Skip the cheap stand-in task, and keep memory flat by letting only one candidate path run at each layer
A general model for all hardware is inefficient. A model specialized for one device, a Raspberry Pi, a GPU, a CPU or a phone, is efficient. To find it, the search must run on that device's real task, and early NAS could not afford that.
NASNet needed 48,000 GPU hours even on CIFAR-10, about 5 years on one GPU. DARTS, which searches by gradient descent, needs about 100 GB of GPU memory to search ImageNet directly. So earlier work searched a proxy task, a cheap stand-in, and then transferred the winner. On the real task that winner was often sub-optimal. ProxylessNAS (Cai et al., ICLR 2019) removes every proxy:
| What the search uses | Proxy search | ProxylessNAS |
|---|---|---|
| Dataset | CIFAR-10 | ImageNet |
| Search space | Small (low depth) | Large |
| Training | Fewer epochs | Full training |
| Speed signal | FLOPs and parameter counts | Profiled latency |
Build an over-parameterized network: at every layer, put all candidate operations side by side, such as a 3 × 3 convolution, a 5 × 5 convolution, pooling and identity. Think of a road with five lanes at every junction. Each lane has an architecture parameter, a score for how much the search likes it. Training this one network is the whole search. At the end, prune the lanes with low scores.
Backpropagation needs the output of every lane that ran. If all N lanes run, memory grows as O(N), and that is where the 100 GB comes from. ProxylessNAS gives each lane a binary gate: 1 keeps it and 0 prunes it. It binarizes the architecture parameters so that one path is active per step. Memory falls from O(N) to O(1).
Count it for 20 layers with N = 5 lanes. Each operation outputs a 56 × 56 × 64 map in 32-bit floats: 802,816 bytes, about 0.77 MiB per image.
Each column is a layer and each box is a candidate operation. Filled boxes are alive and hold a tensor in memory. Change the number of lanes, then press Resample.
Illustrative arithmetic: 20 layers, a 56 by 56 by 64 float32 output per operation, a batch of 64, operation outputs only. The picture shows 6 of the 20 layers.
In One path mode the memory bar stays flat for any N. The factor between the two modes is exactly N.
Training alternates two steps. First, update the weights of the one active path. Second, update the architecture parameters, so that good paths get picked more often. After many rounds, keep the best path in each layer.
pythondef mixed_op_forward(x, ops, alpha): # x (B,C,H,W); ops: list of N modules; alpha (N,) p = softmax(alpha) # how much the search likes each lane k = np.random.choice(len(ops), p=p) # binary gate: one lane gets 1, the rest 0 return ops[k](x), k # only ops[k] output is kept for backprop: O(1)
Chapter 3
See two networks with equal arithmetic and far apart in speed, then learn two ways to put real milliseconds into a search
Two 20 km routes take different times if one has forty traffic lights.
For a network, the distance is MACs, the count of multiply-accumulate operations (FLOPs are about twice MACs). The trip time is latency. On a Google Pixel 1, NASNet-A and AmoebaNet-A have slightly fewer MACs than MobileNetV2 (1.4). Yet they take about 183 and 190 ms against 143.
The lecture grows a Transformer on an Nvidia Titan xp in two ways, deeper or wider, over the same 159 M to 326 M FLOPs.
Two ways to grow a Transformer. Drag the growth step and watch the latency of each on the chosen device.
GPU numbers are the lecture's (Titan xp). The CPU shape is illustrative, after the lecture's Raspberry Pi plot.
On the GPU, the deeper network slows from 52 to 261 ms, while the wider one stays near 51. A GPU runs thousands of multiplications at once, so width fills idle lanes, but extra layers run one after another. On a Raspberry Pi CPU, with few lanes, width raises latency a lot.
MnasNet (Tan et al., CVPR 2019) times each candidate on a phone: slow and expensive. Instead, measure once and store a latency model for the search to ask.
The first model is a latency lookup table: profile each operation once on the device. Call the table T, the operation at layer l op-l, and the shape of its input shape-l.
Latency of net equals the sum over l of T at op-l, shape-l.
For each layer l, look up the time of op-l at shape-l in T. Add the times.
The six default layers of the made-up table below sum to 0.8 + 2.3 + 1.2 + 0.05 + 2.3 + 0.8 = 7.45 ms. The pretend device measures 8.07 ms: the table is 8 percent low.
Press a layer button to cycle its operation. The bars show the time each layer takes in the table.
A made-up phone table: conv 3 × 3 2.3 ms, conv 5 × 5 4.1, dw 3 × 3 0.8, dw 5 × 5 1.2, skip 0.05. The pretend measurement adds 3 percent plus 0.4 ms.
A table of 100 entries at 3 s each takes 5 minutes per device. Timing 50,000 candidates takes about 42 hours.
The second model, a latency prediction model, maps a whole design to one latency. HAT's predictions on a Raspberry Pi ARM CPU sit close to the line y = x.
The failure: a table ignores how layers interact. If it says 15 ms and the device says 19, train a network-wise predictor.
pythonLAT = {'conv3': 2.3, 'conv5': 4.1, 'dw3': 0.8, 'dw5': 1.2, 'skip': 0.05} # profiled once per device, ms def table_latency(ops): # ops: one name per layer return sum(LAT[o] for o in ops) def predictor_latency(feat, W1, W2): # feat (d,): layers, kernel, width, heads, ... h = np.maximum(feat @ W1, 0) # (hidden,) return float(h @ W2) # one number: predicted ms
Chapter 4
Check that a model made for one device beats a model made for another, then see how a single trained network can hold more than 1019 models
Does a model searched for one device win there? ProxylessNAS searched three times, for a GPU, a CPU and a phone, then timed each model on all three. Top-1 accuracy on ImageNet stays near 75 percent, so the speeds compare.
Choose where the model runs. The bars show each searched model's latency there.
From the lecture's ProxylessNAS table. Top-1 accuracy: 75.1 percent for the GPU model, 75.3 for the CPU model, 74.6 for the mobile model.
Each model is fastest on its own device. On the phone, the phone model takes 78 ms and the GPU model 124. The lecture adds that the specialized model is 1.83 times faster than a non-specialized one on mobile, with a larger gain on GPU.
Each device needs many search episodes of expensive training, and then the winner trains again. MnasNet's design cost is about 40K GPU hours per device.
The cost is devices times episodes times training, so each new phone, chip or battery mode multiplies it.
The child networks share the big network's weights and train jointly, so they split one training cost. One OFA network serves GPUs (H100, 4090, Orin), Cortex M7 and M4 microcontrollers (256 KB to 512 KB of memory), Samsung S22, S21 and S20 phones, and a phone's battery states.
One OFA network holds more than 1019 sub-networks. Call the number of kernel sizes a layer may use k, the number of widths w, the depth of a unit in layers d, and the number of units U.
N-nets equals the sum over d of k times w to the d, all to the power U.
Multiply k by w for one layer. Raise that to the power d and add over the depths to count one unit. Raise the unit count to the power U.
K times w is 9. One unit has 92 + 93 + 94 = 81 + 729 + 6,561 = 7,371 options. Five units give 7,3715, about 2.2 × 1019, the slide's order of magnitude.
Each column is a unit, and each box is a layer, shaded by kernel and sized by width.
Illustrative menu: kernels 7, 5, 3; width multipliers 6, 4, 3; depths 2 up to the largest; 5 units. Resolution is elastic too, but this count leaves it out.
pythondef count_subnets(k, w, depths, units): # k kernel sizes, w widths, depths e.g. [2,3,4] per_unit = sum((k * w) ** d for d in depths) return per_unit ** units # count_subnets(3,3,[2,3,4],5) = 2.18e19 def specialize(ofa, device, budget_ms, tries=1000): best = None for _ in range(tries): # each try takes seconds: nothing is trained sub = ofa.sample() if device.latency(sub) <= budget_ms and (best is None or ofa.accuracy(sub) > ofa.accuracy(best)): best = sub return best
The failure this removes: each new phone costing another 40K GPU hour search. With OFA, it costs seconds. Next: how one set of weights serves so many shapes.
Chapter 5
Follow the order of the lecture's four stages: resolution, kernel size, depth and width, and see how each smaller network borrows weights from a bigger one
Progressive shrinking trains the once-for-all network in stages: full first, then one dimension at a time becomes elastic. The order is resolution (input image size), kernel size, depth (layers per unit) and width (channels per layer). Each smaller network starts from a bigger one's weights.
Resolution needs no new weights: each batch gets a random image size.
A kernel is the small grid of weights a convolution slides over the image. A 5 × 5 kernel takes the center of the full 7 × 7 and changes it with a learned transformation matrix, M. The 3 × 3 comes from the 5 × 5 with a 9 × 9 matrix.
W-five-by-five equals reshape of M-twenty-five-by-twenty-five times flat of center-five-by-five of w-seven-by-seven.
Crop the center of w-seven-by-seven, flatten it, multiply by M, and fold the result into a 5 × 5 grid.
The crop reads 25 of the 49 weights. M holds 25 × 25 = 625 numbers and the 3 × 3 step adds 81, so both small sizes cost 706 numbers per layer. With M the identity, w-five-by-five is the plain crop.
Left: the full 7 by 7 kernel, with the block the chosen size reads outlined. Right: the kernel the layer uses.
Toy weights and a toy matrix near the identity; training learns the real ones. The matrix shapes, 25 × 25 and 9 × 9, are the lecture's.
To shrink depth, a unit, a short stack of layers, skips its later layers and outputs O1, O2 or O3 in the lecture. Early layers must work alone and start longer stacks, so depth shrinks 4, then 3, then 2.
Width is the number of channels, the feature maps a layer makes. The lecture sorts channels by importance, so a narrow layer keeps the best. Its example is 0.02, 0.15, 0.85, 0.63. Keeping two after sorting keeps 1.48 of 1.65, about 90 percent. Unsorted, it keeps about 10 percent.
Bar height is channel importance, and filled bars stay. Turn sorting off to see what random order costs.
The first four scores (0.02, 0.15, 0.85, 0.63) are the lecture's example. We made up the other four.
Sorting physically reorders the weights between stages, so a narrow layer is a prefix. Skip it and the half-width network falls far below its parent.
Press a stage. Lit boxes are dimensions that are elastic by then.
Counts use the Chapter 4 menu: 5 units of 4 layers, kernels 7, 5, 3, widths 6, 4, 3, depths 2 to 4. Resolution is left out.
pythondef small_kernel(w7, M25): # w7 (C,7,7); M25 (25,25) learned crop = w7[:, 1:6, 1:6].reshape(-1, 25) # centered 5x5 block, (C,25) return (crop @ M25.T).reshape(-1, 5, 5) # the 5x5 kernel the layer uses def sort_channels(W, importance): # W (C_out, C_in, k, k); importance (C_out,) order = np.argsort(-importance) # highest score first return W[order], order # narrow nets keep W[:k]
Chapter 6
Pick a sub-network for a device with no training, and see why a design with more arithmetic per byte runs faster on a chip with scarce memory bandwidth
With the big network trained, a new device needs no training run. Draw a sub-network, read its predicted latency and estimated accuracy, and keep the best one under the limit.
Below, 400 random sub-networks meet a CPU-like device that pays per multiplication and a GPU-like one that pays mostly per layer.
Each dot is one sub-network. The purple ring is the best dot left of the budget line. Switch device and watch the pick change.
Illustrative: we invented both latency models and the accuracy score. They copy only the lecture's point that the best sub-network depends on the device.
On the GPU-like device the pick uses fewer, wider layers. Each check is one lookup, so hundreds take seconds. A launch has four steps:
On three phones (Samsung S7 Edge, Google Pixel 2, LG G8), an Nvidia 1080Ti, an Intel Xeon CPU and a quantized Xilinx ZU3EG FPGA, OFA's curve of ImageNet top-1 against latency lies above MobileNetV3 and MobileNetV2. The GPU runs at batch 64, the CPU and FPGA at batch 1.
The lecture explains one win with a roofline. A chip computes at most Peak operations per second and fetches at most BW bytes per second, its bandwidth. A program's arithmetic intensity, I, is the operations it does for each byte it moves. Call the speed it reaches Perf.
Perf equals the minimum of Peak and B-W times I.
BW times I is how fast memory feeds the chip. Below Peak, the program is memory bound and gets BW times I. Above, it gets Peak.
A toy chip has Peak 100 GOPS/s and BW 2 GB/s. At I = 20, min(100, 2 × 20) = 40 GOPS/s: memory bound. The ridge sits at 100 / 2 = 50 Ops/Byte.
The line is the most a toy chip can reach. Drag intensity up the slope to the roof. The marks are the lecture's FPGA results.
A toy roofline: peak 100 GOPS/s, bandwidth 2 GB/s. The marks use the lecture's ZU3EG FPGA throughput: MobileNet-v2 48, MnasNet 44, OFA 76 GOPS/s. We placed them on the x axis from the toy slope.
The OFA model has higher arithmetic intensity, so it is less memory bound. On the ZU3EG FPGA it reaches 76 GOPS/s, against 48 for MobileNet-v2 and 44 for MnasNet. That is 1.6 times MobileNet-v2, with no change to the hardware design.
The search never needs the word roofline: measured latency already punishes a layer that waits for memory. A search on operation counts misses this and leaves the peak unused.
pythondef roofline(intensity, peak_gops, bw_gbs): # Ops/Byte, GOPS/s, GB/s return min(peak_gops, bw_gbs * intensity) # GOPS/s the program can reach # roofline(20, 100, 2) = 40.0 (memory bound) roofline(60, 100, 2) = 100.0 (compute bound)
Chapter 7
Keep a pre-trained model's knowledge, search only its attention layers, and trade a growing memory for a fixed one
One reader keeps every page read in a backpack, to look back at any page. After ten thousand pages the pack is a burden. A second reader keeps a summary note of fixed size, and loses details. These are the two kinds of attention in a language model.
The goal: full-attention accuracy with linear-attention efficiency, without pre-training from scratch. Jet-Nemotron gets there with PostNAS, which means NAS run after pre-training (Gu et al., NeurIPS 2025).
PostNAS starts from a trained Qwen2.5-1.5B. It freezes the MLP layers, which hold much of the knowledge, and searches only the attention. The lecture lists four steps.
For each full-attention layer and each token, the model stores one key and one value per KV head. Call the number of full-attention layers L-full, the number of KV heads H-kv, the size of each head d, the context length in tokens T, and the bytes per stored number b.
Cache equals two times L-full times H-k-v times d times T times b.
Multiply the six numbers. The cache grows in step with T and with L-full, so a search that cuts L-full cuts the bill for every token read.
Qwen2.5-1.5B has L-full = 28, H-kv = 2 and d = 128. At T = 65,536 tokens with b = 2: 2 × 28 × 2 × 128 × 65,536 × 2 = 1,879,048,192 bytes, or 1,792 MiB, the slide's 1,792 MB. With L-full = 3 the cache falls to 192 MiB.
Each box is a layer. Yellow layers use full attention and keep a growing cache. Blue layers use linear attention and keep a fixed note. Drag both sliders.
Illustrative: we spread the lecture's 1,792 MB for Qwen2.5-1.5B at 64K tokens evenly over 28 layers (64 MB each) and scale it with context. The table below holds the lecture's measured values.
Jet-Nemotron-2B measures 154 MB, between 3 and 2 full layers, probably because it also uses sliding-window attention in some layers. At 256K tokens, 3 full layers cost 768 MB, while all 28 would cost 7,168 MB.
| Model | KV cache (MB) | Tokens per second | MMLU | MMLU-Pro | BBH |
|---|---|---|---|---|---|
| Qwen2.5-1.5B | 1,792 | 241 | 59.5 | 28.9 | 44.1 |
| Qwen3-1.7B-Base | 7,168 | 61 | 60.3 | 37.8 | 54.2 |
| Gemma3n-E2B | 768 | 701 | 53.9 | 24.3 | 45.1 |
| Mamba2-2.7B | 80 | 2,507 | 25.1 | 8.6 | 25.7 |
| Jet-Nemotron-2B | 154 | 2,885 | 60.8 | 39.0 | 58.3 |
| Jet-Nemotron-4B | 258 | 1,271 | 65.2 | 44.2 | 65.0 |
The lecture measures throughput on an H100 GPU at 64K context. Jet-Nemotron-2B beats Qwen3-1.7B-Base on all three tests. It generates 47 times faster (2,885 / 61) with a cache 46 times smaller (7,168 / 154). At a 256K context the lecture reports 53.6 times faster decoding and 6.1 times faster prefilling.
pythondef kv_cache_bytes(full_layers, kv_heads, head_dim, tokens, bytes_per=2): return 2 * full_layers * kv_heads * head_dim * tokens * bytes_per # 28 layers, 2 KV heads, 128 dims, 64K tokens, 16-bit: 1,879,048,192 bytes = 1,792 MiB
The failure: a linear model that is fast and wrong, like Mamba2 at 8.6 on MMLU-Pro. Fix: keep a few full-attention layers, placed where a search says they matter.
Chapter 8
Judge an untrained network by how it reacts to a nudge, or by whether its gradients agree, and rank thousands of designs in seconds
Zero-shot NAS scores an untrained network: zero training steps. The lecture covers two methods, ZenNAS and GradSign.
ZenNAS (Lin et al., ICCV 2021) says a good network reacts strongly to a small change in its input. The lecture's recipe:
Batch normalization layer i rescales each channel j by its spread, sigma-i-j. Over its c-out channels that gives a root mean spread, sigma-bar-i.
Z-Zen equals z-1 plus z-2. Z-2 is the sum over i of log sigma-bar-i. Sigma-bar-i is the square root of the sum over j of sigma-i-j squared, over c-out.
Z-1 is the log of the output change. For each layer, take the log of the root mean channel variance, and add them to get z-2. Add z-1 and z-2.
With made-up numbers: the output moves 0.5, so z-1 = −0.69. Variances 4, 4, 1, 7 give sigma-bar = √(16 / 4) = 2. Sigma-bars 2, 1.5, 1 give z-2 = 0.69 + 0.41 + 0 = 1.10. So z-Zen = 0.41.
The curve scores depths 1 to 8 at your width, and the ring is your network.
A real forward pass of a toy network: 16 inputs, a batch of 8, normal weights, batch norm and ReLU per layer, perturbation 0.01. The paper measures the link to accuracy.
Wider and deeper networks score higher. The score ranks networks; it does not predict accuracy.
GradSign (Zhang and Jia, ICLR 2022) checks whether training samples push each parameter the same way at the random start. Call the number of samples n and of parameters m. Call the sign (+1 or −1) of sample i's gradient at parameter k g[i, k].
Tau equals the sum over k from 1 to m of the absolute value of the sum over i from 1 to n of g of i, k.
For each parameter k, add the n signs g and drop the sign of the total. Add the m totals to get tau.
With the made-up signs of the device below, 4 samples and 3 parameters, the sums over i are 4, 2 and 0. So tau = 6 of a possible n × m = 12.
Rows are samples, columns are parameters. Press a cell to flip its sign.
A hand-sized example. A real run uses thousands of samples and millions of parameters, with signs from backpropagation at a random start.
pythondef zen_score(net, x, eps=0.01): # x (B,D) ~ N(0,1); net weights ~ N(0,1), BN layers inside z1 = np.log(np.abs(net(x + eps * np.random.randn(*x.shape)) - net(x)).mean()) z2 = sum(np.log(np.sqrt(v.mean())) for v in net.bn_variances) # per BN layer return z1 + z2 def gradsign(per_sample_grads): # (n, m): gradient of each sample at init g = np.sign(per_sample_grads) # (n, m) of +1 / -1 return np.abs(g.sum(axis=0)).sum() # tau, at most n * m
The failure: a score that ranks well in one search space and badly in another. Train the top five, check the rank correlation, and use the score only as a filter before a short list.
Chapter 9
Design the accelerator and the network in one loop, and learn how to hand a search a choice that has no natural number
A menu planned without the kitchen cooks badly. NAAS, Neural Accelerator Architecture Search (Lin et al., DAC 2021), plans the neural architecture and the accelerator architecture, a custom chip like the TPU, in one loop.
| Part | Choices | Kind |
|---|---|---|
| Accelerator | Local buffer size, global buffer size, number of processing elements (PEs) | Architectural sizing |
| Accelerator | Compute array size, PE connectivity | Connectivity parameters |
| Compiler | Loop orders, loop tiling sizes, dataflow | Mapping |
| Neural network | Layers, channels, kernel size, bypass, input and weight quantization precision | Network |
A processing element (PE) is a small compute unit with its own memory. A buffer is on-chip memory. Sizes are easy numbers to search, but connectivity and mapping are not.
Each of K × Y′ × X′ outputs sums over C input channels and an R × S window: psum[k, y′, x′] += acts[c, y, x] × wgts[k, c, r, s]. Temporal mapping sets the order and the tiling of the loops. Spatial parallelism picks the loops that become Parallel-For across the PE array. Together they set how much data crosses each memory.
Evolution works on vectors of numbers, but loop order is an ordering. Index-based encoding numbers all orders (0 is CRXKYS, 1 is CXYRSK), but a step of one carries no physical meaning. Importance-based encoding fixes this in three steps:
The lecture's parallel importances are K = 4, C = 6, Y′ = 2, X′ = 2, R = 3, S = 1. They sort to C, K, R, X′, Y′, S, so with two parallel dimensions, C and K become Parallel-For. The loop-order vector K = 3, C = 5, Y′ = 2, X′ = 4, R = 5, S = 1 sorts to C, R, X′, K, Y′, S, outermost first.
Press a chip to change its importance from 1 to 6. The top row picks the parallel loops. The bottom row sets the loop order, outermost first.
The start is the lecture's example, with sizes 16, 3, 7, 16, 7, 3. Ties break in the order K, C, Y′, X′, R, S. The slide breaks the Y′, X′ tie the other way.
Raise K above 6 in the top row and K becomes the first parallel loop: a small edit, a small move.
An outer evolution loop proposes an accelerator. An inner OFA loop proposes networks that meet the accuracy target. A mapping search scores each pair by EDP, energy times delay, where lower is better.
| Budget and network | Sizing only | NAAS |
|---|---|---|
| EdgeTPU resources, VGG | 2.1 | 7.4 |
| EdgeTPU resources, MobileNet-V2 | 1.2 | 1.7 |
| NVDLA1024 resources, VGG | 2.3 | 6.0 |
| NVDLA1024 resources, MobileNet-V2 | 1.3 | 2.1 |
These are EDP reduction factors read from the lecture's chart. With the OFA network search added, NAAS beats a human design by 2.7 percent accuracy and 4.4 times EDP. Its dataflow parallelizes output height and output channels, on 18 × 10 PEs with a 496 B local buffer and a 107 KB global buffer.
pythondef decode(par_imp, ord_imp, n_par, tiles): # importances: dict dim -> number; tiles: dict dim -> size par = sorted(par_imp, key=lambda d: -par_imp[d])[:n_par] # first n_par dims run in parallel order = sorted(ord_imp, key=lambda d: -ord_imp[d]) # outermost first return [(d, tiles[d], d in par) for d in order] # (dimension, size, parallel?)
The failure: searching sizes alone. Put connectivity and mapping in the search too.
Chapter 10
See the same recipe, train a super network once and search a sub-network for a limit, applied in seven new places
The once-for-all recipe: train one super network whose parts can switch off, then search the family for the best member under a limit. The limit can be milliseconds, megabytes, frames per second or the noise of a quantum chip.
| Application | What trains once, and what the search picks | Result in the lecture |
|---|---|---|
| HAT (Wang et al., ACL 2020) | A SuperTransformer holds weight-sharing SubTransformers. An evolutionary search with hardware latency feedback picks one per device. | WMT'14 English to French on a Raspberry Pi, against the Evolved Transformer: 2.7× faster (20.9 s to 7.8 s), 3.7× smaller (175 MB to 48 MB), 3.2× fewer FLOPs, 10,148× less search cost, 0.1 higher BLEU. |
| SPVNAS (Tang et al., ECCV 2020) | LiDAR point clouds with sparse point-voxel convolution. Fine-grained channels and elastic depth train in stages (depth 3; then 2 and 3; then 1, 2 and 3). An evolutionary search with a latency predictor picks the winner. | 9.1 frames per second, against 3.4 for MinkowskiNet. |
| Anycost GAN (Lin et al., CVPR 2021) | One once-for-all image generator for editing on an iPad. | A small sub-network gives a fast preview, a large one the high-quality final, from the same weights. |
| LitePose (Wang et al., CVPR 2022) | A 2D human pose model found by hardware-aware NAS. | 4.9× lower latency on a Qualcomm Snapdragon 855. |
| QuantumNAS (Wang et al., HPCA 2022) | A "super circuit"; the search picks a noise-robust "sub-circuit" and prunes small-magnitude gates. TorchQuantum implements it. | Noise drops a circuit from 87% to 47%. On MNIST-4 on a real quantum computer: 85% against 47%. |
| Flextron (Cai et al., ICML 2024) | A trained LLM. Rank heads and channels by importance, group them into nested sub-networks, train a router that reads a latency target. | One set of weights runs at, for example, 50, 80 or 100% of the MLP and 10, 40 or 100% of attention, on a phone, a laptop and a cloud GPU. |
| OFA (Cai et al., ICLR 2020) | The image networks of Chapters 4 to 6. | On-device gaze estimation, car and person detection on a Raspberry Pi, and segmentation on mobile. |
HAT replays Chapter 3, now chosen by the search: an IoT device, a CPU and a GPU each get their own shape, deeper for the CPU and wider for the GPU.
Choose a result. The grey bar is the baseline and the colored bar is the model found by search.
All numbers are the lecture's: HAT against the Evolved Transformer on a Raspberry Pi, SPVNAS against MinkowskiNet in frames per second, and QuantumNAS on MNIST-4 on a real quantum computer.
Each result has its own unit, and the recipe stays the same. The failure: a limit you cannot measure, so the search picks a model that misses the real budget. Compare the signal with a few real runs, as in Chapter 3, and build a table or predictor for that limit first.
pythondef once_for_all_recipe(super_net, limit, signal, tries=1000): super_net.train() # one training run, sub-networks share weights best = None for _ in range(tries): sub = super_net.sample() # ms, frames, MB, gate noise: the limit decides if signal(sub) <= limit and (best is None or super_net.score(sub) > super_net.score(best)): best = sub return best
Chapter 11
Keep the whole lecture on one page, and take away a checklist for searching a network under a real limit
The lecture's summary slide lists five things: performance estimation strategy in NAS, hardware-aware NAS, zero-shot NAS, neural-hardware architecture search, and NAS applications. The thread through all five is one sentence. A search is only as good as its two signals, accuracy and cost, so make both cheap, and make the cost the real one for the device.
| Number | What it says | Ch |
|---|---|---|
| 22,400 GPU-hours | Train 12,800 architectures from scratch on CIFAR-10 | 1 |
| 48,000 GPU hours | NASNet on CIFAR-10, about 5 years on one GPU | 2 |
| O(N) to O(1) | Activation memory per layer with a binary gate | 2 |
| 174 ms against 51.7 ms | A deeper and a wider network at about 259 M FLOPs on a Titan xp | 3 |
| 5.1 ms at 75.1% | ProxylessNAS (GPU) on a GPU, against MnasNet at 6.1 ms and 74.0%, and NASNet-A at 38.3 ms and 74.0% | 4 |
| 78 ms against 124 ms | Phone model against GPU model, timed on a phone | 4 |
| 40K, 160K, 1,600K | GPU hours for one, four and many devices without once-for-all | 4 |
| more than 1019 | Sub-networks held by one once-for-all network | 4 |
| 25 × 25 and 9 × 9 | Kernel transformation matrices for 5 × 5 and 3 × 3 | 5 |
| 76 against 48 GOPS/s | OFA against MobileNet-v2 on a ZU3EG FPGA | 6 |
| 47× faster, 46× smaller cache | Jet-Nemotron-2B against Qwen3-1.7B-Base at 64K context | 7 |
| τ ≤ n × m | The GradSign score bound | 8 |
| 4.4× EDP, +2.7% | NAAS with OFA against a human design | 9 |
| 2.7× faster, 3.7× smaller | HAT against the Evolved Transformer on a Raspberry Pi | 10 |
| Term | Plain meaning | Ch |
|---|---|---|
| Accuracy estimation | How a search scores one candidate network | 1 |
| Weight inheritance | A child network starts from its parent's weights | 1 |
| Hypernetwork | A network that writes the weights of another | 1 |
| Proxy task | A cheaper stand-in for the real task | 2 |
| Binary gate | A 0 or 1 that keeps one path alive per layer | 2 |
| Latency lookup table | Measured time per operation, summed per network | 3 |
| Once-for-all network | One trained network that contains many sub-networks | 4 |
| Progressive shrinking | Train full, then allow smaller kernel, depth and width | 5 |
| Arithmetic intensity | Operations performed for each byte moved | 6 |
| KV cache | Stored keys and values of earlier tokens | 7 |
| Zero-shot NAS | Scoring a network with no training step | 8 |
| Importance-based encoding | Turn an ordering into numbers by sorting importances | 9 |
| EDP | Energy times delay, lower is better | 9 |
The main ideas of the lecture fit in a short NumPy sketch. Shapes are in the comments.
pythonimport numpy as np def net2wider(W1, b1, W2, j): # function-preserving widening (Ch 1) W1n = np.vstack([W1, W1[j:j+1]]); b1n = np.append(b1, b1[j]) W2n = np.hstack([W2, W2[:, j:j+1]]); W2n[:, j] /= 2; W2n[:, -1] /= 2 return W1n, b1n, W2n def binary_gate(x, ops, alpha): # one path alive: memory O(1) (Ch 2) p = np.exp(alpha - alpha.max()); p /= p.sum() k = np.random.choice(len(ops), p=p) return ops[k](x), k def table_latency(ops, LAT): # sum of profiled layer times (Ch 3) return sum(LAT[o] for o in ops) def count_subnets(k, w, depths, units): # size of the OFA family (Ch 4) return sum((k * w) ** d for d in depths) ** units def small_kernel(w7, M25): # w7 (C,7,7), M25 (25,25) (Ch 5) return (w7[:, 1:6, 1:6].reshape(-1, 25) @ M25.T).reshape(-1, 5, 5) def sort_channels(W, importance): # narrow nets keep W[:k] (Ch 5) order = np.argsort(-importance); return W[order], order def roofline(intensity, peak, bw): # GOPS/s reachable (Ch 6) return min(peak, bw * intensity) def kv_cache_bytes(full_layers, kv_heads, head_dim, tokens, b=2): # (Ch 7) return 2 * full_layers * kv_heads * head_dim * tokens * b def gradsign(per_sample_grads): # (n, m) gradients at init (Ch 8) return np.abs(np.sign(per_sample_grads).sum(0)).sum() def decode(par_imp, ord_imp, n_par, tiles): # importance-based encoding (Ch 9) par = sorted(par_imp, key=lambda d: -par_imp[d])[:n_par] return [(d, tiles[d], d in par) for d in sorted(ord_imp, key=lambda d: -ord_imp[d])]
Run these on the worked examples. count_subnets(3, 3, [2, 3, 4], 5) gives 2.18 × 1019. roofline(20, 100, 2) gives 40. kv_cache_bytes(28, 2, 128, 65536) gives 1,879,048,192 bytes, which is 1,792 MiB.
Lecture 7 gave the search space and strategy. This lecture added cheap accuracy, real latency, and a shared network for many devices. Next, Lecture 9, Knowledge Distillation, shows another way to make a small network good: teach it with a large one.
Now press Teach and explain, from memory, why a once-for-all network can hold many sub-networks without each one being poor, and why latency needs its own table. Then go back to the hero at the top and drag the number of devices again.
This lesson follows Lecture 8 of MIT 6.5940: TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Read the lecture on the course page, which links the slides. The papers behind it include Zoph and Le (ICLR 2017), Net2Net (ICLR 2016), SMASH (ICLR 2018), ProxylessNAS (ICLR 2019), MnasNet (CVPR 2019), HAT (ACL 2020), Once-for-All (ICLR 2020) and SPVNAS (ECCV 2020). They also include Zen-NAS (ICCV 2021), NAAS (DAC 2021), Anycost GANs (CVPR 2021), GradSign (ICLR 2022), LitePose (CVPR 2022), QuantumNAS (HPCA 2022), Flextron (ICML 2024) and Jet-Nemotron (NeurIPS 2025). Every idea above is re-taught in our own words and devices, and we label toy numbers as illustrative where they appear.