passdrill
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 005/012 medium

Decoder-only autoregressive language models such as GPT (Radford et al., 2018) use masked self-attention during training. What does this masking do, and why is it necessary?

  1. It prevents the model from attending to tokens more than a fixed window size away, purely to reduce the compute cost of attention
  2. It forces every attention head to attend only to the current token itself, ignoring the representations at all other positions
  3. It sets the attention scores for future positions to negative infinity before the softmax, so a token's representation depends only on itself and earlier tokens, matching the left-to-right generation process
  4. It removes the value projection for positions beyond the current one, while still letting their key vectors influence the attention weights
Next card → Shuffle