MoE RMSNorm
×Rescale each position’s features using their root mean square, then apply learned gain.
- in
- [B batch, T positions, 4096 d]
- out
- [B batch, T positions, 4096 d]
Parameters4,096 × 20 layers
4,096 parameters per instance.
| Component | Parameters |
|---|---|
| Learned gain | 4,096 |
One in each of the 20 layers, each with its own weights.
Sources
In codeself.ffn_norm(x) · 697
Direct evidence
RMSNorm divides by the root mean square plus ε, in float32, and multiplies by a learned gain.
model.py 183–196 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6
Excerpt
class RMSNorm(nn.Module):
def __init__(self, dim: int, eps: float = 1e-6):
super().__init__()
self.dim = dim
self.eps = eps
# rmsnorm in the checkpoint is stored in bf16, while the parameter here is stored in fp32 for convenient.
self.weight = nn.Parameter(torch.ones(dim, dtype=torch.float32))
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)The block runs the two sublayers alike: compute the mixes from the streams, read with them, normalise, apply the sublayer, write the streams.
model.py 688–700 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6
Excerpt
def forward(self, x: torch.Tensor, start_pos: int, input_ids: Optional[torch.Tensor]) -> torch.Tensor:
residual = x
x, post, comb = self.hc_pre(x, self.hc_attn_fn, self.hc_attn_scale, self.hc_attn_base)
x = self.attn_norm(x)
x = self.attn(x, start_pos)
x = self.hc_post(x, residual, post, comb)
residual = x
x, post, comb = self.hc_pre(x, self.hc_ffn_fn, self.hc_ffn_scale, self.hc_ffn_base)
x = self.ffn_norm(x)
x = self.ffn(x, input_ids)
x = self.hc_post(x, residual, post, comb)
return x