Positional Encoding · June 2023
Position Interpolation
intermediate
long-contextinference-only
Extend a pretrained RoPE model's context by simply *squishing* the position values into the originally-trained range. The 2023 technique that opened the RoPE-extension research line that YaRN and LongRoPE later refined.
§ 1 · Premise
Extrapolation kills attention long before training data does
A pretrained LLaMA at context length has only ever seen RoPE rotation angles for and dimension index . At inference, ask it to process token at position and the slowest dimension ( rad/pos for , ) sees an angle rad — four times anything it observed in training. Chen et al. 2023, Table 1 report that an unmodified LLaMA-7B drops from perplexity 5.5 at 2K to > at 8K and diverges past 16K; the perplexity cliff arrives at almost exactly regardless of content. The failure is not graceful degradation; it is the model encountering a phase it has never seen and producing garbage from layer 1 onward.
Naive extrapolation fails because the model never developed a representation for rotation angles past its training window. The slow dimensions in particular were used to encode “global position in the document”; the model learned a sharp prior on what those rotations look like, and out-of-distribution rotations land in regions that map to garbage logits. The empirical signature — perplexity stays flat up to , then explodes by orders of magnitude within a few hundred positions — is the calling card of distribution-shift failure rather than gradual capacity exhaustion.
Two cheap fixes had been proposed before PI. Position rescaling the base (“just train longer with bigger ”) works but needs full retraining from scratch. Removing positional encoding entirely (NoPE) works only for models trained that way; it cannot be retrofitted onto an existing RoPE checkpoint. A third option, ALiBi (Press et al. 2022, arXiv 2108.12409), extrapolates gracefully by design but again requires the model to have been pretrained with the ALiBi bias. None of these helps the practitioner who has a pretrained RoPE checkpoint and 1000 GPU-hours.
PI’s contribution: a one-line change to the RoPE rotation formula that lets a 1000-step fine-tune extend the context to . The change introduces no new parameters and no architectural surgery. PI is now superseded for production deployments by YaRN and scaled-base RoPE, but it is the prototype that opened the line.
§ 2 · Derivation
Squish positions into the trained range
Prerequisite. RoPE rotates each coordinate pair of and by the angle , with . The attention inner product depends only on the relative offset via . See the RoPE entry for the rotation identity; the rest of this section focuses on what changes when you want positions past .
Step 1: identify the in-distribution constraint. Let be the training context length and the desired extension length, with extension factor . The training distribution of angles seen by dimension is the set . The model behaves well on any angle in this set, badly on angles outside it. The simplest reformulation is: find a position-to-angle map on the extended range whose range lies within the trained set.
Step 2: the interpolation. Replace the absolute position with the interpolated position in the RoPE angle:
For the scaled position lies in — exactly the training domain. No angle extrapolates. Equivalently, leave positions unchanged and divide every rotation rate by : the two formulations produce bitwise-identical attention outputs (Chen et al. 2023, §3.1).
Step 3: relative-offset structure survives. Substituting into the RoPE inner-product identity, the attention logit between PI-extended positions and becomes
The dependence is still on a relative offset , scaled by . The model sees the same attention geometry it learned, just compressed along the position axis.
Step 4: the resolution cost. Substituting (a extension) into the adjacent-position rotation of the fastest dimension (, rad/pos):
The fast dimension used to rotate by 1 radian between adjacent tokens — enough phase shift that the model could cleanly distinguish from . After PI, that phase shift is 4× smaller. Two adjacent positions now look more alike than the model expects. The slow dimensions are unaffected in any meaningful sense because their adjacent-token phase shift was already tiny.
To make the asymmetry concrete, at :
- : rad/pos; adjacent-token shift drops from to rad ( resolution loss on the band the model used to discriminate neighbors).
- : rad/pos; adjacent-token shift drops from to rad (resolution loss on a band that was already in a “few-tokens-per-radian” regime).
- : rad/pos; adjacent-token shift drops by the same factor of 4, but the absolute shift was already four orders of magnitude below the model’s discrimination threshold — invisible.
The asymmetry — fast dimensions losing real resolution, slow dimensions losing nothing — is the central limitation. NTK-aware RoPE and YaRN both descend from this observation and address it by not rescaling the fast dimensions.
Parameter and compute cost. Zero new parameters. Compute cost: one extra division per RoPE angle, per layer per forward pass. The full extension typically uses a -step fine-tune on long-context data to let the model adapt to the new per-position phase budget; this is the dominant cost, not the inference-time rescale (Chen et al. 2023, §3.2).
§ 3 · Reference implementation
Sketch
def position_interpolation_rope(x, position, theta, scale):
# x: [..., d_h] per-head Q or K input vector
# position: scalar or [T] absolute token positions
# theta: [d_h/2] RoPE rotation rates b^(-2i/d_h)
# scale: extension factor s = L_new / L_train (e.g., 4.0 for 2K -> 8K)
angles = (position / scale) * theta # PI: divide positions by s
cos, sin = angles.cos(), angles.sin()
x1, x2 = x[..., 0::2], x[..., 1::2]
return torch.stack([x1 * cos - x2 * sin, x1 * sin + x2 * cos], dim=-1).flatten(-2)
Two implementation notes. First, scaling positions and scaling are bitwise
equivalent — most production stacks instead precompute theta_scaled = theta / scale once
and keep the standard RoPE inner loop. Second, when extending from a checkpoint, the fine-tune
must use the same scale at training time as inference uses; mixing scales produces a model
that has not seen its inference-time angles.
§ 4 · Empirical evidence
What the original and follow-up ablations show
Headline result. Chen et al. 2023 (Table 4) extend LLaMA-7B / 13B / 33B / 65B from 2K to 32K context via PI plus a 1000-step fine-tune on the Pile. Validation perplexity at the new length matches the 2K baseline within 0.3 nats for all four model sizes — the technique works, and works cheaply. The fine-tune is the load-bearing step; without it, the model adapts only partially to the compressed phases and perplexity stays 1-2 points above the baseline (Chen et al. §4.2).
Fine-tune budget sensitivity. Chen et al. 2023 (Figure 4) sweep the fine-tune length from 0 to 10000 steps at on LLaMA-7B. Perplexity drops sharply over the first ~200 steps (from to ), reaches the 2K baseline by ~1000 steps, and plateaus thereafter. The interpretation: PI’s rescale leaves the model close enough to its trained distribution that a few hundred optimizer steps suffice to absorb the residual distribution shift; longer fine-tuning produces diminishing returns.
Passkey retrieval. Table 6 of the PI paper reports passkey retrieval accuracy of extended LLaMA-13B between 99% and 100% across context lengths from 8K to 32K, with the passkey planted at varying depths. The result is the empirical case that some useful positional resolution survives the PI rescale, even at extension.
Where PI loses, per the YaRN comparison. Peng et al. 2023 (YaRN, arXiv 2309.00071, Table 1) re-run PI and report it trailing YaRN by ~0.5 perplexity points at extension on PG-19 and Proof-Pile. The gap widens as the extension factor grows — at extension on Proof-Pile (Peng et al. Table 3), PI is 1.5 perplexity points behind YaRN. The interpretation in both papers: PI’s uniform-across-bands rescale is exactly the failure mode that NTK-aware and YaRN address by leaving the fast bands alone.
Independent reproductions. The Hugging Face long-context evaluation harness includes a PI baseline for LLaMA-2-7B extended to 16K and 32K; published runs match the Chen et al. perplexity numbers within 0.1 nats and confirm the fast-band acuity regression on a character-level retrieval probe. No public study has reported PI matching or beating YaRN at extensions beyond ; the consensus across follow-ups (NTK-aware, YaRN, LongRoPE, scaled-base RoPE) is that PI is correct in spirit but suboptimal in its uniform-band rescale.
Effect on short-context tasks. A predicted failure mode of PI: by reducing every band’s adjacent-token phase shift by , the model should also lose acuity on tasks shorter than its original training length. Peng et al. 2023 (Table 5) measure this on the LM Eval Harness suite for PI-extended LLaMA-2-7B at . Hellaswag drops 0.5 points, ARC-Challenge drops 0.3 points, MMLU drops 0.2 points — all within standard noise but trending the predicted direction. The same paper reports YaRN preserves short-context performance to within 0.1 points across the suite, attributable to YaRN leaving the fast bands untouched.
Where the line goes from here. NTK-aware RoPE keeps the fast bands intact by rescaling the base instead. YaRN combines NTK-aware’s idea with a three-band smooth ramp and a softmax-temperature correction. LongRoPE drops closed-form schedules entirely and searches the per-dimension space. All three trace their derivation back to PI’s first move: change , not the model. The production lineage similarly inherited PI’s strategic move even when picking different mechanics — Llama-3.1’s scaled-base RoPE (Meta AI 2024, arXiv 2407.21783, §3.2) is morally a NTK-aware variant with continued pretraining; DeepSeek-V2/V3 use YaRN explicitly (Liu et al. 2024). No production decoder ships pure PI in 2025, but every one of them runs the descendant of PI’s “rescale the angles, don’t change the model” recipe.
Lineage
- Predecessors
- Rotary Position EmbeddingRoPE
Cite
BibTeX entry for the original paper
@article{arxiv2306_15595,
title = {Extending Context Window of Large Language Models via Positional Interpolation},
author = {Shouyuan Chen, Sherman Wong, Liangjian Chen, Yuandong Tian (Meta AI)},
year = {2023},
eprint = {2306.15595},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2306.15595}
} Or cite the paper directly: arXiv:2306.15595.
Export
BibTeX
@article{arxiv_2306_15595,
title = {Extending Context Window of Large Language Models via Positional Interpolation},
author = {Shouyuan Chen and Sherman Wong and Liangjian Chen and Yuandong Tian (Meta AI)},
year = {2023},
eprint = {2306.15595},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2306.15595}
} CSL JSON
{
"id": "arxiv_2306_15595",
"type": "article-journal",
"title": "Extending Context Window of Large Language Models via Positional Interpolation",
"author": [
{
"literal": "Shouyuan Chen"
},
{
"literal": "Sherman Wong"
},
{
"literal": "Liangjian Chen"
},
{
"literal": "Yuandong Tian (Meta AI)"
}
],
"issued": {
"date-parts": [
[
2023
]
]
},
"URL": "https://arxiv.org/abs/2306.15595",
"number": "2306.15595",
"source": "arXiv"
} RIS
TY - JOUR
TI - Extending Context Window of Large Language Models via Positional Interpolation
AU - Shouyuan Chen
AU - Sherman Wong
AU - Liangjian Chen
AU - Yuandong Tian (Meta AI)
PY - 2023
JO - arXiv
AN - arXiv:2306.15595
UR - https://arxiv.org/abs/2306.15595
ER -