Branch Log · Open in interactive viewer →

8 Neural Architecture Search (Part II)

Lecture 08 - Neural Architecture Search (Part II) | MIT 6.S965

Exploring the Implementation of Network Architecture Search(NAS) for TinyML Application


8.1 Performance Estimation in NAS

model architecture가 갖는 성능을 평가하는 방법을 생각해 보자. 우선 RNN controller를 쓰는 NAS는 다음과 같은 구조였다.

from scratch

하지만 이러한 방법은 training cost가 너무 많이 든다.


8.1.1 Weight Inheritance

Net2Net: Accelerating Learning via Knowledge Transfer 논문(2015)

Efficient Architecture Search by Network Transformation 논문(2017)

모든 네트워크를 from scratch부터 학습시키기보다, weight를 상속하는 방법을 생각해 볼 수 있다. 작은 network를 weight inheritance를 사용하여 효율적으로 더 큰 네트워크를 구성한 Net2Net 논문이 대표적이다.

논문에서는 작은 모델을 teacher, teacher을 바탕으로 새롭게 만든 더 큰 모델을 student라고 부른다.

layer $i$ 의 hidden units $h[1], h[2]$ 에서 weights $c, d$ 를 복사하여 $h[3]$ unit을 추가한 예시다.

Net2Wider

identity mapping initization을 사용하여 capacity가 더 큰 네트워크를 만든다.

Net2Deeper


8.1.2 HyperNetwork: Weight Generator

SMASH: One-Shot Model Architecture Search through HyperNetworks 논문(2017)

Graph HyperNetworks for Neural Architecture Search 논문(2018)

SMASH 논문에서는 sampled model architecture가 가질 weight를 만드는 네트워크로 hypernetwork를 제시했다.(weight generator)

그렇다면 어떻게 weight를 만들어 낼 수 있을까? 우선 search space $\mathbb{R_c}$ 가 있다고 하자.

training Error $E_t = f_c(W, x_i) = f_c(H(c), x_i)$ 를 구한 뒤 $H$ 를 update한다.

validation set $E_v = f_c(H(c), x_v)$ 를 구한다.


8.1.3 Weight Sharing

Efficient Neural Architecture Search via Parameter Sharing 논문(2018)

널리 쓰이는 다른 대표적인 방법으로는 weight sharing이 있다.

weight sharing


8.2 Performance Estimation Heuristics

하지만 몇 가지 방법은 network architecture training 없이, 오로지 구조를 관찰하여 performance estimation을 수행한다.


8.2.1 Zen-NAS

Zen-NAS: A Zero-Shot NAS for High-Performance Deep Image Recognition 논문(2021)

Gaussian complexity

Zen-NAS 논문에서는 Zen-Score라는 cost proxy를 도입하여 performance estimation을 수행한다. 오로지 random Gaussian input을 사용해 무작위로 초기화된 newtork에서, 몇 번의 forward inference를 수행하면 Zen-Score를 구할 수 있다.

다시 말해 다른 입력들을 줬을 때 표준편차가 더 큰 모델을 찾으면 된다.

이러한 방식을 논문에서는 Zero-Shot NAS라고 부르며, Zen-NAS에서는 Batch Normalization으로 인해 발생할 수 있는 문제까지 고려한다. 다음은 Zen-Score를 구하는 과정을 나타낸 그림이다.

평균 $\mu$ , 분산 ${\sigma}^2$ 를 갖는 Gaussian distribution을 $\mathcal{N}(\mu, \sigma)$ 로 표현한다.

zen score computational graph

순차적으로 Zen-Score를 계산하는 방법을 살펴보자.

  1. network $F(\cdot)$ 의 모든 residual links를 제거한다.

  2. 모든 neurons(activations)이 $\mathcal{N}(0,1)$ 분포를 갖도록 weight를 초기화한다.

  3. $\mathcal{N}(0,1)$ 에서 input $x$ 과 $\epsilon$ 을 sampling한다.

  4. feature map perturbation $\triangle$ 을 계산한다.

$$ \triangle \overset{\triangle}{=} \mathbb{E_{x, \epsilon} } || f(x) - f(x+\alpha \epsilon)||_{F} $$

