Skip to main content
CookLLM logoCookLLM Docs

RoPE Math Derivation

Premium

From complex rotations to higher-dimensional generalization, understand the core math of rotary position embeddings

Get code access

Start From the Requirement

In the previous chapter we stated a core requirement: we want the dot product of QmQ_m and KnK_n to depend only on content and relative position m−nm - n:

⟨f(Xm,m),f(Xn,n)⟩=g(Xm,Xn,m−n)\langle f(X_m, m), f(X_n, n) \rangle = g(X_m, X_n, m - n)

Here ff is the position-encoding function we design; it takes a token content vector and position index and outputs a position-aware vector.

The key insight of RoPE is: encode position by rotation. We start with the simplest 2D case.

Log in to continue reading

This is premium content. Please log in to access the full article.