Rotary position embeddings, commonly called RoPE, inject position into attention by rotating pairs of query and key channels with angles determined by token position. The rotation happens before the query-key dot product. As a result, position is not represented by adding a standalone vector to each token representation.

This distinction matters during inference. A token’s cached key already contains the rotation associated with its assigned position. Reusing that key under a different sequence coordinate without an equivalent transformation changes the attention computation, even when the token content is identical.

RoPE applies position-dependent rotations

For one two-dimensional channel pair, a rotation at position m can be written as

R(mθ) = [[cos(mθ), -sin(mθ)],
         [sin(mθ),  cos(mθ)]]

where θ is the frequency associated with that channel pair. A query q and key k become

q_m = R(mθ) q
k_n = R(nθ) k

before their dot product is evaluated.

The useful algebraic property comes from orthogonal rotations:

q_m^T k_n
= q^T R(mθ)^T R(nθ) k
= q^T R((n - m)θ) k

Under this idealized pairwise form, the position-dependent part of the score depends on the relative offset n - m. Real transformer implementations apply many frequencies across channel pairs, but the same rotation identity is the core mechanism.

RoPE does not make the rest of the model translation-invariant. Token representations entering the attention projection already depend on prior layers, causal context, normalization, and model parameters. The algebra above describes the positional transformation inside the query-key score, not the behavior of the full network.

A shared position shift preserves the pairwise phase difference

Suppose both positions are shifted by the same integer s:

m' = m + s
n' = n + s

Then

n' - m' = n - m

so the relative rotation in the dot product is unchanged for that query-key pair.

This property is narrower than saying that absolute positions never matter. The individual rotated vectors R(mθ)q and R(nθ)k do change under the shared shift. Their dot product preserves the relative phase because the rotations cancel algebraically in that specific operation.

The distinction becomes relevant when a system stores rotated keys, mixes cached and newly computed states, applies architecture-specific scaling, or exposes position identifiers separately from token order. A serving implementation must preserve the model’s intended coordinate system rather than relying on a broad claim that RoPE uses only relative position.

KV caches bind keys to assigned positions

Autoregressive serving commonly stores keys and values from earlier tokens so each decoding step does not recompute the full prefix. With RoPE, a cached key is typically stored after its position-dependent rotation, although exact cache layout is implementation-specific.

If a cached key was produced for position n, its rotated form contains R(nθ). Treating the same tensor as if it belonged to position n + s does not magically apply R(sθ). The cached tensor and the new query can then carry inconsistent coordinates.

This is separate from prefix identity. Two requests may contain the same token IDs yet assign different effective positions because of inserted tokens, removed tokens, special-token handling, sequence packing, or serving logic. Cache reuse is valid only when the cached state is compatible with the model state the new request requires, including its positional convention.

Some systems can transform cached states when shifting coordinates, and some architectures use RoPE variants with additional scaling rules. Such transformations are model- and implementation-specific. Copying a rotated cache entry to a new coordinate without accounting for those rules is not generally equivalent.

Position IDs are semantic inputs even when they are not embedded additively

Framework APIs often expose position_ids, cache positions, or related sequence indices. With RoPE, these values can look like bookkeeping because no additive position embedding table is indexed. They still determine rotation angles and therefore affect attention scores.

A mismatch can be subtle. Tensor shapes remain valid, matrix multiplication still executes, and the cache can have the expected length. The error is semantic: query and key rotations represent coordinates different from those intended by the sequence.

This also means that padding and packing conventions need explicit treatment. A batch may use physical tensor indices that differ from logical token positions. Whether padding positions consume RoPE coordinates depends on the model and serving implementation. The correct mapping is the one used by the checkpoint’s inference contract, not a universal rule derived from batch shape.

Context extension changes the rotation regime

RoPE frequencies are defined by the model architecture. Extending usable context can involve modifications to position mapping or frequency scaling in implementations that support such variants. These methods do not merely allocate a larger attention mask. They alter the positional transformation presented to the model.

A larger accepted position index therefore does not by itself establish that a checkpoint will behave as intended at that index. The architecture, configuration, and inference code must agree on the RoPE variant and its parameters.

This boundary is especially relevant when moving checkpoints between runtimes. Two runtimes can agree on tensor dimensions and weight values yet produce different results if they interpret RoPE scaling, rotary dimensions, frequency bases, or cache coordinates differently.

Rotation layout is part of checkpoint compatibility

The mathematical description groups channels into two-dimensional pairs, but software can arrange those pairs in different layouts. One implementation may pair adjacent components; another may split a vector into halves and rotate corresponding components. Both can implement rotary transformations, but they are not interchangeable unless the checkpoint and weight layout expect the same convention.

The rotary dimension can also cover all or only part of each attention head. Frequencies, base parameters, scaling variants, and numeric precision can further affect the generated sine and cosine values.

For that reason, a RoPE implementation should be treated as part of model semantics rather than as a free serving optimization. Kernel fusion may combine rotation with projection, attention, or cache writes, but the fused result still has to match the checkpoint’s intended transformation within the runtime’s numerical tolerance.

The practical boundary is precise: relative phase explains a useful property of RoPE scores, while cache coordinates, rotary layout, frequency configuration, and context-scaling rules remain concrete compatibility requirements. Preserving tensor shapes is not enough when those positional semantics differ.