Read the equation
rotate_half maps a pair of coordinate blocks(x 1,x 2) to(−x 2,x 1). Multiplication by cosine and addition of the sine-weighted rotated vector implements a two-dimensional rotation for each coordinate pair. The surrounding interleave-to-block reshape determines which coordinates are paired. Norm is preserved when the paired sine/cosine coefficients have unit squared sum.
Terms & definitions
| Term | Meaning in this source |
|---|---|
| q | Query vector after source-prescribed pairing |
| cos | Cosines for the token position |
| sin | Sines for the token position |
How it works
Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.
Assumptions & limits
Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.
Original context
Read the surrounding source passage
APPLICATION
rotate_half(x) splits the last dim in half and returns concat(-x2, x1).
apply_rotary_pos_emb indexes cos/sin by position_ids and computes
q_out = q*cos + rotate_half(q)*sin
after an interleave-to-blocked reshape: (b, h, d) -> (b, h, d/2, 2)
-> transpose(4,3) -> reshape back. Get that reshape wrong and the model
produces fluent nonsense rather than an obvious error.Exact original notation
q_out = q*cos + rotate_half(q)*sin