Positional extrapolation and scaling tests
Separate algebraic position encodings and scaling rules from empirically demonstrated long-distance use and short-context retention.
On this page
The question for today
What you’ll understand
- Derive the relative-phase identity for a rotary coordinate pair.
- Explain positional interpolation without claiming universal length extrapolation.
- Design length, position, and short-context controls for a scaling experiment.
A positional encoding can be evaluated at a large index even when the trained model cannot use that position reliably. Configuring a larger maximum sequence length therefore establishes neither retrieval accuracy nor reasoning over distant evidence. RoFormer supplies the rotary algebra, Position Interpolation rescales indices, and YaRN studies a richer extension recipe. Their empirical results have model, training, and task conditions; none is a universal guarantee for arbitrary longer inputs.
Rotary algebra does not prove semantic generalization
RoPE rotates paired query and key coordinates by position-dependent angles. Within one pair and one frequency, the query-key dot product depends on the difference between their positions. That identity explains a relative-position mechanism; it does not show that learned content interactions remain useful outside the training distribution. Individual coordinate-pair contributions oscillate and need not decrease monotonically with distance. Aggregate claims about decay or generalization require their stated assumptions rather than being inferred from one cosine component.
Identify the checkpoint’s original position convention, tokenizer, training lengths, and implementation before altering it. Query and key rotation, cached-key representation, and serving configuration must agree. A scale change applied inconsistently during cached decoding can introduce an implementation bug distinct from a model’s extrapolation weakness. Reproduce a small uncached versus cached comparison where possible, then test beyond the original range. Equal tensor shapes and a successful forward call are compatibility checks, not evidence that distant facts were actually used.
Scaling changes the position distribution
Uniform Position Interpolation maps a longer index range into the original range. It compresses relative distances in the positional coordinates rather than deleting tokens. The model still receives the longer sequence, with its memory and attention costs, and may need adaptation to distinguish newly compressed positions. YaRN modifies aspects of frequency-dependent scaling and attention scaling rather than being equivalent to every uniform index division. Pin the exact method and configuration when attributing a result to a position-extension recipe.
Compare a scaling-only run, an adapted model, and the original checkpoint where the inputs are legal. Keep training token budget, data mixture, and evaluation protocol visible; a stronger result after more training is not isolated evidence for one positional formula. Also test the original short lengths because scaling can alter behavior there. Report task quality by evidence position and separation as well as sequence length. A successful single-needle retrieval run does not establish multi-hop reasoning, summarization fidelity, or robust performance on every language.
Test the useful context rather than the accepted input
Construct fresh examples with controlled evidence location, distractors, and dependency distance, using the actual tokenizer to verify placement. Include tasks requiring several separated facts and checks for unsupported inference, not only copying an exact key. Keep held-out source documents and generated templates separate from adaptation data. Repeatedly tuning against one visible synthetic needle can overfit a narrow format. A credible extension claim names the tested length range, workloads, prompt policy, and uncertainty instead of treating the configured maximum as the measured capability.
The vector lab illustrates one rotary phase only. Reset, set angle to 120 degrees and magnitude to 1, predict the horizontal projection, then Step: negative one half. Compare a fresh Reset with both angle at 30 degrees and magnitude at 1 before Step: approximately 0.8660. Dividing this phase by four resembles one uniform scaling operation, but the instrument has no multiple RoPE frequencies, learned attention, cached keys, training, or long-context task evaluation.
Work it through
A position map and one illustrative phase
Use uniform interpolation from an original 4,096-token range to a 16,384-token range. Map position 12,000 and a separation of 256 tokens. For a separate single rotary pair, assume angular frequency π/512 radians per token and fixed q = k = (1,0).
The scale is 16,384/4,096 = 4. Position 12,000 maps to 3,000, and the 256-token separation maps to 64 positional units.
The original pair phase is 256 × π/512 = π/2, giving dot product cos(π/2) = 0 under the fixed-vector assumption.
The interpolated pair phase is 64 × π/512 = π/8, giving approximately 0.9239. This changed algebraic contribution does not establish a better full-model attention score or successful reasoning at position 12,000.
Scaling has a precise positional effect while its semantic consequences require controlled empirical tests.
The living notebook
Explore the model
Interactive lab · vectors
One phase projection without a language model
Reset, set θ = 120° and r = 1, predict x, then Step: x = −0.5. Compare a fresh Reset with both θ = 30° and r = 1 before Step: x ≈ 0.8660. This single two-dimensional phase analogy contains no learned RoPE attention, positional adaptation, or context-quality test.
- x component
- 1.393
- y component
- 0.975
- Magnitude
- 1.7
Playback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA changed phase can be computed exactly without proving useful extrapolation.
Pause & reason
Check your understanding
Your turn
Try it yourself
Under uniform interpolation from 2,048 to 8,192 tokens, map position 6,000 and separation 100. Name two controls needed before claiming useful long-context improvement.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The ratio of target to original length is four; separate the arithmetic from the evaluation claim.
Compare with the solution
Position 6,000 maps to 1,500 and separation 100 maps to 25 positional units. Test matched evidence at several locations and distances, and check short-context behavior under the same prompt, tokenizer, and checkpoint conditions. Training-data leakage, adaptation budget, and cached-versus-uncached implementation consistency also need controls; the index mapping alone establishes none of those outcomes.
Keep the idea
Take it with you
- Relative rotary algebra and semantic extrapolation are different claims.
- Position-extension recipes change specific distributions and need exact configuration records.
- Effective context requires held-out tests across lengths, positions, tasks, and short-context controls.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.