RoPE

Wiki chapters and blog posts about RoPE.

Wiki

Long Context: Position Extrapolation, Training Recipes and Cost

Extending a context window from 4K to 128K takes three fixes: RoPE extensions (PI, NTK-aware scaling, YaRN) for unseen positions, staged continued training on long text, and a budget for attention compute and KV cache. This page covers all three with formulas, code and two interactive tools.

Advanced 40 min read

Modern LLM Architecture: From GPT-2 to Llama, Qwen and DeepSeek

Almost every mainstream open LLM is a refined decoder-only Transformer: Pre-Norm with RMSNorm, a SwiGLU feed-forward network, RoPE positions and GQA attention, and some add mixture of experts (MoE) to grow parameters without growing compute in proportion.

Intermediate 15 min read

Positional Encoding Explained: Absolute, Relative and RoPE

Self-attention cannot see token order, so positional encodings tell the model where a token is or how far apart two tokens are: sinusoidal and learned encodings are added to the input, relative biases and ALiBi act on attention scores, and RoPE rotates queries and keys.

Intermediate 26 min read

Blog posts

YaRN: Extending RoPE Models to a 128K Context Window with Light Fine-Tuning

YaRN extends a RoPE model's context window by interpolating each rotary dimension according to how many turns it makes within the training length and adding a softmax temperature tied to ln s. 400 to 600 fine-tuning steps take Llama 2 to 128K. This post covers PI, NTK-aware and the evidence.

Paper notes arXiv 2023

RoFormer: Writing Position into the Attention Dot Product with Rotations

RoFormer's rotary position embedding (RoPE) rotates queries and keys by position, so their dot product depends only on relative position, with no extra parameters. It later became standard in open LLMs such as LLaMA. We check its formulas, its mixed small-scale results and its properties in code.

Paper notes arXiv (later Neurocomputing 2024) 2021

Topics