Routed expert
×One of 256 independent SwiGLU experts; each position runs only the 8 its router selected.
All 5 steps
- in
- [B batch, T positions, 7168 d]
- out
- [B batch, T positions, 7168 d]
Parameters44,040,192 × 14,848 experts
44,040,192 parameters per expert, across its learned components
| Component | Calculation | Parameters |
|---|---|---|
| Gate projection | 7,168 × 2,048 | 14,680,064 |
| Up projection | 7,168 × 2,048 | 14,680,064 |
| Down projection | 2,048 × 7,168 | 14,680,064 |
| Per-instance total | 44,040,192 | |
One of 14,848 independent experts: 256 in each of 58 MoE layers.
Explanation
The reference runs expert only on the positions routed to it and adds its weighted output back at those positions (model.py 794–800).
Sources
In codeself.experts
Direct evidence
Each routed expert is its own SwiGLU MLP of moe_inter_dim hidden features.
model.py 730–744 ↗ · deepseek-ai/DeepSeek-V3.2 @ a7e62ac04ecb
Excerpt
self.w1 = Linear(dim, inter_dim)
self.w2 = Linear(inter_dim, dim)
self.w3 = Linear(dim, inter_dim)… lines 733–743 omitted …
return self.w2((F.silu(self.w1(x).float()) * self.w3(x).float()).type_as(x))The MoE layer holds the router, the routed experts and one shared expert MLP of n_shared_experts × moe_inter_dim features.
model.py 770–778 ↗ · deepseek-ai/DeepSeek-V3.2 @ a7e62ac04ecb
Excerpt
self.n_routed_experts = args.n_routed_experts
self.n_local_experts = args.n_routed_experts // world_size
self.n_activated_experts = args.n_activated_experts
self.experts_start_idx = rank * self.n_local_experts
self.experts_end_idx = self.experts_start_idx + self.n_local_experts
self.gate = Gate(args)
self.experts = nn.ModuleList([Expert(args.dim, args.moe_inter_dim) if self.experts_start_idx <= i < self.experts_end_idx else None
for i in range(self.n_routed_experts)])
self.shared_experts = MLP(args.dim, args.n_shared_experts * args.moe_inter_dim, reduce_output=False)Each token’s output is the router-weighted sum of its selected experts plus the shared expert applied to every token.
model.py 790–803 ↗ · deepseek-ai/DeepSeek-V3.2 @ a7e62ac04ecb
Excerpt
shape = x.size()
x = x.view(-1, self.dim)
weights, indices = self.gate(x)
y = torch.zeros_like(x, dtype=torch.float32)
counts = torch.bincount(indices.flatten(), minlength=self.n_routed_experts).tolist()
for i in range(self.experts_start_idx, self.experts_end_idx):
if counts[i] == 0:
continue
expert = self.experts[i]
idx, top = torch.where(indices == i)
y[idx] += expert(x[idx]) * weights[idx, top, None]
y += self.shared_experts(x)
if world_size > 1:
dist.all_reduce(y)