Enough RoPE

Unlike RNNs, which read one token at a time, Transformers get their whole context window at once. So, it’s pretty intuitive that we need to give them some kind of signal about the ordering of those tokens so they don’t just devolve to treating their input as a bag of words.1 Seb Raschka recently did an in-depth breakdown on positional encodings, including how the industry largely aligned around RoPE for providing this information.

But RoPE is… kinda weird? It encodes the position in the query and key projection heads in attention. It splits the head into pairs of values, treats each pair as a 2D vector, then rotates it (like a hand on a clock) based on the token position. When a query is compared with a key the difference between their rotations gives how far apart the two tokens are. Each pair is rotated at a different rate: a 64-dimension head gives you 32 pairs with the fastest completing a rotation every 6 tokens, the slowest every ~47k. The models learn to stick this together to understand overall position.

That positional information also makes the dimensions somewhat useless for learning other kinds of rules: if you put some semantic comparison into the pairs and they get rotated 180 degrees after 3 tokens, you lose that information.

Unlike rotations, we don’t tell the model to put semantic information into a channel though, they learn it. Specifically, they appear to learn to leverage the dimensions in three ways: a precise count within the last few tokens for the fast rotating pairs, a general sense of how far back something is for the medium pairs, and mostly semantic content that ignores the rotation for the slow pairs.2

It is not a tremendous leap to think that rotating parts of the head then training the model to ignore it may not be the optimal route.

Gemma 4 used “p-RoPE” (partial RoPE), only rotating the fastest quarter of the pairs. A recent ETH paper, HiSA, stopped counting pairs in the attention score if two entries are more than 90° apart, which covered about 2 tokens on the fast pairs to around 12k tokens on the slow pairs. Surprisingly, doing this seemed to result in slightly better models. They concluded that the larger angles are mostly noise the model has to learn to ignore.

I tried this out with SmolLM-135M, fine-tuning it on “what is the token D steps back” in a non-repeating context window. The model solves this completely (out to 1,024 tokens at least). Taking the fine-tuned model and masking out each pair’s contribution where it had done 2 or more rotations nuked exact recall past D = 32, but the same change on the base model made hardly any difference to the model’s performance on regular prose-type tasks (0.0007 nats). So distance positional information isn’t quite noise, but it only impact capabilities the model mostly never needs.3

Put this together and it looks like RoPE gets used in three chunks: fast pairs for exact offsets, something in the middle that acts as a general distance signal, and slow pairs that are mostly content.

RoPE isn’t the only option, though.4 Thinky’s Inkling models instead have specific mechanisms for each of those chunks. For local navigation they use a sconv, a short convolution. Each layer has 4 depthwise 1D convolutions with window size W=4. They don’t mix channels, just neighboring tokens, so the model can learn what represents 1, 2 or 3 tokens ago without having to figure out a rotation.

For the middle distance Inkling adds a relative-position bias to the attention logits, prior to the softmax. This is an additional term, not a transform of the query and key.5 It’s implemented as a lookup table that has one value per distance. Each head learns 16 different versions of those tables during training, and each token’s query value picks its own mix of the 16, so how much attention it pays to different distances depends on what the token is. They use this to cover the whole sliding window on local layers, and the most recent 1k tokens on global ones. Beyond that they skip positional encoding entirely.

How much RoPE do you actually need? Some for the local distance, and some for the last thousand or so tokens, but you, probably, don’t need it much further out. And, if you start with that premise, maybe you don’t need RoPE at all!

  1. Mostly! A causal model can still work out roughly where it is from the mask, which is why NoPE/going without any encoding works at all. Meta’s iRoPE, for example, dispenses with RoPE entirely on the global (non-sliding window) layers. ↩︎
  2. Barbero et al. suggested that in Gemma 7B, the fast-moving pairs act as local positional heads, while the slow pairs get reused as semantic channels rather than positional ones: they move so slowly they are almost position-free. ↩︎
  3. This was a lot less aggressive than the HiSA cut, which in my test reduced performance by 0.22 nats on prose. This was much worse than in the paper, but 1) I didn’t retrain from scratch 2) the performance seemed specific to one layer which had learned what amounted to a fixed penalty on keys a long way back. ↩︎
  4. Back in April, Jane Street published a math-heavy post arguing that a good positional encoding should be linear, depend only on relative distance, be the identity at distance zero, and be continuous. Those constraints pretty much force you into a few valid options: no encoding, a decay term, or rotation. They concluded all the sensible choices are already in production, though their “linear” constrain excludes exactly what Thinky did below! ↩︎
  5. This isn’t new, T5 did it, and Shaw et al. had a query-dependent version back in 2018, but I don’t know anyone shipping it at this scale. ↩︎

Get new posts by email

If you enjoyed this, subscribe and the next post will land in your inbox. No spam, unsubscribe any time.

Prefer a feed reader? Follow along via RSS.