Attention 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 attention module (modeling_gpt2.py 224); the released code adds as it is.
Sources
In codex + a
Direct evidence
First branch of the original GPT-2 layer.
model.py 123–130 ↗ · openai/gpt-2 @ 9b63575ef427
Excerpt
a, present = attn(norm(x, 'ln_1'), 'attn', nx, past=past, hparams=hparams)
x = x + aThe PyTorch layer saves residual before normalization and adds it after attention.
modeling_gpt2.py 272–282 ↗ · huggingface/transformers @ 71c6f699ac9b
Excerpt
residual = hidden_states
hidden_states = self.ln_1(hidden_states)
attn_output, _ = self.attn(… lines 275–281 omitted …
hidden_states = attn_output + residualIncoming transform evidence
The maintained training path applies residual dropout after c_proj and before the residual write; evaluation makes dropout the identity.
modeling_gpt2.py 222–226 ↗ · huggingface/transformers @ 71c6f699ac9b
Excerpt
attn_output = self.c_proj(attn_output)
attn_output = self.resid_dropout(attn_output)
return attn_output, attn_weights