RMSNorm 1
×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]
Normalized in float32 and cast back to the input type before the gain multiplies (model.py 45–46).
Parameters4,096 × 32 layers
4,096 parameters per instance.
| Component | Parameters |
|---|---|
| Learned gain | 4,096 |
One in each of the 32 layers, each with its own weights.
Not checked against a checkpoint.
Sources
In codeself.attention_norm(x)
Direct evidence
RMSNorm rescales the final feature axis and applies one learned gain vector; layer and final callers supply configured epsilon.
model.py 35–266 ↗ · meta-llama/llama3 @ a0940f9cf706
Excerpt
class RMSNorm(torch.nn.Module):
def __init__(self, dim: int, eps: float = 1e-6):
super().__init__()
self.eps = eps
self.weight = nn.Parameter(torch.ones(dim))
def _norm(self, x):
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
def forward(self, x):
output = self._norm(x.float()).type_as(x)
return output * self.weight… lines 47–235 omitted …
self.attention_norm = RMSNorm(args.dim, eps=args.norm_eps)
self.ffn_norm = RMSNorm(args.dim, eps=args.norm_eps)… lines 238–265 omitted …
self.norm = RMSNorm(params.dim, eps=params.norm_eps)Meta’s original Llama 3 8B base catalogue entry supplies dimensions, head counts, vocabulary, MLP rounding settings, epsilon and unscaled RoPE settings.
sku_list.py 19–207 ↗ · meta-llama/llama-models @ 0e0b8c519242
Excerpt
LLAMA3_VOCAB_SIZE = 128256… lines 20–187 omitted …
def llama3_base_models() -> list[Model]:
return [
Model(
core_model_id=CoreModelId.llama3_8b,
description="Llama 3 8b model",
huggingface_repo="meta-llama/Llama-3-8B",
arch_args={
"dim": 4096,
"n_layers": 32,
"n_heads": 32,
"n_kv_heads": 8,
"vocab_size": LLAMA3_VOCAB_SIZE,
"ffn_dim_multiplier": 1.3,
"multiple_of": 1024,
"norm_eps": 1e-05,
"rope_theta": 500000.0,
"use_scaled_rope": False,
},
pth_file_count=1,
),Two independently normalized mechanism branches are added to their corresponding residual inputs.
model.py 236–248 ↗ · meta-llama/llama3 @ a0940f9cf706
Excerpt
self.attention_norm = RMSNorm(args.dim, eps=args.norm_eps)
self.ffn_norm = RMSNorm(args.dim, eps=args.norm_eps)
def forward(
self,
x: torch.Tensor,
start_pos: int,
freqs_cis: torch.Tensor,
mask: Optional[torch.Tensor],
):
h = x + self.attention(self.attention_norm(x), start_pos, freqs_cis, mask)
out = h + self.feed_forward(self.ffn_norm(h))
return out