Embedding addition
×no parameterstf.gather(wte, X) + tf.gather(wpe, positions_for(X, past_length))
Add token and position vectors element-wise before training-only embedding dropout initializes the residual stream.
- in
- [B batch, T positions, 768 d] [B batch, T positions, 768 d]
- out
- [B batch, T positions, 768 d]
During training the maintained code applies dropout to before the first block (modeling_gpt2.py 604): . At evaluation, and in the released code, .
Codemodeling_gpt2.py 577–608 · model.py 157
hidden_states = inputs_embeds + position_embeds.to(inputs_embeds.device) hidden_states = self.drop(hidden_states) for i, block in enumerate(self.h): h = tf.gather(wte, X) + tf.gather(wpe, positions_for(X, past_length))Sources2
Direct evidence
For the base GPT-2 text path, embedding dropout follows token-plus-position addition and precedes the block loop; optional token-type embeddings are outside the base text path.
transformers · huggingface/transformers / src/transformers/models/gpt2/modeling_gpt2.py
Pinned revision 71c6f699ac9b ↗ · lines 576–608
Read code excerpt
hidden_states = inputs_embeds + position_embeds.to(inputs_embeds.device)… lines 578–603 omitted …
hidden_states = self.drop(hidden_states)… lines 605–607 omitted …
for i, block in enumerate(self.h):Direct evidence
The original graph gathers the two tables and adds them into the initial stream.
openai · openai/gpt-2 / src/model.py
Pinned revision 9b63575ef427 ↗ · lines 152–157
Read code excerpt
h = tf.gather(wte, X) + tf.gather(wpe, positions_for(X, past_length))