DL0187 Hardware-Aware Neural Architecture Search

What is Neural Architecture Search (NAS), and how does Hardware-Aware NAS optimize architectures for edge and mobile deployment constraints such as latency, memory, and energy?

Answer

NAS automates architecture design by specifying three things: a search space of candidate operations and connectivity, a search strategy that proposes architectures, and an evaluation method that scores them. Classical NAS maximizes validation accuracy alone, which reliably produces models that are unusable on a phone because accuracy is monotone in capacity. Hardware-aware NAS changes the objective rather than the search algorithm: the target device becomes part of the reward, either as a hard constraint on measured latency or as a multi-objective term that trades accuracy against cost. The critical detail is that FLOPs and parameter counts are poor latency proxies, because depthwise convolutions, squeeze-excite blocks, and grouped convolutions are memory-bandwidth bound rather than compute bound, so the cost signal must come from on-device measurement or a layer-wise latency lookup table (LUT) calibrated on the actual CPU, GPU, DSP, or NPU. Memory enters as a separate ceiling on peak activation footprint (the binding constraint on microcontrollers with a few hundred KB of SRAM), and energy enters through measured joules per inference, which tracks DRAM traffic more than arithmetic. Because a full search costs thousands of GPU-hours per device, production systems amortize it with a weight-sharing supernet that is trained once and then queried per deployment target.

(1) Three Components: search space, search strategy (reinforcement learning, evolution, or gradient-based), and evaluation. The space dominates the outcome, since a badly chosen space caps the achievable Pareto front no matter how good the optimizer is.
(2) FLOPs Are Not Latency: two blocks within 5% of each other in FLOPs can differ by 1.8x in measured milliseconds, so proxy metrics silently select the wrong architecture.
(3) Cost In The Objective: either a hard constraint \mathrm{Lat}(\alpha) \leq T, a soft reward such as MnasNet’s \mathrm{Acc} \cdot (\mathrm{Lat}/T)^{w}, or a differentiable expected latency term added to the loss.
(4) Latency Lookup Tables: profile each candidate operator once per device and sum per-layer times, which makes the cost model cheap and differentiable but blind to operator fusion and thermal throttling.
(5) Memory And Energy Are Separate Constraints: peak activation RAM bounds what fits in SRAM, and energy per inference is dominated by off-chip memory traffic, so neither is implied by a latency target.
(6) Amortization Is The Production Trick: a once-for-all supernet trained with progressive shrinking yields deployable subnets for a new phone in minutes instead of a fresh search per device.

Flow diagram of a hardware-aware NAS loop: a search space of MBConv blocks with kernel and expansion choices feeds a sampler or controller, which emits a subnet that is scored for accuracy by a weight-sharing supernet and for cost by a hardware cost model built from a layer-wise latency lookup table plus on-device runs, both feeding a multi-objective reward that is fed back to the sampler, with the selected subnet fine-tuned, quantized, and deployed

Figure 1: The loop is sample subnet → score accuracy on a weight-sharing supernet → query a hardware cost model → combine into one multi-objective reward → update the sampler. Only the cost model is device-specific, which is why the same search pipeline produces a different winner for a mid-range CPU than for an NPU.

The cost model is where most engineering effort goes. A layer-wise LUT stores the measured runtime of every candidate operator at every feature-map shape on the target, so predicting a candidate’s latency is a table sum instead of a deployment. This is fast enough to put inside a training loop, and because the sum is linear in the per-operator times it can be made differentiable with respect to architecture probabilities. The failure mode is LUT drift: a compiler that fuses convolution with batch normalization and activation, a scheduler that changes clock frequency under load, or a runtime that picks a different kernel for a specific channel count will all break additivity, and errors compound across dozens of small layers. Practical pipelines therefore validate the LUT against end-to-end on-device measurements for a sample of candidates and refit when the mean absolute percentage error drifts past a few percent.

Scatter plot of measured mobile CPU latency in milliseconds against multiply-accumulate cost in MFLOPs for nine candidate blocks, with compute-bound blocks and memory-bound blocks distinguished, and two double-headed arrows marking pairs of blocks that have nearly equal FLOPs but 1.8 to 1.9 times different measured latency

