C.W.K.
Stream
Lesson 11 of 12 · published

Mixture of Experts — sparse 컴퓨트, dense 지식

~14 min · moe, mixtral, deepseek

Level 0Token
0 XP0/94 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Mixture of Experts(MoE)는 FFN을 expert FFN 집합 + 학습된 router로 대체. 각 토큰에 대해 router가 top-K expert(보통 K=1 또는 2)를 골라, 그 expert들만 계산. 전체 파라미터는 큼, 토큰당 active 파라미터는 훨씬 작음.

고품질이면서 서빙 싸야 하는 모델의 아키텍처적 선택. 100B 파라미터 모델의 지식을 20B 파라미터 모델의 토큰당 컴퓨트로 얻어.

모델총 파라미터active 파라미터expertrouting
Mixtral 8×7B47B13B8top-2
Mixtral 8×22B141B39B8top-2
Llama 4 Scout109B17B16 (routed)top-1
Llama 4 Maverick400B17B128 + 1 sharedtop-1
DeepSeek-V3671B37B128 + 1 sharedtop-K
Mistral Small 4119B6B128top-4

왜 MoE가 통하나

토큰마다 필요한 "사고" 종류가 달라. 코드 토큰은 어떤 expert가 좋고, 한국어 토큰은 다른 expert, 수치 추론 단계는 또 다른 expert. router가 expert를 특화하게 하면 모델이 파라미터를 효율적으로 써 — 각 토큰에 맞는 expert만 발화. 비용: 학습이 더 어려움(load balancing, routing 붕괴), 서빙에 커스텀 추론 프레임워크 필요, 배치당 tail latency 변동.

Code

Top-2 MoE block (sketch)·python
class MoELayer(nn.Module):
    def __init__(self, d_model, d_ff, n_experts, top_k=2):
        super().__init__()
        self.experts = nn.ModuleList(
            [SwiGLU(d_model, d_ff) for _ in range(n_experts)]
        )
        self.router = nn.Linear(d_model, n_experts, bias=False)
        self.top_k = top_k
    def forward(self, x):
        # x: (B, L, d_model)
        logits = self.router(x)                            # (B, L, n_experts)
        topk_vals, topk_idx = logits.topk(self.top_k, dim=-1)
        gates = F.softmax(topk_vals, dim=-1)              # normalize over chosen
        out = torch.zeros_like(x)
        for k in range(self.top_k):
            for e in range(len(self.experts)):
                mask = (topk_idx[..., k] == e)
                if mask.any():
                    out[mask] += gates[..., k][mask].unsqueeze(-1) * self.experts[e](x[mask])
        return out
# Real implementations dispatch tokens to experts in batched form
# (custom kernel territory) for performance.

External links

Exercise

스케일링 세 접근 개념 비교 — (a) dense Llama 3 70B, (b) Mixtral 8x22B(141B 총 / 39B active), (c) Llama 4 Maverick(400B / 17B active). 각각 FP16 파라미터 메모리, 32K 컨텍스트 KV cache, 대략의 토큰당 throughput 추정. 고품질에서 어느 게 서빙 가장 싸?

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.