Expand description
Rotary Position Embedding (RoPE) — the STEM definition: a 2-D rotation.
RoPE encodes token position by rotating each adjacent dimension pair (2i, 2i+1) of a
head by a position- and frequency-dependent angle
θ_i = (pos / scale) · base^(−2i / head_dim)
(x0, x1) ↦ (x0·cosθ − x1·sinθ, x0·sinθ + x1·cosθ)That is exactly a rotation in the (2i, 2i+1) plane — the same rotation a geometric-algebra
rotor (super::geometric_algebra) performs — applied per head. It is orthogonal, so it
preserves the norm of every pair. Nothing proprietary: it is trigonometry. The LLM runtime’s
rope_inplace is an f32 backend computing this same function.
In place on a caller-owned slice; zero allocation.
Functions§
- rope_
interleaved - Apply interleaved (“normal”/llama) RoPE to
vec, treated asn_headsconsecutive blocks ofhead_dimelements. Each block’s adjacent pairs(2i, 2i+1)are rotated byθ_i.posis the token position,basethe RoPE frequency base (e.g. 10000),scalethe position scaling (≤ 0 or non-finite is treated as 1).