Global layer

Add attention update

×

Add the mechanism’s update to the residual stream element by element.

h′=h+Δattn{\htmlData{light=residual attention-add}{h'}}={\htmlData{light=block-input}{h}}+{\htmlData{light=attention}{\Delta_{\mathrm{attn}}}}
in
hh [B batch, T positions, 2880 d]Δattn\Delta_{\mathrm{attn}} [B batch, T positions, 2880 d]
out
h′h' [B batch, T positions, 2880 d]
Sources

In codex + t · 245

Open pinned code ↗

Direct evidence

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