Attention RMSNorm
×Rescale each position’s features using their root mean square, then apply learned gain.
- in
- [B batch, T positions, 2880 d]
- out
- [B batch, T positions, 2880 d]
Computed in float32 and cast back after the scale multiplies (model.py 43–47); the scale is stored in bfloat16 in the checkpoint and held in float32 by the module.
Parameters2,880 × 18 layers
2,880 parameters per instance.
| Component | Parameters |
|---|---|
| Learned gain | 2,880 |
One in each of the 18 global layers, each with its own weights.
Sources
In codeself.norm(x) · 218
Direct evidence
RMSNorm: a float32 scale initialised to ones; the input taken to float32, divided by the root of its mean square plus ε (10⁻⁵ by default), multiplied by the scale and cast back.
model.py 32–47 ↗ · openai/gpt-oss @ 5681a6b65526
Excerpt
class RMSNorm(torch.nn.Module):
def __init__(
self, num_features: int, eps: float = 1e-05, device: torch.device | None = None
):
super().__init__()
self.num_features = num_features
self.eps = eps
self.scale = torch.nn.Parameter(
torch.ones(num_features, device=device, dtype=torch.float32)
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
assert x.shape[-1] == self.num_features
t, dtype = x.float(), x.dtype
t = t * torch.rsqrt(torch.mean(t**2, dim=-1, keepdim=True) + self.eps)
return (t * self.scale).to(dtype)The attention block’s forward: normalise; project; take the query, key and value features in that order; read queries as 8 groups of 8 heads of 64, keys and values as 8 heads of 64; rotate queries and keys; attend; project; add to the block’s input.
model.py 217–246 ↗ · openai/gpt-oss @ 5681a6b65526
Excerpt
def forward(self, x: torch.Tensor) -> torch.Tensor:
t = self.norm(x)
qkv = self.qkv(t)
q = qkv[:, : self.num_attention_heads * self.head_dim].contiguous()
k = qkv[
:,
self.num_attention_heads
* self.head_dim : (self.num_attention_heads + self.num_key_value_heads)
* self.head_dim,
].contiguous()
v = qkv[
:,
(self.num_attention_heads + self.num_key_value_heads)
* self.head_dim : (self.num_attention_heads + 2 * self.num_key_value_heads)
* self.head_dim,
].contiguous()
q = q.view(
-1,
self.num_key_value_heads,
self.num_attention_heads // self.num_key_value_heads,
self.head_dim,
)
k = k.view(-1, self.num_key_value_heads, self.head_dim)
v = v.view(-1, self.num_key_value_heads, self.head_dim)
q, k = self.rope(q, k)
t = sdpa(q, k, v, self.sinks, self.sm_scale, self.sliding_window)
t = self.out(t)
t = x + t
return t