NeurIPS 2021
Sparsely-gated MoEs networks는 NLP에서 excellent scalability를 입증해왔다.
하지만 Computer Vision에서, 모든 performant networks는 "dense"하다.
즉, every input이 every parameter에 의해 processed된다.
우리는 largest dense networks에 대한 scalable and competitve한
a sparse version of the Vision Transformer인, a Vision MoE (V-MoE)를 소개한다.
image recognition에 적용했을 때, V-MoE는 SOTA network와 performance가 동등하면서도 inference 시 computation을 절반까지 줄일 수 있다.
추가로, 우리는 routing algorithm을 확장하여 entire batch에서 each input의 subsets을 prioritize(우선 처리)할 수 있는 방식을 제안하며,
이를 통해 adaptive per-image compute를 할 수 있다.
이를 통해 V-MoE는 test 시 performance와 computation 간의 trade-off를 smoothly하게 만들 수 있다.
마지막으로, 우리는 vision models을 확장하기 위한 V-MoE의 가능성을 입증하며, 15B parameter model을 train하여 ImageNet에서 90.35%의 성능을 달성했다.
(network capacity 증가로, high computational cost가 요구되고 있음...)
(NLP에서 conditional computation은 위 문제를 해결하려는 접근법임)
(우리는 ViT를 사용하여 conditional computation을 vision에 대해 확장하려고 한다)
(기존 routing network의 non-differentiability를 개선한 학습 방법을 제안했다)
(inference 동안 sparsity level을 조절함으로써 performance vs. inference-cost trade-off를 조절할 수 있다)
our main contributions을 다음과 같이 요약:
Conditional computation은 서로 다른 inputs에 대해 network의 서로 다른 subsets을 활성화하는 것을 목표로 한다.
mixture-of-experts model은 specific instantiation(특정 구현) 방식으로, 서로 다른 model "experts"들이 inpput space의 서로 다른 regions을 담당한다.
우리는 [54]의 setting을 따르며, 개의 experts를 가진 a mixture of experts layer를 다음과 같이 정의한다:
where is the input to the layer,
is the function computed by expert ,
and is the "routing" function which prescribes the input-conditioned weight for the experts.
and 는 모두 neural network로 parameterized된다.
이 정의에 따르면, 이는 여전히 dense network이다.
그러나 가 sparse하다면, 즉 의 non-zero weights만 assign되도록 제한된다면, unused experts는 computed될 필요가 없다.
이는 inference and training computation에 비해 model의 #params을 super-linear scaling(초선형적인 확장)을 할 수 있도록 해준다.
우리는 ViT 맥락에서 sparsity를 vision에 적용하는 것을 탐구했다.
ViT는 transfer learning setting에서 잘 확장되는 것으로 입증되었으며, CNN보다 적은 pre-training compute로 better accuracies를 달성한다.
ViT는 images를 a sequene of patches로 처리한다.
input image는 먼저 equal-sized patches로 구성된 grid로 divided된다.
그런 다음 이를 Transformer's hidden size로 linearly projected된다.
이후 positional embedding을 추가한 후, patch embeddings(tokens)은 주로 self-attention and MLP layers가 교차하는 Transformer에 의해 처리된다.
MLP는 two layers and a GeLU non-linearity를 사용하여 정의된다:
Vision MoE에서는 이러한 MLP layer 중 subset을 MoE layers로 교체하며, 각 expert는 MLP이다. (Figure 1)
experts는 와 same architecture를 가지지만 different weights 를 갖는다.
이는 M4 machine translation model의 design pattern과 유사하다.
V-MoE의 각 MoE layer에서 routing function 을 사용했다,
where 는 vector의 모든 elements 중 largest values를 제외한 나머지를 모두 0으로 만드는 연산,
and 은 ~ entry-wise마다 독립적으로 sampled된다. (MoE 논문에서 추가한 Gaussian noise인듯)
실제로, 우리는 or 를 사용했다.
ViT의 맥락에서, 는 network의 특정 layer에서 image token의 representation을 나타낸다.
따라서, V-MoE는 entire images를 routing하는 것이 아니라 patch representations을 routing한다.
이전 formulations [54]과의 차이점은 experts weights에 대해 softmax 이후에 를 적용한다는 것이다.
이는 softmax 이전에 를 적용했을 때의 문제(rounting에 대한 gradients가 거의 모든 곳에서 0이 되는 현상)을 방지하며, 일 때도 더 나은 성능을 보인다(Appendix A).
(아래는 이전 논문 [54]에서 했던 방법을 그대로 사용)
(그냥 training하면 다음과 같은 문제들 발생...)
(문제를 해결하기 위한 load balancing 방법 제시)
이러한 imbalance를 해결하고 implementation을 단순화하기 위해,
우리는 각 expert의 buffer capacity(각 expert가 처리할 수 있는 #tokens)를 고정시키고,
load balancing을 encourage하는 auxiliary losses를 추가하여 model을 train했다.
이는 [54, 39, 22]에서 제안한 two of the auxiliary losses의 slight variants(약간 변형된 버전)를 사용한다.(Appendix A)
expert의 buffer capacity 는
batch에 포함된 #images ,
#tokens per image ,
#(selected experts per token) ,
total #experts ,
and the capacity ratio 로 정의된다:
만약 router가 어떤 expert에 대해 이상의 token을 assign하면, 까지만 processed된다.
나머지 tokens은 완전히 'lost'(손실)되지는 않으며, residual connections에 의해 그들의 information이 유지된다.
또한 인 경우, 여러 experts가 각각의 token을 처리하려 시도한다.
따라서 token이 완전히 discarded되지는 않는다.
반대로, 특정 expert에게 할당된 token이 보다 적을 경우, 나머지 buffer는 zero-padded된다.
(skip)
Section 2의 notation을 사용하면, routing function 는 a batch of input 에 대해 row-wise로 적용된다.
batch에는 개의 image가 포함되며, 각 image는 개의 token으로 구성된다.
의 각 row는 한 image의 특정 token의 -dimensional representation을 나타낸다.
따라서 은 -th token과 -th expert에 대한 routing weight를 나타낸다.
모든 routing algorithm에서, 일 경우, 모든 TOP- assignment는 TOP- assignment보다 priority를 갖는다.
router는 먼저 모든 expert를 choice를 배정한 후, choice를 배정한다.
[54]에서 사용된 the default-or vanilla-routing과 같이, TOP- position을 고려하면, routing은 다음과 같이 experts에게 tokens을 할당한다.
router는 의 rows를 순차적으로 검사하여, expert's buffer가 not full할 때 해당 token을 TOP- expert에게 assign한다.
결과적으로, token은 그에 해당하는 row의 rank에 따라 priority가 주어진다.
batch 내 images는 randomly 정렬되지만, 각 image 내의 token은 pre-defined fixed order(미리 정의된 고정된 순서)를 따른다.
Prioritized routing은 model이 원래 어떻게 학습되었는지에 대해 독립적이다.
Figure 6는 V-MoEe-H/14 model에서 BPR과 vanilla routing을 사용했을 때, inference 시 computing을 줄이는 효과를 보여준다.
두 methods의 성능 차이는 특히 에서 현저하게 나타난다.
이 구간에서는 model이 실제로 token을 완전히 버리기 시작한다().
또한, BPR은 매우 낮은 capacity에서도 model이 dense model과 경쟁력을 유지할 수 있도록 한다.
Figure 5에서 V-MoE-L/16과 V-MoE-H/14를 대상으로 보여주듯이,
Batch Prioritized Routing과 low 값은 V-MoE가 inference 시 performance and FLOPs를 smoothly trade-off할 수 있게 하며, 이는 매우 독특한 model 특징이다.
더 구체적으로, Table 10은 V-MoE model이 dense ViT-H 성능을 능가하면서도 FLOPs를 절반 이하로 줄이고, runtime을 60% 미만으로 줄일 수 있음을 보여준다.
반대로, FLOPs 비용을 동일하게 유지하면서 ImageNet/5-shot에서 one-ponit accuracy gain을,
JFT에서는 3point에 가까운 Precision@1을 유지할 수있었다. (Table 11)
dense model은 일반적으로 동일한 FLOPs에 대해 V-MoE 구현에서 data transfer가 포함되므로 더 적은 runtime을 요구한다.