Figure 2: Measured latency versus FLOPs for candidate blocks on one mobile CPU. The ordering is not preserved: a grouped convolution and a squeeze-excite MBConv cost roughly 1.9x and 1.8x the latency of blocks with nearly identical FLOPs, because both are memory-bandwidth and kernel-launch bound. Searching against FLOPs would pick the slow block.

Mathematical Formulation:
\max_{\alpha \in \mathcal{A}} \mathrm{Acc}(\alpha, w^{*}(\alpha))
\text{s.t.}\ \mathrm{Lat}(\alpha, H) \leq T
R(\alpha) = \mathrm{Acc}(\alpha) \cdot (\mathrm{Lat}(\alpha)/T)^{w}
\mathcal{L}(\theta, \alpha) = \mathrm{CE}(\theta, \alpha) + \lambda \log \mathrm{Lat}(\alpha)
\mathrm{Lat}(\alpha) = \sum_{l=1}^{L} \sum_{o \in \mathcal{O}} p_{l,o} \, t_{l,o}
\max_{l} (a_{l} + a_{l+1}) \leq M_{\mathrm{SRAM}}

Where:

  • \alpha is a candidate architecture drawn from the search space \mathcal{A}, and w^{*}(\alpha) are its weights, either trained from scratch or inherited from a supernet.
  • \mathrm{Lat}(\alpha, H) is the latency on target hardware H and T the deployment budget, so the same \alpha has a different cost on a CPU, a DSP, and an NPU.
  • R(\alpha) is the soft multi-objective reward, with exponent w negative (MnasNet uses w = -0.07) so that exceeding the budget is penalized smoothly rather than rejected outright.
  • \mathcal{L} is the differentiable alternative: cross-entropy on weights \theta plus a log-latency regularizer weighted by \lambda, which controls where on the Pareto front the search lands.
  • p_{l,o} is the softmax probability of choosing operator o \in \mathcal{O} at layer l, and t_{l,o} the measured LUT entry for that operator at that layer’s shape, so expected latency is linear in p and its gradient is exactly t_{l,o}.
  • a_{l} is the activation tensor size at layer l; since an inplace-scheduled runtime holds an input and an output buffer simultaneously, the peak pair sum must fit the on-chip budget M_{\mathrm{SRAM}}.
Accuracy versus latency scatter and Pareto frontiers for two devices: a mobile CPU frontier and an NPU frontier over the same set of architectures, with a cloud of dominated candidates below, a vertical dashed line at a 20 millisecond budget, and two starred architectures showing that the best subnet under the budget differs between the two devices

Figure 3: The same architecture set has a different Pareto front per device. Architecture Y misses a 20 ms budget on the CPU at 26 ms but clears it on the NPU at 16 ms, so the optimal pick flips. This is why hardware-aware NAS is rerun (or a supernet requeried) for each target rather than solved once.

Budget Decomposition For A 30 ms Camera Frame:
t_{pre} + t_{infer} + t_{post} \leq 30\ \text{ms}
3\ \text{ms} + 22\ \text{ms} + 5\ \text{ms} = 30\ \text{ms}

The search target T is never the product-level frame budget. Resize, color conversion, and normalization consume a few milliseconds before the network runs, and non-maximum suppression or decoding consumes more afterwards, so the network budget that goes into the reward is what remains. Getting this wrong by 5 ms produces an architecture that is Pareto-optimal against the wrong constraint, which is a more common production failure than a weak search algorithm.

PropertyRL / evolutionary controllerDifferentiable supernetOnce-for-all supernet
Typical search costThousands of accelerator hours per device and per budgetRoughly 200 to 400 GPU hours, one run per device and budgetAbout 1,200 GPU hours once, then minutes for each new target
How hardware cost entersMeasured on-device latency of the sampled model inside the rewardExpected latency from a layer-wise LUT, differentiable in the architecture weightsAccuracy and latency predictors queried by cheap evolutionary search
Retraining after searchFull training of the winning architectureFull retraining of the derived subnetNone required; subnets are directly deployable, fine-tuning optional
Search-time memoryLow, one candidate resident at a timeHigh, all candidate operators resident unless paths are binarizedHigh while training the supernet, negligible during per-device search
Main weaknessCost scales linearly with the number of devices and budgetsLUT drift and weight co-adaptation bias the candidate rankingComplex progressive-shrinking and distillation recipe, residual supernet gap

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *