40 layers › 2 groups of 6 layers › Source layer, pairs pooled
MoE RMSNorm
×learnedself.ffn_norm(x) · 991
Rescale each position’s features using their root mean square, then apply learned gain.
- in
- [B batch, T positions, 5120 d]
- out
- [B batch, T positions, 5120 d]
- parameters
- 5,120 · × 2 groups = 10,240
Parameters
5,120 parameters per instance.
| Component | Calculation | Parameters |
|---|---|---|
| Learned gain | 5,120 | |
| Per-instance total | 5,120 | |
Each normalization instance owns its learned gain vector.
Across 2 independent groups: parameters.
Derived from the configured feature width; the model total matches the checkpoint’s tensors.
Codemodel.py 281–293, 968–994
class RMSNorm(nn.Module):
def __init__(self, dim: int, eps: float = 1e-6):
super().__init__()
self.dim = dim
self.eps = eps
self.weight = nn.Parameter(torch.ones(dim))
def forward(self, x: torch.Tensor):
dtype = x.dtype
x = x.float()
var = x.square().mean(-1, keepdim=True)
x = x * torch.rsqrt(var + self.eps)
return (self.weight * x).to(dtype) def forward(
self,
x: torch.Tensor,
start_pos: int,
pre_mix: torch.Tensor,
image_mask: torch.Tensor | None,
*attn_args,
) -> tuple[torch.Tensor, torch.Tensor]:
"""`pre_mix` collapses the hc_mult copies down to one input for this block's attention. Each
sub-block's own `hc_mixes` produces the mix for the *next* one, so attention uses what the
previous layer's FFN produced and the FFN uses what this attention produced.
image_mask: [b, s] bool, True inside image spans (selects the VL routing bias)."""
residual = x
attn_pre, attn_post, attn_comb = self.hc_mixes(x, self.hc_attn_fn, self.hc_attn_scale, self.hc_attn_base)
x = self.hc_pre(x, pre_mix)
x = self.attn_norm(x)
x = self.attn(x, start_pos, *attn_args)
x = self.hc_post(x, residual, attn_post, attn_comb)
residual = x
ffn_pre, ffn_post, ffn_comb = self.hc_mixes(x, self.hc_ffn_fn, self.hc_ffn_scale, self.hc_ffn_base)
x = self.hc_pre(x, attn_pre)
x = self.ffn_norm(x)
x = self.ffn(x, image_mask)
x = self.hc_post(x, residual, ffn_post, ffn_comb)
return x, ffn_preSources2
Direct evidence
RMSNorm divides by the root mean square over the features, computed in float32, and multiplies by a learned gain.
rmsnorm · deepseek-ai/DeepSeek-V4.1-Flash / inference/model.py
Pinned revision 2cba9e42aa02 ↗ · lines 281–293
Read code excerpt
class RMSNorm(nn.Module):
def __init__(self, dim: int, eps: float = 1e-6):
super().__init__()
self.dim = dim
self.eps = eps
self.weight = nn.Parameter(torch.ones(dim))
def forward(self, x: torch.Tensor):
dtype = x.dtype
x = x.float()
var = x.square().mean(-1, keepdim=True)
x = x * torch.rsqrt(var + self.eps)
return (self.weight * x).to(dtype)Direct evidence
Attention reads the streams with the mix the previous sublayer computed and writes with its own; the mixture reads with the mix attention computed and writes with its own, and hands its reading mix to the next layer.
block-forward · deepseek-ai/DeepSeek-V4.1-Flash / inference/model.py
Pinned revision 2cba9e42aa02 ↗ · lines 968–994
Read code excerpt
def forward(
self,
x: torch.Tensor,
start_pos: int,
pre_mix: torch.Tensor,
image_mask: torch.Tensor | None,
*attn_args,
) -> tuple[torch.Tensor, torch.Tensor]:
"""`pre_mix` collapses the hc_mult copies down to one input for this block's attention. Each
sub-block's own `hc_mixes` produces the mix for the *next* one, so attention uses what the
previous layer's FFN produced and the FFN uses what this attention produced.
image_mask: [b, s] bool, True inside image spans (selects the VL routing bias)."""
residual = x
attn_pre, attn_post, attn_comb = self.hc_mixes(x, self.hc_attn_fn, self.hc_attn_scale, self.hc_attn_base)
x = self.hc_pre(x, pre_mix)
x = self.attn_norm(x)
x = self.attn(x, start_pos, *attn_args)
x = self.hc_post(x, residual, attn_post, attn_comb)
residual = x
ffn_pre, ffn_post, ffn_comb = self.hc_mixes(x, self.hc_ffn_fn, self.hc_ffn_scale, self.hc_ffn_base)
x = self.hc_pre(x, attn_pre)
x = self.ffn_norm(x)
x = self.ffn(x, image_mask)
x = self.hc_post(x, residual, ffn_post, ffn_comb)
return x, ffn_pre