Legacy Concept Lab
Rotary Position Embeddings (RoPE)
GPT-NeoX, Llama 1/2/3, PaLM, Gemini, Claude 3: RoPE is the dominant position encoding for modern LLMs
#18RoPERepresentations
key equation
Phase 2: Architecture fundamentalsConcept 18 of 100
Why It Matters for Modern Models
- GPT-NeoX, Llama 1/2/3, PaLM, Gemini, Claude 3: RoPE is the dominant position encoding for modern LLMs
- Enables better length extrapolation than learned absolute positions—models can handle longer contexts than seen in training
- Multi-frequency structure naturally represents both local patterns (high ω) and long-range dependencies (low ω)
What Tutorials Skip
What is still poorly explained in textbooks and papers:
- Why rotation specifically? Because group composition R(θ_p)^T R(θ_q) = R(θ_q - θ_p) automatically produces relative position
- How multi-frequency pairs work like clock hands: fast clocks for nearby tokens, slow clocks for distant ones
- Why long-context methods (Position Interpolation, YaRN) scale positions—prevents phase wrapping beyond training distribution
- Geometric picture: RoPE is equivariance to translation, similar to CNNs but for 1D sequences via rotation group
Interactive Visualization
Core Math (Optional Deep Dive)
If you want intuition first, start with the key equation and the visualization. Come back here for the full walkthrough.
Key Equation
Attention is permutation-equivariant by design—without position encoding, transformers can't distinguish token order.
RoPE encodes position as a rotation applied to queries and keys. For 2D subspace with position :
where
The key property: rotations compose via relative position:
Full RoPE applies this to multiple 2D pairs at different frequencies , creating a multi-scale positional ruler.
In complex notation: , making relative position a phase difference.