Split View: MoE 라우팅 — 전문가는 어떻게 뽑히는가
MoE 라우팅 — 전문가는 어떻게 뽑히는가
- 들어가며
- 가장 단순한 형태: Mixtral
- 활성 파라미터와 전체 파라미터
- 공유 전문가와 조밀한 첫 층
- 로드 밸런싱: 두 갈래
- 희소도를 얼마나 올릴 것인가
- 라우팅 범위 제한
- 마치며
- 참고 자료
- 직접 해보기
- 시리즈
들어가며
앞 글에서 config.json으로 조밀한 모델의 파라미터를 세어 봤습니다. 그런데 요즘 큰 모델의 config를 열면 num_experts나 n_routed_experts 같은 낯선 필드가 나옵니다. 전문가 혼합, 즉 MoE 계층입니다.
아이디어는 단순합니다. 층마다 하나뿐이던 FFN을 여러 개의 작은 FFN으로 쪼개고, 토큰마다 그중 몇 개만 실행합니다. 이 글은 그 "몇 개만"이 config에 어떻게 적히고, 무엇을 아끼고 무엇을 아끼지 못하는지를 다룹니다.
수치는 2026-08-12에 논문·공식 리포트·config.json에서 직접 확인했습니다. 모델은 갱신되므로 원본을 다시 확인하세요.
가장 단순한 형태: Mixtral
Mixtral-8x7B의 config에서 MoE 관련 필드만 뽑으면 이렇습니다.
{
"num_local_experts": 8,
"num_experts_per_tok": 2,
"intermediate_size": 14336,
"router_aux_loss_coef": 0.02
}
전문가가 8개이고 토큰마다 2개를 씁니다. Mixtral 논문은 이 구조를 두고 전체 470억 파라미터 중 토큰당 130억만 사용한다고 적습니다(arXiv:2401.04088). 같은 논문은 라우터가 매 층, 매 토큰마다 두 전문가를 고르며 시점마다 다른 전문가가 선택될 수 있다고 설명합니다.
활성 파라미터와 전체 파라미터
여기서 가장 중요한 오해를 짚고 갑니다. 활성 파라미터가 줄어드는 것은 연산량이지 메모리가 아닙니다. 전문가는 언제 호출될지 모르므로 전부 메모리에 올라가 있어야 합니다. Mixtral 논문도 서빙 메모리 비용은 희소 파라미터 수인 470억에 비례한다고 명시합니다.
Qwen3-30B-A3B로 직접 계산해 보겠습니다. config는 hidden_size 2048, 층 48개, 전문가 128개, num_experts_per_tok 8, moe_intermediate_size 768입니다.
전문가 하나 (게이트/업/다운 3개 행렬)
= 3 x 2,048 x 768 = 4,718,592
층 하나의 전문가 전체 : 128 x 4,718,592 = 603,979,776
층 하나에서 실제 실행 : 8 x 4,718,592 = 37,748,736
전체 파라미터 (계산) = 30,532,122,624 -> 공개 값과 정확히 일치
활성 파라미터 (계산) = 3,353,032,704 -> 약 3.35B, 이름의 A3B와 일치
비율 = 3.35B / 30.53B = 약 11%
연산은 11퍼센트만 하지만 메모리는 100퍼센트 필요합니다. MoE의 본질은 메모리를 연산으로 바꿔 주는 거래가 아니라, 메모리를 더 쓰는 대신 같은 연산으로 더 많은 지식을 담는 거래입니다.
공유 전문가와 조밀한 첫 층
DeepSeek-V3는 조금 다른 구조를 씁니다. 기술 리포트의 모델 하이퍼파라미터 절에 따르면 층은 61개, 각 MoE 계층은 공유 전문가 1개와 라우팅 전문가 256개로 이루어지고, 라우팅 전문가 중 8개가 토큰마다 활성화됩니다. 전문가 내부 차원은 2048입니다. 전체 6710억 중 토큰당 370억이 활성화됩니다(arXiv:2412.19437).
공유 전문가는 라우팅과 무관하게 모든 토큰이 항상 통과하는 전문가입니다. 어느 토큰에나 필요한 공통 기능을 여기에 몰아 두면, 라우팅 전문가들은 더 특화된 역할을 맡을 수 있습니다.
또 하나 눈여겨볼 필드가 first_k_dense_replace입니다. DeepSeek-V3는 이 값이 3이고, 리포트도 첫 세 층을 제외한 모든 FFN을 MoE로 바꿨다고 적습니다. Kimi K2는 같은 필드가 1입니다. 초기 층은 토큰별 특화보다 일반적인 표현을 만드는 일을 하므로 조밀하게 두는 편이 안정적이라는 판단입니다.
로드 밸런싱: 두 갈래
라우터를 그냥 두면 소수의 전문가에게 토큰이 몰립니다. 나머지 전문가는 학습되지 않고, 병렬화한 장비 사이에 부하가 쏠립니다. 해결책은 크게 두 갈래입니다.
첫째는 보조 손실입니다. 부하가 균등해지도록 손실 항을 추가합니다. config의 router_aux_loss_coef가 그 계수이고, Mixtral은 0.02, Qwen3 MoE 모델들은 0.001입니다. Qwen3 리포트는 전문가 특화를 장려하기 위해 전역 배치 단위의 로드 밸런싱 손실을 채택했다고 밝힙니다(arXiv:2505.09388). 문제는 이 손실이 본래 목적함수와 다투기 때문에 성능을 조금 깎는다는 점입니다.
둘째는 보조 손실을 쓰지 않는 방식입니다. DeepSeek-V3는 전문가마다 편향 항을 두고 상위 k개를 고를 때만 그 편향을 더합니다. 리포트에 따르면 편향은 라우팅에만 쓰이고, 매 스텝 끝에 과부하 전문가는 편향을 낮추고 저부하 전문가는 올립니다. 편향 갱신 속도는 처음 14.3조 토큰 동안 0.001이었다가 남은 5000억 토큰에서는 0으로 바뀝니다. 극단적 쏠림만 막기 위한 시퀀스 단위 균형 손실은 계수 0.0001로 아주 작게 유지합니다.
두 방식의 차이는 분명합니다. 보조 손실은 구현이 단순하지만 목적함수를 오염시키고, 편향 방식은 목적함수를 건드리지 않지만 조정할 하이퍼파라미터와 학습 중 스케줄이 늘어납니다.
희소도를 얼마나 올릴 것인가
Kimi K2는 전문가 수를 384개로 늘렸습니다. 리포트의 표 2는 DeepSeek-V3와 나란히 비교합니다. 층 수는 61개로 같고, 전체 파라미터는 6710억에서 1.04조로 늘었지만 활성 파라미터는 370억에서 326억으로 오히려 줄었습니다. 전문가는 256개에서 384개로 늘고 토큰당 활성 전문가는 8개로 같습니다(arXiv:2507.20534).
같은 리포트는 희소도를 전체 전문가 수를 활성 전문가 수로 나눈 값으로 정의하고, 활성 파라미터를 고정한 채 전체 전문가를 늘리면 학습·검증 손실이 일관되게 낮아졌다고 보고합니다. 검증 손실 1.5를 기준으로 희소도 48은 희소도 8, 16, 32 대비 각각 1.69배, 1.39배, 1.15배 적은 연산량으로 같은 지점에 도달했다고 적습니다.
대가도 같은 문단에 적혀 있습니다. 희소도를 올리면 인프라 복잡도가 올라가고, 그래서 성능과 비용의 균형점으로 48을 골랐다고 밝힙니다. 전문가가 많아질수록 장비 간 all-to-all 통신량과 배치 스케줄링 난이도가 함께 올라갑니다.
라우팅 범위 제한
DeepSeek-V3의 config에는 n_group 8, topk_group 4가 있습니다. 전문가를 그룹으로 묶고 토큰 하나가 닿을 수 있는 그룹 수를 제한하는 장치입니다. 리포트도 각 토큰이 최대 4개 노드로만 전송되도록 보장한다고 적습니다. 통신 비용에 상한을 두는 설계입니다. 반면 Kimi K2는 표 2에서 전문가 그룹화를 쓰지 않는다고 명시합니다. 같은 문제를 서로 다른 인프라 전제 위에서 푼 결과입니다.
마치며
MoE의 config는 네 가지만 보면 됩니다. 전문가가 몇 개인지, 토큰당 몇 개를 쓰는지, 공유 전문가가 있는지, 그리고 균형을 손실로 잡는지 편향으로 잡는지입니다. 이 네 값에서 활성 파라미터를 계산할 수 있고, 활성 파라미터는 연산 비용을, 전체 파라미터는 메모리 비용을 알려 줍니다. 두 숫자를 분리해서 읽는 것이 MoE를 이해하는 출발점입니다.
참고 자료
- Mixtral of Experts (arXiv:2401.04088): https://arxiv.org/abs/2401.04088
- DeepSeek-V3 Technical Report (arXiv:2412.19437): https://arxiv.org/abs/2412.19437
- Qwen3 Technical Report (arXiv:2505.09388): https://arxiv.org/abs/2505.09388
- Kimi K2 (arXiv:2507.20534): https://arxiv.org/abs/2507.20534
- Qwen3-30B-A3B config.json: https://huggingface.co/Qwen/Qwen3-30B-A3B/raw/main/config.json
- DeepSeek-V3 config.json: https://huggingface.co/deepseek-ai/DeepSeek-V3/raw/main/config.json
직접 해보기
- 신경망 아키텍처 탐색기 — 층 구성을 바꿔 가며 구조를 살펴보세요.
- VRAM 계산기 — 전체 파라미터 기준으로 메모리를 추정해 보세요.
- AI 벤치마크 정리 — 벤치마크 수치를 볼 때 어떤 조건이 붙는지 확인해 보세요.
시리즈
- 이전 글: config.json 완전 해부
- 다음 글: 어텐션 변형 — MHA에서 MLA까지
MoE Routing — How an Expert Gets Picked
- Introduction
- The Simplest Form: Mixtral
- Active Parameters Versus Total Parameters
- Shared Experts and Dense Early Layers
- Load Balancing: Two Approaches
- How Far to Push Sparsity
- Limiting Routing Scope
- Closing
- References
- Try It Yourself
- Series
Introduction
In the previous post we counted the parameters of a dense model from its config.json. But open the config of a modern large model and unfamiliar fields appear, such as num_experts or n_routed_experts. This is the mixture-of-experts, or MoE, layer.
The idea is simple. Split the single FFN in each layer into many smaller FFNs, and run only a few of them per token. This post is about how that "only a few" is written into the config, and what it does and does not save.
All figures were verified directly against papers, official reports, and config.json files on 2026-08-12. Models get updated, so check the originals again.
The Simplest Form: Mixtral
Pulling only the MoE-related fields from the Mixtral-8x7B config gives this.
{
"num_local_experts": 8,
"num_experts_per_tok": 2,
"intermediate_size": 14336,
"router_aux_loss_coef": 0.02
}
There are 8 experts and each token uses 2. The Mixtral paper describes this structure as giving each token access to 47B parameters while using only 13B active parameters per token (arXiv:2401.04088). The same paper explains that the router chooses two experts at every layer for every token, and that different experts can be selected at each timestep.
Active Parameters Versus Total Parameters
Here is the misconception worth settling first. What shrinks with active parameters is compute, not memory. Since you never know which expert will be called, all of them must sit in memory. The Mixtral paper states plainly that the memory cost of serving Mixtral is proportional to its sparse parameter count of 47B.
Let us compute this directly for Qwen3-30B-A3B. The config gives hidden_size 2048, 48 layers, 128 experts, num_experts_per_tok 8, and moe_intermediate_size 768.
One expert (gate/up/down, 3 matrices)
= 3 x 2,048 x 768 = 4,718,592
All experts in one layer : 128 x 4,718,592 = 603,979,776
Actually executed : 8 x 4,718,592 = 37,748,736
Total parameters (computed) = 30,532,122,624 -> matches the published value exactly
Active parameters (computed) = 3,353,032,704 -> about 3.35B, matching the A3B in the name
Ratio = 3.35B / 30.53B = about 11%
You do 11 percent of the compute but need 100 percent of the memory. The essence of MoE is not trading memory for compute. It is spending more memory to hold more knowledge at the same compute.
Shared Experts and Dense Early Layers
DeepSeek-V3 uses a slightly different structure. According to the model hyper-parameters section of its technical report, there are 61 layers, each MoE layer consists of 1 shared expert and 256 routed experts, and 8 of the routed experts activate per token. The expert intermediate dimension is 2048. Of 671B total parameters, 37B activate per token (arXiv:2412.19437).
A shared expert is one that every token passes through regardless of routing. Concentrating the common functionality that every token needs into that expert frees the routed experts to take on more specialized roles.
Another field worth noting is first_k_dense_replace. DeepSeek-V3 sets it to 3, and the report likewise states that all FFNs except those in the first three layers were substituted with MoE layers. Kimi K2 sets the same field to 1. Early layers build general representations rather than token-specific specialization, so keeping them dense is the more stable choice.
Load Balancing: Two Approaches
Left alone, a router will funnel tokens to a handful of experts. The rest never train, and load piles up unevenly across parallel devices. There are broadly two remedies.
The first is an auxiliary loss. You add a loss term that pushes the load toward uniformity. The router_aux_loss_coef in the config is its coefficient: 0.02 for Mixtral and 0.001 for the Qwen3 MoE models. The Qwen3 report states that a global-batch load balancing loss was adopted to encourage expert specialization (arXiv:2505.09388). The problem is that this loss competes with the real objective and shaves off a little quality.
The second approach avoids an auxiliary loss entirely. DeepSeek-V3 keeps a bias term per expert and adds it to the affinity scores only when selecting the top k. The report notes that the bias is used only for routing, and that at the end of each step the bias is decreased for overloaded experts and increased for underloaded ones. The bias update speed was 0.001 for the first 14.3T tokens and switched to 0.0 for the remaining 500B tokens. A sequence-wise balance loss guards against extreme imbalance and is kept very small, with a coefficient of 0.0001.
The contrast is clear. An auxiliary loss is simple to implement but contaminates the objective, while the bias scheme leaves the objective alone at the cost of extra hyperparameters and a schedule to tune during training.
How Far to Push Sparsity
Kimi K2 raised the expert count to 384. Table 2 of its report lines the model up against DeepSeek-V3. Layer count is the same at 61, total parameters rose from 671B to 1.04T, yet active parameters fell from 37B to 32.6B. Experts went from 256 to 384 while active experts per token stayed at 8 (arXiv:2507.20534).
The same report defines sparsity as the ratio of total experts to activated experts, and reports that holding activated parameters fixed while increasing the total number of experts consistently lowered both training and validation loss. At a validation loss of 1.5, it states that sparsity 48 reached the same point with 1.69x, 1.39x, and 1.15x fewer FLOPs than sparsity levels 8, 16, and 32 respectively.
The cost appears in the same paragraph. Raising sparsity increases infrastructure complexity, and the authors say they chose 48 to balance performance against cost. As experts multiply, both all-to-all communication volume between devices and the difficulty of batch scheduling rise with them.
Limiting Routing Scope
The DeepSeek-V3 config contains n_group 8 and topk_group 4. This groups experts and caps how many groups a single token can reach. The report likewise states that each token is ensured to be sent to at most 4 nodes. It is a design that puts a ceiling on communication cost. Kimi K2, by contrast, explicitly lists expert grouping as not used in Table 2. The same problem solved on different infrastructure assumptions.
Closing
For an MoE config you only need four things: how many experts there are, how many are used per token, whether there is a shared expert, and whether balance is enforced by a loss or by a bias. From those four values you can compute active parameters, and active parameters tell you the compute cost while total parameters tell you the memory cost. Reading those two numbers separately is where understanding MoE begins.
References
- Mixtral of Experts (arXiv:2401.04088): https://arxiv.org/abs/2401.04088
- DeepSeek-V3 Technical Report (arXiv:2412.19437): https://arxiv.org/abs/2412.19437
- Qwen3 Technical Report (arXiv:2505.09388): https://arxiv.org/abs/2505.09388
- Kimi K2 (arXiv:2507.20534): https://arxiv.org/abs/2507.20534
- Qwen3-30B-A3B config.json: https://huggingface.co/Qwen/Qwen3-30B-A3B/raw/main/config.json
- DeepSeek-V3 config.json: https://huggingface.co/deepseek-ai/DeepSeek-V3/raw/main/config.json
Try It Yourself
- Neural network architecture explorer — vary the layer configuration and inspect the structure.
- VRAM calculator — estimate memory against the total parameter count.
- AI benchmark overview — check what conditions are attached when you read benchmark numbers.
Series
- Previous: Anatomy of config.json
- Next: Attention Variants — From MHA to MLA