Routed expert

Gate projection

×

Map 4,096 input features to 2,048 gate features.

g=xffnW1{\htmlData{light=gate}{g}}={\htmlData{light=x}{x_{\mathrm{ffn}}}}W_{1}
in
xffnx_{\mathrm{ffn}} [B batch, T positions, 4096 d]
out
gg [B batch, T positions, 2048 d_ff]
Parameters8,388,608 × 5,120 experts

8,388,608 parameters per instance.

ComponentCalculationParameters
Weight matrix4,096 × 2,0488,388,608

This projection has no bias parameter.

The reference module holds the weight output by input, [out, in].

One in each of 5,120 experts: 256 in each of 20 layers.

Sources

In codeself.w1(x) · 598

Open pinned code ↗

Direct evidence

An expert is a SwiGLU whose gate is clamped above at 10 and whose up branch is clamped to ±10, computed in float32, with the routing weight applied before the down projection.

model.py 587–606 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6

Excerpt
class Expert(nn.Module):
    """Single MoE expert: SwiGLU FFN (w1, w2, w3). Computation in float32 for stability."""
    def __init__(self, dim: int, inter_dim: int, dtype=None, swiglu_limit=0):
        super().__init__()
        self.w1 = Linear(dim, inter_dim, dtype=dtype)
        self.w2 = Linear(inter_dim, dim, dtype=dtype)
        self.w3 = Linear(dim, inter_dim, dtype=dtype)
        self.swiglu_limit = swiglu_limit

    def forward(self, x: torch.Tensor, weights: Optional[torch.Tensor] = None) -> torch.Tensor:
        dtype = x.dtype
        gate = self.w1(x).float()
        up = self.w3(x).float()
        if self.swiglu_limit > 0:
            up = torch.clamp(up, min=-self.swiglu_limit, max=self.swiglu_limit)
            gate = torch.clamp(gate, max=self.swiglu_limit)
        x = F.silu(gate) * up
        if weights is not None:
            x = weights * x
        return self.w2(x.to(dtype))