4.1.7 · D5Transformer Architecture

Question bank — Rotary positional embeddings (RoPE)

2,174 words10 min readBack to topic

Before we start, we earn every symbol this page leans on, so no reveal line uses anything cold.

Figure — Rotary positional embeddings (RoPE)
Figure — Rotary positional embeddings (RoPE)

True or false — justify

RoPE adds a position vector to the token embedding.
False. Vanilla sinusoidal encoding adds; RoPE rotates the query and key vectors instead, so position never contaminates the raw content by addition.
Rotating a vector changes its length.
False. is orthogonal (), so it preserves length — it only swings the direction. This is exactly why a token's "size" (norm) survives RoPE untouched.
RoPE rotates queries, keys, and values.
False. Only queries and keys are rotated. Values carry content to be aggregated; rotating them would twist the payload, not just steer the attention weights.
Two token pairs with the same gap but different absolute positions get the same relative angle contribution.
True. The dot product collapses to , which depends only on the difference , so absolute placement drops out.
RoPE spins the whole -dimensional vector by one single angle.
False. It splits into independent pairs and spins each pair by its own frequency , giving a spread of fast and slow rotations.
can be any positive integer, even or odd.
False. (the head dimension ) must be even, because rotation acts on 2D planes and the coordinates are paired as ; an odd would leave one coordinate with no partner to rotate against.
Lower embedding dimensions in RoPE use lower frequencies.
False. Lower dimensions (small ) use higher frequencies (fast rotation, fine local detail); higher dimensions (large ) use lower frequencies (slow rotation, long-range structure).
Because rotation angles wrap every , RoPE can process sequences longer than it was trained on.
Only partly. Attention reads relative gaps, and a gap seen in training keeps the same angle at any absolute position — so short gaps extrapolate cleanly. But it is not free: each frequency has its own wrap period , the slow high- pairs sweep angles at very long range that were never seen during training, so extrapolation degrades there — the qualification in Length Extrapolation in LLMs.
RoPE requires an explicit learned bias term per relative distance.
False. That is Relative Position Bias (T5). RoPE bakes relative position into the geometry of the dot product — no extra learned parameters.
Each attention head must share the same RoPE rotation.
False. In Multi-Head Attention each head applies RoPE to its own , so heads can specialise to different position scales independently.
RoPE modifies the softmax step of attention.
False. It modifies the score inside the Attention Mechanism before softmax; the softmax and value aggregation are unchanged.

Spot the error

", so the score depends on ."
Wrong sign. The transpose reverses the first spin, , so , giving the difference , not the sum — that difference is the entire point.
"Since values also flow through attention, we should rotate too for consistency."
Error. Attention ; position belongs in which tokens to fetch (), not in what content () gets fetched. Rotating would corrupt the payload.
"Higher dimensions need higher precision, so give them higher frequencies."
Error. Higher frequency = faster spin = fine short-range detail. Long-range structure needs slow spin (low frequency), which is precisely why high dimensions get shrinking toward zero.
"We should rotate individual coordinates separately."
Error. Rotation lives in a 2D plane, so you must pair coordinates: spin together, together. A lone number cannot be "rotated" — this is also why must be even.
"RoPE removes the need to normalise by ."
Error. The scaling controls dot-product magnitude and is independent of position. RoPE leaves it in place.
"Because position 2000 was never trained, RoPE fails on it just like learned embeddings."
Error. Learned embeddings fail because absolute slot 2000 has no learned vector; RoPE has no per-position parameters — it computes the angle, and attention only reads the relative gap, which was trained.

Why questions

Why rotation specifically, and not addition, scaling, or a learned lookup?
Because the dot product of two rotated vectors depends only on the angle difference (). No other cheap operation makes relative position "fall out" of the attention score for free.
Why must the two rotation angles cancel into a difference rather than pile up?
The transpose in reverses the first rotation into ; composing rotations adds turns, so the reversed against the forward leaves — absolute offsets cancel and only the gap survives.
Why use many frequencies instead of one?
A single frequency aliases: two positions apart give the identical angle, so that pair alone cannot tell them apart. Stacking different frequencies means the full set of angles almost never collides at once — the pair that aliases for one distance stays distinct in every other pair.
Why leave the values un-rotated even though position matters?
Position should steer attention weights, not distort the information being summed. is the information; spinning it would answer "where" by damaging "what."
Why does the schedule borrow from sinusoidal encodings?
It reuses a geometric spread of wavelengths from short to very long, giving a smooth ladder of scales — a proven way to cover many distances without gaps.
Why does RoPE differ from ALiBi (Attention with Linear Biases)?
ALiBi adds a fixed penalty straight onto each attention score (closer tokens get less penalty, farther more), a purely additive bias with no rotation. RoPE instead rotates and so relative distance emerges from the dot-product geometry — same goal, different mechanism.

Edge cases

What rotation does position apply?
The identity — leaves the vector exactly as-is, so the first token carries no rotation, only pure content.
What is the relative angle when (a token attending to itself)?
Zero. , so self-attention scores feel no position twist at all — as they should, since the gap is zero.
If the gap is negative (query after key), does RoPE still work?
Yes. is just a rotation by a negative angle (spin the other way); the geometry is symmetric and well-defined for any signed gap.
What happens to a coordinate whose partner in the pair is zero, e.g. , rotated at position in pair (angle )?
It still rotates normally: writing the rotation angle , the pair becomes . A zero component is a valid starting point, not a degenerate case — the pair simply starts on an axis.
What if two positions differ by exactly a multiple of for some pair?
That pair's rotation aliases to the same angle, so it cannot distinguish those two distances — but the other frequencies still differ, so the full vector keeps them apart. This is why multiple frequencies matter.
Does a very high frequency cause the first pair to "wrap" many times over a long sequence?
Yes, and that is intended. Fast wrapping still yields consistent relative angle differences for a given gap, so training on those gaps transfers to long sequences — the basis of RoPE extrapolation.
For very high , — what practical danger appears?
The rotation becomes tiny, so those pairs barely turn even across a long sequence. Two far-apart positions then produce almost-identical angles there, and in finite floating-point precision the difference can round away, weakening long-range discrimination in exactly the pairs meant to handle it.
Recall One-line summary

RoPE spins and by absolute angles so the dot product feels only the relative gap (); values and stay fixed, must be even, and multiple frequencies defeat single-frequency aliasing.