Position Interpolation › A Worked Example
Language AI HandbookAll chapters Position Interpolation › A Worked ExampleOne section · Sections in this chapter4 / 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 writing code, let's work through a concrete numerical example to solidify the concept. This will make the subsequent implementation much easier to follow.
Suppose we have a model with (two dimension pairs, which is unrealistically small but easy to trace), , trained on sequences up to positions. We now want to process a sequence of positions.
The scale factor is:
The base frequencies for our two dimension pairs ( and with ) are:
Now consider position in the extended sequence. Under standard RoPE (no interpolation), the rotation angles would be:
- Dimension pair 0: radians
- Dimension pair 1: radians
The training maximum (at position 7) was:
- Dimension pair 0: radians
- Dimension pair 1: radians
Position 12 exceeds the training maximum for both dimension pairs. The fast-rotating dimension pair 0 is especially far outside the training range (12.0 vs 7.0 radians).
Under Position Interpolation, we scale the position first: . The rotation angles become:
- Dimension pair 0: radians (within training max of 7.0)
- Dimension pair 1: radians (within training max of 0.07)
Both angles now fall within the range the model saw during training. The model can apply its learned interpretation of these rotation patterns to process what is effectively a mid-sequence position. The trade-off is that position 12 in the extended sequence "feels like" position 6 in the original sequence, meaning the model perceives it as occupying roughly the middle of the context rather than three-quarters of the way through. Fine-tuning corrects this calibration.
