Layer

MLP residual merge

×

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

xn+1=xn′+Dresid(Δmlp){\htmlData{light=x-out mlp-add}{x_{n+1}}}={\htmlData{light=x-attn attn-add}{x'_{n}}}+D_{\mathrm{resid}}({\htmlData{light=mlp}{\Delta_{\mathrm{mlp}}}})
in
xn′x'_{n} [B batch, T positions, 768 d]Dresid(Δmlp)D_{\mathrm{resid}}(\Delta_{\mathrm{mlp}}) [B batch, T positions, 768 d]
out
xn+1x_{n+1} [B batch, T positions, 768 d]

DresidD_{\mathrm{resid}} is dropout during training and the identity at evaluation. The maintained code applies it inside the MLP module (modeling_gpt2.py 242); the released code adds mm as it is.

Sources

Direct evidence

Second branch and layer return in the reference graph.

model.py 123–130 ↗ · openai/gpt-2 @ 9b63575ef427

Excerpt
        m = mlp(norm(x, 'ln_2'), 'mlp', nx*4, hparams=hparams)
        x = x + m
        return x, present

The same residual contract in the maintained PyTorch implementation.

modeling_gpt2.py 303–309 ↗ · huggingface/transformers @ 71c6f699ac9b

Excerpt
        residual = hidden_states
        hidden_states = self.ln_2(hidden_states)
        feed_forward_hidden_states = self.mlp(hidden_states)

… lines 306–306 omitted …

        hidden_states = residual + feed_forward_hidden_states

Incoming transform evidence

The maintained training path applies residual dropout after the MLP projection and before the residual write; evaluation makes dropout the identity.

modeling_gpt2.py 238–243 ↗ · huggingface/transformers @ 71c6f699ac9b

Excerpt
        hidden_states = self.c_proj(hidden_states)
        hidden_states = self.dropout(hidden_states)
        return hidden_states