Rotary and relative position encodings
What it is
Inject position by rotating query/key pairs by an angle proportional to position (RoPE), or by adding learned relative biases (ALiBi, T5).
When to use it
Every modern transformer. RoPE with frequency scaling (YaRN, NTK) is how context windows get extended at inference.
Caveats
Extrapolation to sequences longer than those seen in training is unreliable without adjusting the frequencies or fine-tuning. The base frequency is a hyperparameter, and RoPE must be applied inside every attention layer.
Key ideas
- RoPE is relative in the dot product, which is why it extrapolates at all
- Position-scheme choice determines how well a model stretches to longer context
Related architectures
Original paper
RoFormer: Enhanced Transformer with Rotary Position Embedding (2021, arXiv)