Explain RoPE. What's the rotation intuition and why did it become the default?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Rotary Position Embedding injects position by rotating the query and key vectors rather than adding anything to embeddings. Pair up the dimensions of each head (dim 0-1, 2-3, ...) and treat each pair as a 2D vector; for a token at position m, rotate pair i by angle m·θ_i, where θ_i = 10000^(−2i/d) gives geometrically spaced frequencies - fast-spinning pairs encode fine/local position, slow-spinning pairs encode coarse/long-range position.
Full worked answer with diagram
Rotary Position Embedding injects position by rotating the query and key vectors rather than adding anything to embeddings. Pair up the dimensions of each head (dim 0-1, 2-3, ...) and treat each pair as a 2D vector; for a token at position m, rotate pair i by angle m·θ_i, where θ_i = 10000^(−2i/d) gives geometrically spaced frequencies - fast-spinning pairs encode fine/local position, slow-spinning pairs encode coarse/long-range position.
The payoff is what happens in the dot product. Rotations preserve norms, and the angle between a query rotated by m·θ and a key rotated by n·θ changes by exactly (m−n)·θ. So the attention score between positions m and n depends only on their relative offset m − n (and the content vectors) - relative position encoding, achieved multiplicatively, with zero learned parameters, applied only to Q and K (V is left alone; the output carries no positional contamination). The clock-hands intuition: each dimension pair is a clock hand spinning at its own rate as position advances; attention compares the difference in clock readings between two tokens.
Why it won (Llama, Qwen, Mistral, most modern open models - and it's the assumption behind most long-context tooling):
- Relative position matches what language needs, without the extra attention terms older relative-position schemes (T5 bias, Shaw et al.) required.
- No parameters, no position-table length cap; compatible with KV caching (each token's K is rotated once by its absolute position, then cached - relative behaviour emerges in the dot product).
- Decaying inter-token dependency with distance falls out naturally at standard frequency settings.
- Crucially, it turned out to be extensible: because position lives in rotation angles, context extension becomes frequency surgery - position interpolation, NTK-aware scaling, and YaRN all work by rescaling θ or positions, which is far cleaner than retrofitting an embedding table.
Limitation: vanilla RoPE still degrades sharply past trained length - unseen angle ranges are out-of-distribution - which is exactly what the extension methods address.
Worth sketching. The two rotations meeting at one dot product is the whole proof sketch in a picture.
flowchart LR
QM["q at position m"] --> RM["rotate each dim pair by m x theta_i"]
KN["k at position n"] --> RN["rotate each dim pair by n x theta_i"]
RM --> DOT["dot product"]
RN --> DOT
DOT --> REL["angle difference is (m - n) x theta_i:<br/>score depends only on the offset"]
V["v"] --> UNT["untouched, so the output<br/>carries no positional contamination"]
REL --> EXT["extension becomes frequency surgery:<br/>rescale theta or rescale positions"]
What a good answer covers
- Rotary Position Embedding injects position by rotating the query and key vectors rather than adding…
- Pair up the dimensions of each head (dim 0-1, 2-3, ...) and treat each pair as a 2D vector; for a token…
- The payoff is what happens in the dot product
- Rotations preserve norms, and the angle between a query rotated by m·θ and a key rotated by n·θ changes…
- So the attention score between positions m and n depends only on their relative offset m − n (and the…
Key terms: rotating · relative offset m − n · extensible
In the glossary: Attention · Contamination · Position interpolation · YaRN · RoPE
Interviewer follow-ups to expect
Prove that the score depends only on m−n for a single 2D pair. Why is RoPE applied to Q and K but not V?
How do position interpolation and YaRN manipulate RoPE's frequencies?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep