Rotary and relative position encodings

Transformer components · component · 2021 · text

What it is

Inject position by rotating query/key pairs by an angle proportional to position (RoPE), or by adding learned relative biases (ALiBi, T5).

When to use it

Every modern transformer. RoPE with frequency scaling (YaRN, NTK) is how context windows get extended at inference.

Caveats

Extrapolation to sequences longer than those seen in training is unreliable without adjusting the frequencies or fine-tuning. The base frequency is a hyperparameter, and RoPE must be applied inside every attention layer.

Key ideas

  • RoPE is relative in the dot product, which is why it extrapolates at all
  • Position-scheme choice determines how well a model stretches to longer context

Related architectures

Original paper

RoFormer: Enhanced Transformer with Rotary Position Embedding (2021, arXiv)

Lessons that cover it

Browse all 198 architectures

The architecture landscape, in one place.

Two things get called “ML architecture”: the classical statistical model families, and the neural network wirings. Both are here, tagged by what they are and what data they eat.

Start from your problem

Architectures

0 shortlisted