Explain Rotary Position Embeddings and Extending Them to Longer Contexts
Last updated: November 29, 2026
Quick Overview
Explain how rotary position embeddings encode position, prove the attention score depends only on relative offset, and discuss how to extend a model trained at 8k tokens to a much longer context.
0
0
0 solved
Explain how rotary position embeddings encode position, prove the attention score depends only on relative offset, and discuss how to extend a model trained at 8k tokens to a much longer context.
Long context is a headline capability for Gemini, so Google research and modeling interviews dig into positional encodings beyond the textbook sinusoid. The interviewer checks the math of the rotation, the relative-position property, and practical knowledge of why naive extrapolation fails and what interpolation methods do.
What the Interviewer Expects
- Describes rotating pairs of query and key dimensions by position-dependent angles
- Shows the dot product depends only on position difference
- Explains the frequency spectrum and which dimensions encode long range
- Explains why extrapolating past the training length fails
- Compares position interpolation, NTK-aware base scaling, and similar methods
- Mentions that some fine-tuning at the longer length is still needed
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Why is RoPE applied to queries and keys but not values?
- How does ALiBi differ, and what are its trade-offs?
- How would you evaluate whether long-context extension actually works beyond perplexity?
- What does attention entropy do as context grows, and why might you scale logits?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
RoPE applies to queries and keys inside every attention layer. Dimension pairs are rotated by angle at position , with and base . ...
Approach
Treat each pair as a complex number . RoPE maps and . The real part of summed over pairs is $\sum_i ...