$L$ 개 레이어(function)을 의미한다.( $m_0$ : input dimension, $m_L$ : output dimension)

  1. BN layer의 compensation term을 계산한다.

    output channels $m$ 개를 갖는 $i$ 번째 BN layer에서, 각 채널이 갖는 분산의 평균을 제곱근한 값을 계산한다.

$$ \bar{ {\sigma}{i} } = \sqrt{ {\sum} $$}{\sigma}^2_{i,j}/m

  1. Zen score를 계산한다.

$$ \mathrm{Zen}(F) \overset{\triangle}{=} \log(\triangle) + \sum_{i}\log(\bar{ {\sigma}_{i} }) $$


8.2.2 GradSign

GradSign: Model Performance Inference with Theoretical Insights 논문(2021)

GradSign 논문에서는 다음과 같은 heuristic을 사용한다.

GradSign


8.3 Hardware-Aware NAS

다양한 hardware architecture에 알맞는 network architecture를 매번 검색한다면 엄청난 GPU cost가 발생할 것이다. 이러한 비용을 아끼기 위해 전통적으로는 proxy tasks를 utilize하는 방향으로 연구가 진행되었다.

다음은 몇 가지 예시이다.

단점: 실제로는 capacity, complexity가 달라서 잘 동작하지 않는 경우가 많다.

단점: 일부 구조는 적은 epoch만으로도 빠르게 수렴한다.

단점: #Flops가 적은 모델이라도 더 느릴 수 있다.


8.3.1 ProxylessNAS

ProxylessNAS: Direct Neural Architecture Search on Target Task and Hardware 논문(2018)

ProxylessNAS 논문은 proxy를 사용하지 않고 hardware에 알맞는 network architecture를 찾는다.

ProxylessNAS

만약 좋지 않은 path라면 해당 path를 pruning하면서 진행된다.

따라서 memory footprint가 작다.(O(N) $\rightarrow$ O(1))

그렇다면 latency는 어떻게 profile할까?


8.3.1.1 MACs is not a good metric for latency

우선 MACs와 Flops는 latency를 위한 proxy로 적합하지 않다.

MACs and latency

또한 hardware에 따라서도 scaling 방법 차이에 따라 latency 변화가 다르다.

hardware difference: MACs and latency


8.3.1.2 layer-wise latency profiling

따라서 ProxylessNAS에서는 latency predictor(지연시간 예측기)를 도입하여 latency를 예측한다.

latency predict

이때 latency predictor도 Lookup Table을 구성하는 단위에 따라서 layer-wise, network-wise로 나뉘는데, ProxylessNAS, Once-For-All에서는 layer-wise latency profiling을 사용한다.

layer-wise latency profiling

LUT 예시를 한 번 살펴보자.

LUT

다음은 LUT를 사용한 latency predictor가 얼마나 latency를 예측하는지를 시각화한 그래프다.

ProxylessNAS latency predictor performance


8.3.2 HAT: network-wise latency profiling

HAT: Hardware-Aware Transformers for Efficient Natural Language Processing 논문

반면 HAT 논문에서는 network 단위로 latency profiling을 수행한다.

network-wise

마찬가지로 시각화한 그래프를 보면 유효한 방법인 것을 알 수 있다.

network-wise latency profiling


8.3.3 Once-for-All NAS

Once-for-All: Train One Network and Specialize it for Efficient Deployment 논문(2019)

ONCE-FOR-ALL github

Once-for-All 논문에서는 supernet을 단 한 번 학습하면, 제약조건에 따라 다양한 subnet을 추출할 수 있는 방법을 제시한다.

Once-for-All

하지만 이러한 supernet training은 굉장히 큰 GPU cost를 필요로 한다. OFA에서는 Progressive Shrinking(PS)라는 접근법으로, 더 효율적으로 supernet training을 진행한다.


8.3.3.1 Progressive Shrinking

Progressive Shrinking은 다음과 같은 단계로 진행된다.

progressive shrinking

다양한 해상도 범위에서 제일 큰 구조를 학습한다.

제일 큰 kernel size(7x7)가 아닌 5x5, 3x3 kernel size를 사용하는 구조를 학습한다.

progressive shrinking: kernel size

block에서 제일 많은 #layers(4개)가 아닌 3개, 2개 레이어를 갖는 구조를 학습한다.

progressive shrinking: layers

channel 중요도를 계산한 뒤, 중요하지 않은 channel을 pruning한다.

progressive shrinking: channels