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.

Google
Machine Learning
Machine Learning Engineer
Google
November 29, 2026
Machine Learning Engineer
Onsite
Machine Learning
Hard

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
Rotary position embeddings
Relative position
Context extension
Position interpolation
Long-context evaluation
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. 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 Prep
Sample Answer
Clarify

RoPE applies to queries and keys inside every attention layer. Dimension pairs (x2i,x2i+1)(x_{2i}, x_{2i+1}) are rotated by angle mθim\theta_i at position mm, with θi=b−2i/d\theta_i = b^{-2i/d} and base b=10000b = 10000. ...

Approach

Treat each pair as a complex number ziz_i. RoPE maps q↦qieimθiq \mapsto q_i e^{\mathrm{i} m \theta_i} and k↦kieinθik \mapsto k_i e^{\mathrm{i} n \theta_i}. The real part of qkˉq \bar{k} summed over pairs is $\sum_i ...


Submit Your Answer
Markdown supported