Shared expert

Up projection

×

Map 7,168 input features to 3,072 features in parallel with the gate.

u=xffnW3{\htmlData{light=up}{u}}={\htmlData{light=x}{x_{\mathrm{ffn}}}}W_{3}
in
xffnx_{\mathrm{ffn}} [B batch, T positions, 7168 d]
out
uu [B batch, T positions, 3072 d_ff]
Parameters22,020,096 × 2 layers

22,020,096 parameters per instance.

ComponentCalculationParameters
Weight matrix7,168 × 3,07222,020,096

This projection has no bias parameter.

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

One in each of the 2 layers, each with its own weights.

Sources

In codeself.w3(x) · 599

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-Pro @ b5968e9190ef

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))