RoPE Implementation
PremiumInverse frequency computation, cos/sin caching, and a vectorized apply_rotary_pos_emb
Get code accessInverse Frequency Precomputation
The previous chapter reduced RoPE to "rotate each two-dimensional subspace." Turning that sentence into code means three concrete steps: work out how fast each subspace rotates, multiply that rate by the position to get an angle, then turn the angle into / tensors you can multiply directly.
The first step is easy to wave through as a one-line formula, but it is what governs the model's extrapolation behaviour. Recall the formula:
Log in to continue reading
This is premium content. Please log in to access the full article.
CookLLM Docs