Down projection
×Map 2,304 gated features back to 5,120 features.
- in
- [B batch, T positions, 2304 d_ff]
- out
- [B batch, T positions, 5120 d]
The reference multiplies the gated features by the token’s routing weight before this projection (model.py 849–850), which equals weighting the expert’s output; the weighted sum outside draws it there.
Parameters11,796,480 × 3,840 experts
11,796,480 parameters per instance.
| Component | Calculation | Parameters |
|---|---|---|
| Weight matrix | 2,304 × 5,120 | 11,796,480 |
This projection has no bias parameter.
The reference module holds the weight output by input, [out, in].
One in each of 3,840 experts: 384 in each of 5 layers in each of 2 groups.
Sources
In codeself.w2(x) · 851
Direct evidence
An expert is SwiGLU with its gate and up branches clamped; the routing weight multiplies the hidden features before the down projection.
model.py 830–851 ↗ · deepseek-ai/DeepSeek-V4.1-Flash @ 2cba9e42aa02
Excerpt
class Expert(nn.Module):
"""One SwiGLU FFN. The clamps come straight from training, where they keep fp8/fp4 activations in
range: the up branch is clamped on both sides, the gate branch only from above."""
def __init__(self, dim: int, inter_dim: int, dtype=None, swiglu_limit=0.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: torch.Tensor | None = 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))