Position Interpolation › The Extrapolation Problem

Michael BrenndoerferUpdated July 6, 20258 min read
Language AI HandbookAll chapters
Part 18 of 67Long Context
Chapter 127Position Interpolation › The Extrapolation Problem
Reading section 2 of 12 · The Extrapolation Problem · 8 minSection 2 of 12 · 8 min

Book contents

Section 2 of 12 · 8 min read

Position Interpolation › The Extrapolation ProblemOne section · Sections in this chapter2 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Before we can appreciate the solution, we need to understand the failure mode in precise terms. The extrapolation problem is not just that "big numbers are bad." It arises from a specific mismatch between what the model learned and what it is asked to do, and the details of that mismatch matter for understanding why Position Interpolation works.

RoPE encodes position through rotation. At position mm, each dimension pair of the query and key vectors is rotated by an angle proportional to mm. The key idea is that each dimension pair rotates at a different frequency, creating a unique positional signature. Think of it as a clock with many hands, each ticking at a different speed. The pattern formed by the positions of all the hands at a given moment encodes the current "time" (position). Two different positions will have two different hand configurations. The rotation angle for dimension pair ii at position mm is computed as:

θi(m)=m⋅θi=m⋅1base2i/d\theta_i(m) = m \cdot \theta_i = m \cdot \frac{1}{\text{base}^{2i/d}}

where:

  • θi(m)\theta_i(m): the rotation angle (in radians) applied to dimension pair ii at sequence position mm
  • mm: the position index in the sequence (0, 1, 2, ..., L−1L-1 for a sequence of length LL)
  • ii: the dimension pair index (0, 1, 2, ..., d/2−1d/2 - 1)
  • dd: the total embedding dimension (typically 64, 128, or larger)
  • base\text{base}: a constant that controls the range of frequencies (typically 10000)
  • θi=1/base2i/d\theta_i = 1/\text{base}^{2i/d}: the base frequency for dimension pair ii, which decreases exponentially as ii increases

The exponential decay in the base frequency θi\theta_i means that dimension pair 0 rotates fastest (with θ0=1\theta_0 = 1 radian per position), while higher-indexed pairs rotate progressively slower. This creates a multi-scale representation where different dimension pairs capture positional information at different granularities. The fastest dimension pairs complete a full rotation every few positions, making them sensitive to fine-grained local position distinctions. The slowest dimension pairs complete a rotation only after tens of thousands of positions, making them sensitive to coarse global structure. Together, they form a rich positional encoding that the transformer can read like a coordinate system.

Notice that the angular resolution of this coordinate system is calibrated to the training sequence length. The frequencies were chosen (using the base of 10,000) so that the full spectrum of rotation patterns fits comfortably within the context window. When you push beyond that window, you are not just asking the model to handle new numbers. You are asking it to interpret rotation patterns that were never part of the coordinate system it was trained to read.

Out[3]:
Visualization
Line plot showing wavelength in positions on a log scale across 32 dimension pairs, rising exponentially from left to right.
RoPE wavelengths across dimension pairs. The wavelength (positions per full rotation) increases exponentially from about 6 positions for pair 0 to over 60,000 positions for pair 31. This multi-scale structure allows RoPE to encode both local and global positional information.

During training on sequences of length LL, the model sees positions 0,1,2,…,L−10, 1, 2, \ldots, L-1. The rotation angles range from 0 to (L−1)⋅θi(L-1) \cdot \theta_i for each dimension pair. Every pattern the model has learned to interpret lies somewhere in this bounded space.

What happens when we present the model with position 2L2L? The rotation angle 2L⋅θi2L \cdot \theta_i exceeds anything seen during training. For the fastest-rotating dimensions (where θi\theta_i is large), these new angles produce embedding rotations the attention mechanism has never learned to interpret. In practice, this means that when a token at position 3,000 tries to attend to a token at position 100, the relative rotation computed from those positions falls entirely outside what the model learned during training. The attention score becomes meaningless, not because the model cannot compute a number, but because the number it computes carries no learned meaning.

Let's visualize this problem by examining the rotation angles at different positions.

In[4]:
Code
import numpy as np


def compute_rope_angles(positions, d_model=64, base=10000):
    """Compute RoPE rotation angles for given positions.

    Args:
        positions: Array of position indices
        d_model: Embedding dimension
        base: Base for frequency computation

    Returns:
        angles: Array of shape (len(positions), d_model/2)
    """
    # Compute frequencies for each dimension pair
    dim_pairs = d_model // 2
    i = np.arange(dim_pairs)
    theta = 1.0 / (base ** (2 * i / d_model))

    # Compute angles: outer product of positions and frequencies
    positions = np.array(positions)
    angles = np.outer(positions, theta)

    return angles


# Training range: positions 0 to 2047 (2K context)
train_length = 2048
train_positions = np.arange(train_length)
train_angles = compute_rope_angles(train_positions)

# Extended range: positions 0 to 8191 (4x context)
extended_length = 8192
extended_positions = np.arange(extended_length)
extended_angles = compute_rope_angles(extended_positions)

# Find maximum angles seen during training vs extension
max_train_angles = train_angles[-1]  # Angles at position 2047
max_extended_angles = extended_angles[-1]  # Angles at position 8191
Out[5]:
Console
Maximum rotation angles by dimension pair (radians):
--------------------------------------------------
Pair   Training (pos 2047)    Extended (pos 8191)   
--------------------------------------------------
0      2047.00                8191.00               
1      1535.03                6142.38               
2      1151.11                4606.14               
3      863.21                 3454.12               
31     0.27                   1.09

For the fastest-rotating dimension pair (pair 0), the model sees angles up to about 2,047 radians during training. Extending to 4x the context pushes this to over 8,000 radians. While both values wrap around the unit circle many times, the relative patterns between dimension pairs change in ways the model hasn't learned.

The real problem becomes clear when we examine what happens to attention patterns. During training, the model learns that certain rotation angle combinations correspond to meaningful relative positions. When extrapolated angles produce unfamiliar combinations, the learned attention patterns break down.

Out[6]:
Visualization
Line plot showing rotation angles across 32 dimension pairs for positions 512, 2047, and 8191. Higher positions show dramatically larger angles for low-index dimension pairs.
Rotation angles across dimension pairs at different positions. During training (blue, orange), the model sees angles within a bounded range. Extrapolating to 4x the training length (green) produces angles far outside this range for fast-rotating dimensions, while slow-rotating dimensions barely change. This imbalance disrupts the learned attention patterns.

The plot reveals the core issue. Fast-rotating dimensions (low indices) experience dramatic angle increases during extrapolation. The angle at position 8191 for dimension pair 0 is four times larger than at position 2047. Meanwhile, slow-rotating dimensions (high indices) barely change. This asymmetric behavior disrupts the carefully balanced patterns the model learned during training.

The asymmetry matters for an important reason. The fast-rotating dimensions are responsible for distinguishing nearby positions, the very cases where the model most needs accurate positional information. When a model must determine whether a pronoun refers to the noun in the immediately preceding clause versus the one three sentences earlier, it relies on high-frequency positional signals. Those are exactly the signals that break under extrapolation. The slow-rotating dimensions, which encode coarse global position, remain more stable but are not sufficient on their own.