MLP residual merge
×Add the mechanism’s update to the residual stream element by element.
- in
- [B batch, T positions, 768 d] [B batch, T positions, 768 d]
- out
- [B batch, T positions, 768 d]
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 as it is.
Sources
In codex + m
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, presentThe 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_statesIncoming 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