RoPE (Rotary Position Embedding) injects position information by rotating the attention queries and keys by an angle proportional to the word's position. It was proposed by Su et al. in 2021 in the RoFormer paper.
The scaled dot-product attention in the Transformer does not distinguish word order on its own. The original Transformer added sinusoidal positional encoding to the input embeddings. Instead of adding, RoPE multiplies the queries and keys in every layer by a rotation matrix.
Rotation is used because when two vectors are each rotated and then their dot product is taken, the result depends only on the difference between the rotation angles. If the query at position is rotated by and the key at position by , the dot product depends only on the angle difference , that is, only on the distance between the two words. The defining feature of RoPE is that although the rotation uses absolute positions, attention receives relative positions.
There are no learned parameters. LLaMA drops absolute position embeddings and applies RoPE in every layer of the network (Section 2.2 of the LLaMA paper).
The left of the figure at the top of the article shows where position information is injected. It has the same layout as the figures in the articles on learned positional embeddings, relative position representations, and ALiBi, so the injection points can be compared directly. The right is a worked example of the rotation and dot product for one 2-dimensional pair.

