How does Rotary Position Embedding (RoPE) work?
hardAnswer
- Rotate the Q and K vectors in each 2D subspace of the head dimension by an angle proportional to the position: , , with ^(2i/d).
- Because of the rotation identity, · depends only on the difference — encodes relative position multiplicatively.
- Extrapolates well (with NTK / linear scaling tweaks), used in LLaMA, Mistral, Falcon, Qwen, GPT-NeoX, most modern open LLMs.
Check yourself — multiple choice
- Add to embeddings
- Rotate Q, K per position by ^(2i/d) — inner product depends only on (i - j); standard in modern LLMs
- RoPE is deprecated
- Same as ALiBi
RoPE: 2D rotations of Q, K → dot product depends on relative position.
#positional-encoding#transformers
Practise Deep Learning
214 interview questions in this topic.