Embedding dropout
×During training, drop and rescale the summed token and position embeddings before the first layer. Evaluation leaves the sum unchanged.
- in
- [B batch, T positions, 768 d]
- out
- [B batch, T positions, 768 d]
Training only: in evaluation it returns its input unchanged.
Explanation
Acts between Embedding addition and Initial residual stream.
Dropout is training regularization: randomly removing contributions reduces reliance on particular features or attention connections. During training, elements are independently retained with probability and retained values are divided by . Evaluation returns the input unchanged.
This dropout is the maintained training implementation (Transformers). The released OpenAI graph implements inference with dropout omitted.
Sources
Direct evidence
For the base GPT-2 text path, embedding dropout follows token-plus-position addition and precedes the layer loop; optional token-type embeddings are outside the base text path.
modeling_gpt2.py 576–608 ↗ · huggingface/transformers @ 71c6f699ac9b
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):PyTorch documents dropout as training regularization, with retained-value rescaling and identity evaluation. This is general operation evidence; GPT-2 placement is sourced separately.
dropout.py 35–70 ↗ · pytorch/pytorch @ ba56102387ef
Excerpt
class Dropout(_DropoutNd):
r"""During training, randomly zeroes some of the elements of the input tensor with probability :attr:`p`.
The zeroed elements are chosen independently for each forward call and are sampled from a Bernoulli distribution.… lines 39–41 omitted …
This has proven to be an effective technique for regularization and
preventing the co-adaptation of neurons as described in the paper
`Improving neural networks by preventing co-adaptation of feature
detectors`_ .
Furthermore, the outputs are scaled by a factor of :math:`\frac{1}{1-p}` during
training. This means that during evaluation the module simply computes an
identity function.… lines 50–68 omitted …
def forward(self, input: Tensor) -> Tensor:
return F.dropout(input, self.p, self.training, self.inplace)