Md. Asif Uddin

Proposition 327 of 39 in the corpus

Rotary encoding turns position into an angle, so the absolute indices cancel.

Rotating the query and the key by angles proportional to their positions leaves an inner product that depends only on the difference between them. Relative position falls out of the algebra rather than being added on.

Depends on

Rotary position embeddingA circle with three vectors drawn at angles proportional to their positions in the sequence. Because both the query and the key are rotated, the angle between any two of them depends only on how far apart the positions are.position becomes an anglem = 2m = 5m = 9⟨ R(mθ)q , R(nθ)k ⟩= ⟨ q , R((n−m)θ)k ⟩The absolute indices cancel. What survivesthe inner product is n − m, the distance.Nothing is added to the embedding, so theresidual stream is left alone; only q and kare turned, inside each head.
Fig. 3 — Rotary encoding turns position into an angle. Both the query and the key are rotated, so the absolute indices cancel in the inner product and only the distance survives.

Demonstration

Take the query and key as sequences of two-dimensional pairs. Rotate the pair at position m by angle , and the pair at position n by . Then

⟨ R(mθ)q , R(nθ)k ⟩  =  ⟨ q , R((n − m)θ)k ⟩

because a rotation is orthogonal and rotations compose by adding angles. The absolute positions m and n cancel; what survives is nm, the distance.

This is a genuinely different move from the previous proposition. A sinusoidal or learned encoding adds a position-dependent vector to the token embedding, so position enters the residual stream and every subsequent operation sees it mixed into the content. Rotary encoding adds nothing. It rotates q and k inside each attention head, at the point of comparison, and leaves the residual stream untouched.

Three practical consequences follow, and they explain why it is now the default in most open language models.

Relative by construction, not by learning. The model does not have to discover that positions are comparable by difference; the arithmetic guarantees it.

No table, no length ceiling in the parameters. There is nothing to run out of, which makes the various context-extension methods possible at all: scaling θ down at inference (position interpolation) compresses a longer sequence into the range of angles the model was trained on.

Decay with distance, for free. Because different pairs rotate at different rates, the inner product between distant positions averages toward zero across dimensions — a mild locality bias that nobody had to specify.

Corollary

The rotation is applied per head, after the projections of Chapter V, Proposition 2 and before the dot product. Getting that placement wrong — before the projection, or on the values as well — is a common implementation error, and it produces a model that trains and is merely worse, rather than one that fails.

Sources