chapter 01
RoPE, properly
Day 1 introduced the idea: rotate queries and keys by their position, and the dot product sees only the distance.
Where it lives
RoPE inside one attention layer, with shapes
The frequency table
One frequency per pair, set by the base
inv_freq = 1 / base ** (arange(0, d_h, 2) / d_h) wavelengthi = 2π / θi
Build cos and sin once, look them up forever
Pairing and rotate_half
Two ways to choose the pairs
rotate_half, step by step
rotate_half([x₁, x₂]) = [−x₂, x₁] q′ = q · cos + rotate_half(q) · sin
Positions at decode time
The new token starts where the cache ends
position_ids = cache_len + arange(new_tokens)