Reference
장점:
단점:
Sparse-gate MoE
MoE Transformer
Switch Transformer
GLaM (Generalist Language Model)
Mixtral
Sparse MoE layers (Experts)
Gate Network or Route
장점:
단점:
- Adaptive Mixture of Local Experts (1991)
- Learning Factored Representations in a Deep Mixture of Experts (2013)
- Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer (2017)
- GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding (Jun 2020)
- GLaM: Efficient Scaling of Language Models with Mixture-of-Experts (2021)
- Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity (2021)
- ST-MoE: Designing Stable and Transferable Sparse Expert Models (Feb 2022)
- FasterMoE: modeling and optimizing training of large-scale dynamic pre-trained models(April 2022)
- MegaBlocks: Efficient Sparse Training with Mixture-of-Experts (Nov 2022)
- Mixture-of-Experts Meets Instruction Tuning:A Winning Combination for Large Language Models (May 2023)
- Mixtral-8x7B-v0.1, Mixtral-8x7B-Instruct-v0.1.
Sparsity
전통 MoE gating 함수 G, Experts E
Noisy Top-K Gating
✅ Load balancing issue!
- 이때, noise를 포함하는 건 load balancing issue 완화 때문임.
- 입력들이 소수의 experts에만 쏠리면 학습이 비효율적임.
- 이를 완화하기 위해서 모든 expert들이 균형있게 선택되도록 부가적인 loss (auxiliary loss) 추가함. (tunable noise)
- 그래서 선택과정을 더 확률적으로 만들어서 탐색하게 함
배경
MoE 활용해서 Transformer를 600B까지 scale up한 모델 (MoE transformer라고 부름)
모델
(1) Transformer Encoder의 FFN 레이어를 MoE로 대체 (2번째 그림)
(2) 한 token 2개의 experts 작동 (top-2)
(3) experts 디바이스에 분산 => 각 디바이스 expert에 입력 보내기 => 해당 expert의 연산 결과 다시 가져오기 (3번째 그림)
✅ 효율적인 분산 컴퓨팅
- 대규모 모델 훈련할 때 분산 컴퓨팅 사용하는 게 일반적임. 시간+자원 줄이기 위해서 여러 컴퓨팅 장치에 작업 분배해서 동시에 처리
- 예 1. Data paralleism: 모델을 여러 곳에 복제해서, 데이터셋을 나눠서 훈련
- 예 2. Model Parallelism: 모델 자체를 여러부분으로 나눠서 다른 장치에서 훈련. 이때 필요한 경우 서로 통신하여 중간 결과 교환.
- 예 3. MoE: 다른 레이어는 다 복제하고, MoE 레이어는 디바이스끼리 공유(분산)! 전문가들이 여러 장치에 걸쳐 분산되는 거니까, 많은 전문가들이 동시에 활성화되어 계산 수행 가능! 전문가가 다른 쪽에 있으면 거기로 input보내서 결과 가져오기.
Load balancing issue 해결 방법
auxilary loss
Randon routing:
top-2 expert: 이때 점수 가장 높은 expert 첫번째로 선택하고, 두 번째 expert는 각 점수(weights)에 비례하는 확률로 추출
top1은 무조건 softmax에서 나온 값 중에서 제일 높은 애로 정하는데, 두 번째 놈은 random으로 설정함. 그런데 그 random으로 뽑을 때 각각의 expert 뽑힐 확률은 weights에 비례하게 계산
import numpy as np
# 4명 전문가들의 게이트 확률
gate_outputs = np.array([0.6, 0.2, 0.15, 0.05])
# Top-1 전문가 선택
top1_index = np.argmax(gate_outputs)
top1_expert = gate_outputs[top1_index]
# 나머지 전문가들 중 두 번째 전문가 확률적으로 선택
remaining_indices = np.delete(np.arange(len(gate_outputs)), top1_index)
remaining_gates = gate_outputs[remaining_indices]
# 확률 분포를 계산
total_remaining_gates = np.sum(remaining_gates)
probabilities = remaining_gates / total_remaining_gates
# 두 번째 전문가 확률적으로 선택
second_expert_index = np.random.choice(remaining_indices, p=probabilities)
# 결과 출력
print(f"Top-1 Expert Index: {top1_index}, Gate Output: {top1_expert}")
print(f"Second Expert Index: {second_expert_index}, Gate Output: {gate_outputs[second_expert_index]}")
Expert capacity (전문가 역량): 각 expert 마다 몇 개의 token까지 수용 가능한지 설정
저자가 밝힌 한계점
배경:
MoE 사용할 때 발생하는 다음 3가지 줄이기 위한 연구
모델
(1) Simplifying Sparse Routing
(2) Efficient Sparse Routing
(a) Distributed Switch Implementation: Expert Capacity 설정 강화!
(b) A Differentiable Load Balancing Loss: Auxiliary loss
훈련 방식의 효율 높이기
실험 결과:
Discussion (자문자답)
https://research.google/blog/more-efficient-in-context-learning-with-glam/
배경
Dataset
모델
Model Partitioning (for scaling & training cost)
각 expert들은 여러 디바이스로 놔눠져 있음
이때, GSPMD 컴파일러 백앤드 사용하여 전문가 scaling할 때 생기는 문제 해결
GSPMD (General and Scalable Parallelization for Neural Networks)
- 2D topology: 컴퓨터 네트워크에서 장치들이 2차원 형태로 연결. (여러 대 컴퓨터가 행과 열로 배열)
- 2D sharding: 큰 데이터를 2차원 형태로 나눔 (큰 직사각형 종이를 작은 정사각형 조각들로)
실험 결과
거대 파라미터 대비 적은 에너지 소모
GPT3보다 zero, one, few-shot에서 29개 NLP task에서 더 좋은 성능
capacity factor 훈련 중에 컴퓨팅리소스에 따라 변경 가능
- GLaM(8B/64E): Transformer 레이어-8B parameter dense 모델/ Non-transformer 레이어- 64 expert MoE 레이어
- GLaM(137B): 같은 데이터셋으로 학습된 dense 137B 파라미터 모델
배경:
LLama2 백본으로 하는 mistral에 MoE 결합한 Sparse Mixture of Experts (SMoE) language model.
차별점:
Mistral7B랑 동일 아키텍처, but 각 레이어가 8개의 Experts로 구성
2개 expert (top-2 routing)
결과
Mixtral 8X7B
ST-MoE
Scaling Vision with Sparse Mixture of Experts (NeurIPS, 2021)
: MoE를 ViT에 적용하여 절반의 계산 비용으로 동일한 성능을 내는 V-MoE 제안
https://arxiv.org/abs/2106.05974
https://ostin.tistory.com/346
AdaMV-MoE: Adaptive Multi-Task Vision Mixture-of-Experts (ICCV, 2023)
:a fixed network capacity는 overfitting 문제 있을 수 있음
=> 패치별로 활성화된 Experts들
=> 오쫌 Vision GNN 느낌나는 결과인걸~?
기존 모델들에 MoE 결합하는 걸로 새로운 연구 제시하는 것들이 많군
MoE에 대해서 몰랐는데 꼼꼼히 알려주셔서 좋았습니다
!!