passdrill
AI & LLM Engineering · How LLMs Work: Transformers & Training · Card 015/024 hard

Su et al. (2021), "RoFormer: Enhanced Transformer with Rotary Position Embedding," introduce rotary position embedding (RoPE) as an alternative to adding sinusoidal positional vectors to token embeddings. How does RoPE encode positional information?

  1. It concatenates a learned position index as an extra dimension appended to every query and key vector before the dot product is computed
  2. It rotates each query and key vector by an angle that depends on the token's position and a per-dimension frequency, so that the dot product between a rotated query and key naturally depends on their relative distance rather than their absolute positions alone
  3. It replaces the dot-product attention score with a lookup table indexed by the absolute position of the query, discarding the key vector's position entirely
  4. It multiplies the attention output by a fixed sinusoidal mask after the softmax has already been applied, without altering the query or key vectors themselves
Next card → Shuffle