Masked multi-head self-attention

Attention weights after dropout

×

Training dropout acts on the probabilities before value retrieval; at evaluation this equals A.

shape
A~iÃ_{i} head i [B batch, 1, 1001]A~\widetilde A all heads [B batch, 12 heads, 1, 1001]

Training only, in the maintained code: dropout zeroes some weights and rescales the rest, so a row need not sum to one (modeling_gpt2.py 67). At evaluation, and in the released OpenAI code, A~i=Ai\widetilde A_i=A_i.

Sources

In codeattn_weights · modeling_gpt2.py 67

Open pinned code ↗

Incoming transform evidence

The maintained eager attention path normalizes scores, applies training-dependent dropout, and multiplies the resulting weights by values.

modeling_gpt2.py 63–69 ↗ · huggingface/transformers @ 71c6f699ac9b

Excerpt
    attn_weights = nn.functional.softmax(attn_weights, dim=-1)

    # Downcast (if necessary) back to V's dtype (if in mixed-precision) -- No-Op otherwise
    attn_weights = attn_weights.type(value.dtype)
    attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)

    attn_output = torch.matmul(attn_weights, value)