How does Rotary Position Embedding (RoPE) encode relative position information?
Last updated
RoPE splits each query and key into 2D pairs and rotates pair i by angle m·θ_i at position m, with θ_i = 10000^(−2i/d) giving different frequencies.
Rotations compose, so
(R_m q)ᵀ(R_n k) = qᵀ R_{n−m} k. The attention score depends only on the offset, turning absolute rotations into relative position.It applies to Q and K only, adds no learned parameters, and works with KV caching. Longer contexts need rescaling (position interpolation, NTK scaling, YaRN).