YaRN › Worked Example: Tracing a Dimension Pair
Language AI HandbookAll chapters YaRN › Worked Example: Tracing a Dimension PairOne section · Sections in this chapter9 / 16 ↓
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
Let's trace YaRN's computation for a specific dimension pair to make the mathematics concrete. We'll work through a 4x extension from context length 2,048 to 8,192 with a 64-dimensional model.
Consider dimension pair (the 11th pair out of 32 total). We'll compute everything step by step.
Step 1: Compute the original frequency.
The base frequency formula gives:
Computing numerically: , so .
Step 2: Compute the wavelength.
The wavelength is:
So one complete rotation of dimension pair 10 takes about 112 positions.
Step 3: Compute the wavelength ratio.
With original context :
Since , dimension pair 10 falls in the "no interpolation" region. The model completes about 18 full rotations () during the training context, so it has learned all possible rotation states.
Step 4: Apply the ramp function.
Since , we have . The adjusted frequency is:
Dimension pair 10 is unchanged: it rotates at its original speed.
Now let's examine dimension pair (near the low-frequency end).
Step 1: Compute the original frequency.
Step 2: Compute the wavelength.
One full rotation of dimension pair 28 takes over 35,000 positions.
Step 3: Compute the wavelength ratio.
Since , dimension pair 28 falls in the ramp (transition) region.
Step 4: Apply the ramp function.
The linear weight is:
The interpolation factor is:
The adjusted frequency is:
Dimension pair 28 is slowed down to about 61% of its original speed. With the extended context of 8,192 positions, a token at position 8,192 would produce a rotation angle of radians, which corresponds to about 14% of a full rotation. The model has learned rotation states up to about radians in the original training, so 0.884 radians is outside the training distribution. The gamma correction reduces this to radians... wait, let's check with the corrected frequency: radians. Pair 28 still extrapolates somewhat (since we applied only partial interpolation), which is intentional. Full interpolation would be too conservative; partial interpolation strikes a balance between accessing new context and staying close to the training distribution.
Step 5: Temperature correction.
For :
The attention score multiplier is . Every pre-softmax attention score is multiplied by this factor before the softmax is applied.
This worked example shows the key principle: YaRN applies a per-dimension decision based on physical intuition (how much of the rotation cycle has been trained), rather than a global formula that treats all dimensions identically.