Attention is blind to order, so position has to be put in. Nearly every open model does it with RoPE: each pair of query and key dimensions is turned by position × its own frequency, so a score depends only on the distance between two tokens. Its slow pairs, whose period is longer than the trained length, are what break past that length, and every context-extension method (PI, NTK, YaRN, Llama 3) is a rule for slowing them down.
Fig. 1, step by step: RoPE is a bank of clocks
You need: what attention computes (scores q · k, a softmax, a weighted sum of values) and what a KV cache holds: The transformer from zero or the root Topic: llm-architecture. This page owns position schemes and RoPE scaling; MLA's decoupled RoPE key is taught on Attention variants, KV memory and effective context on Long context, the RoPE paper itself on RoFormer.
rope_theta: θi = base−2i/d, so a larger base makes the slow pairs slower.| Scheme | What it changes | Learned? | Past the trained length | Tiny GPT, held-out loss at 256 measured | Tiny GPT, loss at 1,024 to 2,047 measured | In the 2026 configs read here |
|---|---|---|---|---|---|---|
| Learned absolute | Adds one trained vector per position to the input | Yes, one row per position | No row exists: a hard error | GPT-2, BERT; none of the 2026 models | ||
| Sinusoidal | Adds fixed sines and cosines to the input | No | Defined, but the model never saw those vectors | The 2017 Transformer | ||
| T5 bias | Adds one learned scalar per distance bucket to each score, per head | Yes, 32 per head | All distances from 128 on share one bucket | not run here | not run here | T5 and its descendants; Inkling (2026) learns a relative bias of its own, form unconfirmed |
| ALiBi | Subtracts slope × distance from each score | No, a fixed slope per head | Nothing goes out of range | BLOOM, MPT (2022 to 2023) | ||
| RoPE | Rotates each pair of query and key dimensions by position × frequency, in every layer | No | Slow pairs meet unseen angles; fixed by RoPE scaling | of the configs | ||
| NoPE | Nothing; the causal mask is the only order signal | No | No angles to break, but attention past the trained length is still untrained | Some layers of Llama 4, SmolLM3, Command A; all attention layers of Nemotron-H, Granite 4.0-H, Kimi Linear and K3 |
Measured columns: the topic's tiny GPT (6 layers, 256 wide, 1,500 steps on 12.3M TinyStories tokens at context 256, seed 0, equal budgets, only the position scheme changed), Apple M1 Pro, 2026-10-18 (section 5). A gap of a few hundredths is within seed noise. The last column counts the configs read by this page's census (src/census/census.py); "RoPE" includes partial and decoupled RoPE.
A head scores the token at i against every key j with sij = qi · kj / √d, and q, k, v are linear maps of each token's vector, which says nothing about where the token is. Shuffle the inputs and the outputs shuffle the same way: attention is permutation-equivariant, so "Roxy climbed the hill" and "the hill climbed Roxy" are the same bag of vectors. The causal mask leaks some order: one layer still sees a set (shuffle tokens 0 to i − 1 and token i's output is unchanged), but each earlier token saw a different prefix, so from the second layer on the stack can count. A decoder with no positions (NoPE) can learn order; a bidirectional encoder cannot.
How a mask becomes a count, in the smallest case. Let one value feature be 1 on the first token and 0 elsewhere, and let a head attend uniformly to everything the mask allows: at position 2 it averages three values and outputs 1/3, at position 3 it outputs 1/4. The output is one over the prefix length, which a later layer can read as a position (Kazemnejad et al.'s construction, made concrete in Raschka's walkthrough). The probe below measures what this predicts.
Where the model keeps position. Fit a linear probe (ridge regression) from the residual stream after each block to the absolute position 0 to 255, on windows the probe never saw: R2 = 1 means position is written in plainly, 0 that a linear readout cannot find it.
Fig. 2, step by step: five tiny GPTs that differ only in their position scheme
Positions matter whenever order carries meaning, most when a model must find one token far back and when it runs past the length it was trained on. The two checks are the ones above: a permutation test on one block, a position probe per block.
An absolute scheme adds a position vector pm to the token's embedding once, xm = e(tokenm) + pm, and position must survive in the residual stream. A relative bias adds a number that depends on the distance to every attention score, in every layer. RoPE rotates queries and keys so the dot product itself depends on the distance. NoPE adds nothing.
Fig. 3, step by step: one pair of tokens, four lanes
The chart puts all of them on one query: one token's content vector (64 dimensions, seeded random, illustrative) repeated at every position, so content adds the same to every score and only position differs.
Predict, then try: which curves move when you shift the pair along? Only the absolute ones (their unshifted curve stays faint): the same two tokens at the same distance get a different score at a different place. Switch to Attention weights: NoPE spreads attention evenly over everything the mask allows, ALiBi decays exponentially (head 1 looks a few tokens back, head 8 hundreds), T5 is flat from 113 tokens on, RoPE with base 10,000 decays and ripples. At 0 to 2,048 the learned table stops at 512: there is no row 512.
The curve is what position adds to the logit between the query and a key k tokens back, computed exactly. Head selects ALiBi's slope and T5-base's decoder head (the first 8 of its 12). The trained length 512 is illustrative (BERT's and T5's input length).
A learned table (GPT-2 has 1,024 rows, BERT 512) costs Lmax × d parameters (65,536 in the tiny GPT, 786,432 in GPT-2) and a hard cap. As a share of the model the cost is small only at short contexts: GPT-2 Medium's 1,024 rows are 0.30% of its 355M weights, and a 100,000-row table would add 102.4M and make up 22.4% of the resulting 456M (calculation, the framing of Raschka's walkthrough). Ask the learned-position tiny GPT for position 300 and it fails loudly, as Hugging Face's GPT-2 does:
The 2017 sinusoids were chosen because they "may allow the model to extrapolate to sequence lengths longer than the ones encountered during training" (Vaswani et al. §3.5); learned embeddings gave "nearly identical results" (Table 3, row E). In practice they do not extrapolate: sinusoidal perplexity stopped improving about 20 tokens past a 512-token training length and degraded from about 50 (Press et al. 2021 §2). On the tiny GPT, Both kinds also mix position and content in one vector from the first layer, which DeBERTa argued against (closed block below). The Attention Is All You Need page draws the sinusoid heatmap and retrains a toy without positions.
T5 (2019) adds one learned scalar per distance bucket to the logit: 32 buckets per head, shared across layers. Exact offsets first, then logarithmically wider buckets, with 113 onwards in the last one. One layer is blind beyond 128, though stacked layers pass information further. It extrapolated best of the pre-ALiBi baselines (600 to 800 extra tokens), at the price of training at least twice as slowly (ALiBi §2); details on the T5 page.
ALiBi (2021) adds a fixed penalty −m · distance to each score, a different slope per head: 1/2, 1/4, ..., 1/256 for 8 heads (Press et al. §3). A 1.3B model trained on 1,024 tokens "extrapolates to input sequences of length 2048, achieving the same perplexity as a sinusoidal position embedding model trained on inputs of length 2048 but training 11% faster and using 11% less memory". Its cost is that every head is forced to prefer nearby tokens, so a head that should retrieve something far back fights a penalty that grows with distance, and FlashAttention needed an explicit bias path for it. Used by BLOOM and MPT; every open family since 2023 in the configs read here uses RoPE (or, in hybrids, no positions) instead. Measured here:
A learned relative bias returned in 2026. Thinking Machines' Inkling (975B parameters, 41B active, released 15 July 2026) adds a learned relative bias to each score before the softmax; its announcement says only that this relative positional embedding beat RoPE and extrapolated better. Raschka describes the bias as depending on the query token's hidden state as well as the distance, which would make it T5's bucketed scalar made content-dependent; that reading is unconfirmed until the code or a report says so (Raschka's walkthrough, section 5).
Shaw, Uszkoreit and Vaswani (2018) added a learnable vector for each relative distance, clipped at a maximum k, to the keys when scores are formed and optionally to the values. On WMT 2014 it beat absolute positions by 1.3 BLEU (English to German) and 0.3 BLEU (English to French), and "combining relative and absolute position representations yields no further improvement" (Shaw et al.). T5 simplified it to one scalar per bucket.
DeBERTa's disentangled attention (2020): "each word is represented using two vectors that encode its content and position, respectively, and the attention weights among words are computed using disentangled matrices on their contents and relative positions" (He et al.): content-to-content, content-to-position and position-to-content terms. Absolute positions enter only in an "enhanced mask decoder" near the output. Not run here: it is an encoder design, and no decoder config read on this page uses it.
ALiBi's slopes beyond 8 heads. For 16 heads, the geometric sequence from 1/√2 with ratio 1/√2. MPT-7B's config generalises this as 2−8h/n over its 32 heads (alibi_bias_max 8: slopes from 0.84 to 1/256).
T5's buckets. In the decoder, offsets 0 to 15 get a bucket each, then 16 to 18, 19 to 20 and so on, growing logarithmically, with 113 onwards in bucket 31 (recomputed with T5's bucket function). The T5-base decoder's last bucket, offsets 113 and beyond (the dotted line in the chart), holds values from −40.8 to 32.8 across heads where every other bucket stays between −22 and 5.4; the chart clips them. Span corruption makes a 104-token target per 512 tokens of text (T5 page), shorter than 113, so the denoising objective alone never reaches that bucket; the released checkpoints were also trained on supervised tasks with longer targets, so why its values sit so far out is unconfirmed.
The tiny GPT's code. Learned and sinusoidal positions are GPT.embed (lines of the root's src/data/tiny_gpt.py); ALiBi is alibi_slopes and attn_bias (lines and ).
We want a score that depends on how far apart two tokens are and not where the pair sits, with no parameters, without touching the values, and with keys that can still be computed once and cached. Rotary position embedding (RoFormer, Su et al. 2021) gets all four by rotating each query and key instead of adding a vector.
Fig. 4, step by step: one pair, then a whole head
Each vector is rotated by its own absolute position, so a key is rotated once and stored rotated in the KV cache; the offset appears only inside the dot product. Rotations keep lengths, and values are not rotated: position shapes where a head looks, not what it reads. RoPE is absolute in form and relative in effect.
A whole head is a bank of clocks. Split each query and key of a head (dimension d) into d/2 pairs and give pair i its own speed. In the tiny GPT (head 32, base 10,000) there are 16 pairs: pair 0 turns once every 6.3 tokens, pair 6 once every 199, pair 7 once every 353 and pair 15 once every 35,333. Within the 256-token training window pairs 0 to 6 go round at least once, so the model has seen every angle they can take; pairs 7 to 15 only covered a wedge, pair 15 just 2.6 degrees. Fast pairs resolve neighbouring tokens, slow pairs measure long distances, and that split, 7 fast and 9 slow, is Fig. 1 at the top and the whole story of section 6. At Llama 3's shape (d = 128, base 500,000) the spectrum runs from pair 0 at 1 radian per token (a turn every 6.3 tokens) to pair 63 at 2.46 × 10−6 radians per token (a turn every 2.56 million tokens).
Cost and the two checks. No parameters; about 3 operations per element of q and k per layer and token, 6 × 256 = 1,536 in the tiny GPT against about 1.57 million for the layer's matrix products, 0.1% (calculation); on datacenter GPUs it is fused into the attention or projection kernels. What matters is that every RoPE layer uses the convention the weights were trained with: the base, the rotated dimensions and the pairing layout. Getting any of them wrong runs without an error and degrades the text (measured in Depth below). Two checks, cheapest first. The shift test: compute a head's scores, add 3 to every position, recompute and assert they match (torch.testing.assert_close, as in Raschka's walkthrough); it catches q and k rotated by different positions, cached keys given the wrong positions and a broken cos and sin table, in milliseconds and with no weights. It cannot catch a wrong convention, since any base and either pairing are shift-invariant; for that, compare the loss on a few hundred tokens with a reference. The RoFormer page owns the rest of the paper: its eight-pair dials, the long-term decay figure rebuilt, and toy models run past their length.
Hugging Face computes cos and sin once per position and applies them with rotate_half, which pairs dimension i with dimension i + d/2 ():
The tiny GPT does the same in 17 lines (root src/data/tiny_gpt.py, ): the class Rope takes the frequencies from rope_inv_freq and is applied to q and k right after the head split and before the scores.
Measured on the tiny GPT's training run, unfused on MPS, RoPE trained at (rough timings on a shared laptop).
The same rotation can pair dimensions (x0, x1), (x2, x3), ... (the paper's and GPT-J's layout; Command A's config says rope_gptj; DeepSeek ships interleaved weights, and transformers keeps a separate apply_rotary_pos_emb_interleave for them, ) or pair i with i + d/2 (Hugging Face's rotate_half; gpt-oss's _apply_rotary_emb splits in halves too, ). The two are equivalent only after permuting the rows of the query and key projections, which Hugging Face's Llama conversion script does with its permute function (convert_llama_weights_to_hf.py).
In short: held-out loss 1.96 becomes 3.61 with no error and no warning.
A larger base slows every pair except pair 0, so more pairs stay informative across a long window. Xiong et al. found Llama 2's base of 10,000 decayed attention too strongly beyond 4,000 to 6,000 tokens and proposed "increasing the 'base frequency b' of RoPE from 10,000 to 500,000", called adjusted base frequency, ABF (Xiong et al. §4.1); Llama 3 pretrains with 500,000 (Llama 3 page), and Qwen3 raises 10,000 to 1,000,000 for its long-context stage (Qwen3 page). This is a pretraining choice, not the NTK-aware scaling of section 7, although both change the base.
Read a config's position line in 30 seconds. (1) Is there RoPE at all: rope_theta or rope_parameters, but check the modeling code of hybrids, where the field can be present and unused. (2) How many dimensions rotate: head_dim × partial_rotary_factor, or qk_rope_head_dim for MLA, or rotary_dim. (3) Which layers: layer_types, no_rope_layers, no_rope_layer_interval, per-layer-type rope_parameters. (4) Scaling: rope_scaling or rope_parameters.rope_type with its factor and original_max_position_embeddings, the length the model was actually pretrained at; max_position_embeddings is a ceiling, not the trained length (Qwen3's configs say 40,960 for a 32,768-token native window; MiniMax-M1's says 10,240,000).
rope_parameters, a dict holding rope_type, rope_theta, factor and the rest (nested per layer type for Gemma 4); old rope_theta and rope_scaling fields are still read and moved into it (RotaryEmbeddingConfigMixin.standardize_rope_params in transformers modeling_rope_utils.py). Code that reads config.rope_scaling directly gets the old field or nothing.Five variants matter in practice. Partial RoPE rotates a fraction of each head and leaves the rest to match on content alone (GPT-NeoX 25%, Phi-2 40%, GLM-4.5 and MiniMax-M3 half, Qwen3-Next a quarter). Rotating less barely saves anything (halving MiniMax-M3's cosine and sine tables at a million positions saves 128 MiB, and the KV cache still stores the full key), and Fractional Rotation found about 10% rotated matched full RoPE in 1B to 8B models; the reasons to rotate only part of a head lie elsewhere: a content-only channel (Barbero et al.'s Gemma finding below) and, for MLA, keeping position out of the absorbed keys (next). Decoupled RoPE (DeepSeek's MLA) keeps position out of the compressed keys and carries it in a separate 64-dimension key shared by all heads, because a rotated key would block absorbing the key up-projection into the query (the mechanism is on Attention variants). Multimodal RoPE gives images and video several indices: Qwen2-VL splits the rotation into "temporal, height, and width" components, and for text "these components utilize identical position IDs, making M-RoPE functionally equivalent to 1D-RoPE" (Qwen2-VL §2.1). What this does inside a vision-language model (an image advances the position counter by its larger side, not by its token count) is on Vision-language models, section 2a. Mixed layers interleave RoPE layers with NoPE layers or a different base. No RoPE anywhere in hybrids, where recurrent layers carry order. The strips beside this show the layer patterns, read from each config.
From each config.json (layer_types, no_rope_layers, sliding_window_pattern, no_rope_layer_interval, linear_attn_config); the fields are quoted verbatim in the closed table below. Short cells are local layers.
Partial RoPE comes in two kinds. The default kind spreads the whole spectrum over the rotated dimensions (exponents 2i/drot), so its slowest pair is as slow as a full head's. Gemma 4's "proportional" kind keeps the full head's exponents (2i/dhead) for the first pairs and sets the rest to zero frequency, so it keeps only the fast clocks.
Why keep only fast pairs: Barbero et al. found Gemma uses RoPE's highest frequencies for positional attention patterns and "greatly prefers to use the lowest frequencies", which they suspect carry semantic information (Round and Round We Go).
| Model | What carries position | Config fields (verbatim) | Source |
|---|---|---|---|
| GPT-NeoX-20B | RoPE on 25% of each head's dimensions; the rest position-free | rotary_pct 0.25, rotary_emb_base 10000 | config, paper |
| Phi-2 | RoPE on 40% of the head | partial_rotary_factor 0.4 | config |
| GLM-4.5 | RoPE on half of each 128-dimension head | partial_rotary_factor 0.5, rope_theta 1000000 | config |
| MiniMax-M3 | RoPE on half of each 128-dimension head, over a million positions | head_dim 128, rotary_dim 64 (partial_rotary_factor 0.5), rope_theta 5000000, max_position_embeddings 1048576 (read 27 November 2026) | config.json, as read on Raschka's walkthrough |
| Qwen3-Next, Qwen3.5 | RoPE on a quarter of each 256-dimension head, only in the full-attention layers (one in four); the Gated DeltaNet layers carry no positions. Qwen3.5 adds interleaved M-RoPE sections for images. | partial_rotary_factor 0.25, rope_theta 10000000, mrope_section [11, 11, 10] (Qwen3.5) | Qwen3-Next config, Qwen3.5 config |
| Gemma 4 31B | rope_parameters: sliding_attention default, theta 10,000; full_attention "proportional", partial_rotary_factor 0.25, theta 1,000,000; global_head_dim 512 | config, transformers | |
| DeepSeek-V3, V3.2, V4-Pro (MLA) | Per head, 128 position-free dimensions from the latent plus a 64-dimension decoupled RoPE key shared by all heads: one third of the 192 score dimensions rotate. YaRN stretches only this key. V4's compressed-attention layers use their own base. | qk_nope_head_dim 128, qk_rope_head_dim 64; V4: compress_rope_theta 160000 | V3 config, V4-Pro config, V3 report §4.3 |
| Qwen2-VL-7B | M-RoPE: the 64 frequency pairs split 16 / 24 / 24 among time, height and width | mrope_section [16, 24, 24] | config |
| Gemma 3 27B | Five local layers (1,024-token window, base 10,000) for every global layer (base 1,000,000, Position Interpolation ×8 for 128K) | sliding_window_pattern 6, rope_local_base_freq 10000, rope_scaling linear 8 | report §2, §5.3, config (mirror) |
| gpt-oss-120b | Alternating 128-token sliding-window and full-attention layers, all with RoPE (YaRN ×32) | layer_types, sliding_window 128, rope_theta 150000 | config |
| Llama 4 Scout | Three RoPE layers attending within 8,192-token chunks, then one full-attention layer with no positions; on those NoPE layers the query is scaled by 1 + 0.1 ln(⌊(p+1)/8192⌋ + 1), 1.49 at position one million and 1.72 at ten million (recompute.py; code below) | no_rope_layers [1,1,1,0,...] (1 = uses RoPE), attention_chunk_size 8192, attn_temperature_tuning true, attn_scale 0.1, floor_scale 8192 | Meta blog, config (mirror), transformers |
| Command A | "Interleaved layers of sliding window attention and full attention in 3:1 ratio. Each sliding window layer uses RoPE and every full attention layer uses No Positional Embeddings" | sliding_window_pattern 4, sliding_window 4096, rope_theta 50000, position_embedding_type rope_gptj | report, config (mirror) |
| SmolLM3-3B | RoPE removed "from every 4th layer"; all layers attend fully | no_rope_layer_interval 4, rope_theta 5000000 | blog, config |
| Mistral Large 3 (MLA) | A 64-dimension decoupled RoPE key, YaRN ×36 from 8,192 with its temperature switched off, plus a Llama 4 style query scale 1 + 0.1 ln(1 + ⌊p/8192⌋), 1.358 at its last position 294,911 (the formula as transformers applies the same field for Ministral 3, ) | qk_rope_head_dim 64, yarn: factor 36, apply_scale false; llama_4_scaling: beta 0.1 | params (config.json) |
| Kimi K3 | No RoPE in any layer: 24 MLA layers run with mla_use_nope, and the 69 Kimi Delta Attention (linear) layers order tokens by their recurrence | mla_use_nope true, linear_attn_config.full_attn_layers (24 of 93) | config |
| Nemotron-H, Nemotron 3 Super, Granite 4.0-H, Jamba | No positions in the few attention layers; the Mamba layers carry order. Nemotron 3 Super's config still carries rope_theta 10000, but transformers 's modeling_nemotron_h.py defines apply_rotary_pos_emb and never calls it (Jamba's file the same); Granite says so directly. | Nemotron: rope_theta 10000 (unused); Granite: position_embedding_type "nope" | Nemotron 3 Super config, Granite config; detail on Beyond attention |
Raschka sorted the entries of his LLM Architecture Gallery (snapshot of 9 November 2026) by release date and position scheme. Directions only, since the shares are in his bar charts and the groups are small (his words): RoPE in every softmax attention layer is still the most common choice, but its share fell from 2025 to the first half of 2026 and again in the second half; RoPE and NoPE mixes grew; every NoPE-only entry is a recurrent hybrid; among RoPE entries, partial RoPE went from a minority to a majority. It is a count over one curated list, in which a family can appear several times, not a measurement of the field; this page's own census (the table at the top and the Every config tab) counts configs and does not track a trend. Read and discussed on Raschka's walkthrough, section 5.
The topic's tiny GPT trained five times changing only pos: learned, sinusoidal, ALiBi, NoPE and RoPE (base 10,000), same seed and batches, plus the sinusoidal model with its token embeddings × 16 and a second seed for RoPE and learned.
At 12.3M tokens and 5.8M parameters this ordering is weak evidence about large models. What transfers is what each scheme does once the input is longer than anything it saw, which depends on its arithmetic and not on scale: sections 6 to 8.
| Scheme | Position parameters | Held-out loss, 100 windows | Loss on the running sequence | Tokens/s (rough) | Greedy continuation of "Once upon a time" (first 90 characters) |
|---|
Root src/data: 6 layers, dmodel 256, 8 heads of 32, pre-norm LayerNorm, GELU, tied embeddings; 1,500 steps of 32 × 256 tokens (12.3M tokens), AdamW at 3 × 10−3 with cosine decay; measured on Apple M1 Pro (MPS, fp32), 2026-10-18. The learned run is the root's reference baseline and the RoPE run the Attention lab's MHA run; the other three were trained for this page with the same settings.
A model trained on length L has seen relative distances below L only, so pair i has seen angles from 0 to Lθi. A fast pair (wavelength shorter than L) has gone round, often many times, and every angle it meets later is familiar. A slow pair (wavelength longer than L) has only covered a wedge; the first distance beyond L pushes it to angles no training example produced, and the scores it feeds are untested. Position Interpolation's authors describe the result as "catastrophically high attention scores that completely ruin the self-attention mechanism" (Chen et al. 2023); ALiBi's authors measured rotary models gaining for only 100 to 200 tokens past their training length (Press et al. §2). Relative does not mean unbounded.
Fig. 5 runs one config through growing distances, first inside L, then out to the config's own target s × L, with plain RoPE (the method being replaced); Fig. 6 in section 7 holds that distance and applies each extension. Each dial is one pair: shaded is every angle it reached in training, the hand its angle now, orange outside the wedge; under it, its wavelength and its angle now against the largest one training produced. The strip in front shows all pairs, fastest on the left.
Fig. 5, step by step: plain RoPE from inside L to s × L
Frequencies from each config.json and the ports of Hugging Face's modeling_rope_utils.py, which agree with transformers 's own functions to on every preset (src/code/hf_check.py; Dynamic NTK as the YaRN paper defines it). Eight steps: a quarter of L, half, the edge, then five steps growing geometrically to s × L; the static numbers in the steps are Llama 3.1 8B's, and the chips redo them for another config. Each pair is judged alone, on its angle modulo one turn: a slow pair whose angle has wrapped back into its wedge has seen that angle, but never together with the other pairs' angles at this distance, so the counts are a lower bound on what is new to the model, and they do not say how often an angle was trained.
Every method rewrites the frequencies θi (equivalently, the positions they multiply) of a model that already uses RoPE, then usually fine-tunes briefly at the new length, with s = Lnew / L:
linear.llama3 rope type, July 2024): the same idea with boundaries set by wavelength. Pairs with a wavelength under L/4 = 2,048 tokens are kept, those over L = 8,192 are divided by 8, and a smooth blend covers those between: 29 kept, 6 blended, 29 divided in Llama 3.1 8B (recompute.py, from its config and ). The Llama 3 paper does not describe this scaling; it describes the long-context stage (section 9).Fig. 6, step by step: four methods at s × L
The same rules as curves, for any config: Fig. 6 shows eight pairs at one distance, the chart every pair's slow-down.
Try: pick the tiny GPT first: the measured losses under the chart are what each line did to its loss past 256. On Llama 3.1, YaRN and Llama 3 scaling agree at both ends and differ only in where the blend sits (YaRN by turns per pair, from L/32; Llama 3 by wavelength, from L/4). NTK-aware is a straight line on this chart: the base change slows pair i by si/(d/2 − 1). Pick Phi-3: LongRoPE's searched factors rise unevenly, in jumps rather than a smooth curve, and reach ÷64.8 on its slowest pair, twice its factor of 32, while its "short" factors stay near ÷1 to ÷3. Llama 4's config sets low_freq_factor and high_freq_factor both to 1, which collapses the blend into a single step at 8,192 tokens.
beta_slow 1, beta_fast 32); Hugging Face computes the ramp on the pair index between the two boundaries, rounded outwards unless truncate is falseapply_scale false).Each bar is one RoPE pair; its height is how many full turns it makes inside the original training context (log scale). Bars above β are kept, bars below α are divided by s, the rest are on the ramp.
Defaults reproduce: gpt-oss-120b's 9 kept, 9 on the ramp and 14 interpolated pairs and its temperature factor of 1.347 are the LLM Architecture Gallery's earlier figures, recomputed here independently from the config (carried from that page's 2026-10-02 build, which now links here). On DeepSeek-V3's decoupled key (base 10,000, 64 rotated dimensions, YaRN factor 40, original 4,096, beta_fast 32, beta_slow 1), 11 are kept, 12 on the ramp and 9 fully interpolated, for a 163,840-token ceiling; only the 64 rotated dimensions are stretched.
linear type divides the frequencies by the factor ().dynamic type uses a slightly different base, b · ((s l′/L) − (s − 1))d/(d−2) ().mscale 0.707 gives 1.590); V3 returned to 0.1 (V3 §4.3).Hugging Face's YaRN, verbatim (transformers , the lines that build the frequencies):
The RoPE tiny GPT, scaling applied at inference only, no fine-tuning, read on 24 windows of 2,048 tokens: 4 to 8 times past its training length at the end. The other schemes are the section 5 models, unchanged.
In round numbers: plain RoPE goes from 2.07 inside 256 to 3.82 at 1,024 to 2,047; YaRN ×8 holds 2.43 there; ALiBi stays at 2.07.
| Model | Scaling at inference | 0 to 255 | 256 to 511 | 512 to 1,023 | 1,024 to 2,047 |
|---|
The windows are the Long context sibling's, so the RoPE numbers agree with its to the fourth decimal. Measured on Apple M1 Pro (CPU, 4 threads, inference only, deterministic), 2026-10-18, by src/past/past_eval.py.
One input, moved. The running sequence (Roxy the rhinoceros, 256 tokens, never seen in training) is read with other validation stories in front of it, so the same tokens start at position 0, 128, 256, ... up to 1,536. Top: plain RoPE. Bottom: the method you pick, same text, same offset. The strip is Roxy's tokens in 32 cells of 8, coloured by loss (darker red is worse); the dials are the tiny GPT's 16 pairs at the furthest distance in the window; the box is the greedy continuation of Roxy's first 200 tokens.
The animation, step by step: Roxy moved along, plain RoPE against YaRN ×8
What transfers is the arithmetic: which pairs go out of range and when, that a scheme with nothing to go out of range stays flat, and the order of costs (PI most inside 256, NTK least, YaRN reaching furthest). What does not is the size of each gap: these stories average about 230 tokens, so far tokens matter little here; the large-model evidence is the papers' own curves and needle tests, not reproduced here.
Stories average about 230 tokens: 122,021,463 tokens over 529,875 stories (root src/data). The published long-context results (YaRN, PI, LongRoPE perplexity curves, needle tests) exist only as figures in their papers.
Not run here: fine-tuning each method at the new length (the recipes do this; two fine-tunes are the long_context sibling's, above), dynamic NTK (in one forward pass over 2,048 tokens it equals NTK-aware at s = 8 under the YaRN paper's definition, a calculation), LongRoPE (needs a factor search), and any pretrained model past its window (hours of CPU for little the toy does not already show).
src/past/past_eval.py, the function as run:
No current model trains its whole run at its final window. The pattern: pretrain short with a base chosen for the long target, extend in a short continued-pretraining stage on long documents with the positions rescaled, and check that short-context quality recovers. Llama 3.1 went from 8K to 128K in six stages over about 800B tokens; DeepSeek-V3 needed 1,000 steps at 32K and 1,000 at 128K; Gemma 3 rescaled "at the end of pre-training". The training side is on Data mixing, curricula and continued-pretraining ratios (sections 5 to 7, which hold the former CPT page) and Pretraining; whether a model then uses its window is the Long context sibling's subject.
rope_scaling "only when processing long contexts is required", and setting the factor to the need (2.0 for 65,536 tokens) (Qwen3-8B card). Its hosted endpoint uses dynamic YaRN instead. On the tiny GPT: | Model | Pretraining | Long-context stage | Positions | Window |
|---|---|---|---|---|
| Llama 3.1 | 8K, base 500,000 | Six stages from 8K to 128K over about 800B tokens; each stage ends when short-context evaluations have fully recovered and needle-in-a-haystack retrieval is perfect up to that length (Llama 3 page) | Released config: llama3 scaling, factor 8 over 8,192 | 128K |
| Qwen3 | 4,096 for the general stages | Hundreds of billions of tokens at 32,768, base raised from 10,000 to 1,000,000 (ABF) (Qwen3 page) | YaRN ×4 plus Dual Chunk Attention at inference, off by default | 32,768 native, 131,072 with YaRN (card) |
| DeepSeek-V3 | 4K | 1,000 steps at 32K (batch 1,920), then 1,000 at 128K (batch 480), learning rate 7.3 × 10−6 (report §4.3) | YaRN s = 40, α = 1, β = 32 on the decoupled key | 128K |
| DeepSeek-V4-Pro | Original length 65,536 (config) | Not in hand on 2026-10-18 (unconfirmed) | YaRN ×16 on the 64-dimension decoupled key; every pair already turns at least once within 65,536, so none is fully interpolated (21 kept, 11 on the ramp) | 1,048,576 (config) |
| Gemma 3 | 32K; local layers base 10,000, global 1,000,000 | Rescaled "at the end of pre-training" (report §5.3) | PI ×8 on the global layers | 128K |
| SmolLM3 | 4K | 4K to 32K with base 1.5M, then 32K to 64K with base 5M, 50B tokens each (blog) | NoPE in every 4th layer; YaRN to 128K at inference | 64K trained, 128K with YaRN |
| Olmo 3 | Original length 8,192 (config) | Extended to 65,536 (config); stage details not checked here | YaRN ×8, base 500,000 | 65,536 (config) |
| Llama 4 Scout | "Both pre-trained and post-trained with a 256K context length" (Meta blog) | iRoPE: NoPE every 4th layer, temperature on those layers; base config llama3 ×8, Instruct config ×16 with low = high = 1 | 10M claimed | |
| Phi-3-mini-128k | 4K default | LongRoPE (report §2) | 48 searched factors | 128K |
NoPE learns order from the causal mask (section 1: the probe finds position in its middle blocks). Kazemnejad et al. found NoPE "outperforms other explicit positional encoding methods" on their length-generalisation tasks and showed it "can represent both absolute and relative PEs, but when trained with SGD, it mostly resembles T5's relative PE attention patterns" (NeurIPS 2023). At scale, NoPE alone "lags behind" RoPE on standard benchmarks, although in needle tests it put the most attention on the needle (Yang et al. 2025). Hence the hybrids in section 4: Cohere's RNoPE-SWA (RoPE in sliding-window layers, NoPE in one full-attention layer of four) reached 256K with "almost no loss" on needle tests and trains "nearly 2x faster at 128k", shipped in Command A; Llama 4 adds a position-dependent temperature on its NoPE layers ("inference time temperature scaling", from Scalable-Softmax); SmolLM3 found that removing RoPE from every 4th layer "improves long context performance without affecting short context capabilities". In 2026 hybrids (Kimi K3, Nemotron 3 Super, Granite 4.0-H) the attention layers carry no positions at all, because the recurrent layers between them already see tokens in order. What a long context costs to serve (windows, KV compression, sparse attention) is on Long context and Attention variants, the benchmarks on Long-context and multimodal benchmarks.
All closed; the measured mistakes run on the tiny GPT. The pairing-layout and sinusoid-scale mistakes are in sections 3 and 2.
rope_theta into a checkpoint's configoriginal_max_position_embeddings to the new lengthrope_theta, so the model uses RoPE"rope_theta 10000; transformers 's modeling_nemotron_h.py defines apply_rotary_pos_emb and calls it nowhere (counted by src/code/code_refs.py: ). Read the modeling code of hybrids before quoting their position scheme.max_position_embeddings.config.rope_parameters), compare original_max_position_embeddings with the paper's pretraining length, compute the inverse frequencies with the library's function and with your own, and measure loss per position band on long held-out documents with and without the scaling: a correct setup costs a little below the original length and saves a lot beyond it (section 8).Each row is the config's own method at its own factor. "Kept / blended / ×s" counts pairs at ÷1, in between, and at ÷s; "Logit ×" is the attention temperature the method applies (YaRN (0.1 ln s + 1)2; LongRoPE 1 + ln s / ln L, the square of Hugging Face's attention_factor); the last column compares s × L with the config's max_position_embeddings.
| Model | Base | Rotated dims | Trained L | Method and parameters | Kept / blended / ×s | Logit × | s × L / max | Source |
|---|---|---|---|---|---|---|---|---|
| Llama 3.1 8B | llama3: factor 8, low 1, high 4 | config (mirror) | ||||||
| Llama 4 Scout | llama3: factor 16, low 1, high 1; RoPE layers only | config (mirror) | ||||||
| Qwen3-8B | yarn: factor 4, original 32,768 (added by the user; the config ships rope_scaling null) | model card, config | ||||||
| DeepSeek-V3 | yarn: factor 40, beta_fast 32, beta_slow 1, mscale 1; decoupled key only | config | ||||||
| gpt-oss-120b | yarn: factor 32, beta_fast 32, beta_slow 1, truncate false | config | ||||||
| Phi-3-mini-128k | longrope: 48 long and 48 short factors | config | ||||||
| Gemma 3 27B | linear (PI): factor 8 on global layers; pretrained at 32K | config (mirror), report §5.3 | ||||||
| Tiny GPT (this topic) | yarn: factor 8 to reach the 2,048-token evaluation, orig 256 (set at inference; measured in Reading section 8) | root src/data/tiny_gpt.py | ||||||
| DeepSeek-V4-Pro | yarn: factor 16, original 65,536, beta_fast 32, beta_slow 1; decoupled key only | config | ||||||
| Olmo 3 32B | yarn: factor 8, original 8,192 | config | ||||||
| Mistral Large 3 | yarn: factor 36, original 8,192, beta 32, alpha 1, apply_scale false; decoupled key only | config | ||||||
| Kimi K2 | yarn: factor 32, original 4,096, beta_fast 1, beta_slow 1; decoupled key only | config |
Defaults reproduce: gpt-oss-120b's 9 kept, 9 on the ramp and 14 interpolated pairs, and its logit factor of about 1.347 squared, are the Architecture Gallery's figures, recomputed here independently from the config with the ramp ported from Hugging Face's code. DeepSeek-V3's 40 × 4,096 = 163,840 and Phi-3's 32 × 4,096 = 131,072 equal their configs' max_position_embeddings (independently); Qwen3's 4 × 32,768 = 131,072 is the card's 131,072 by construction. Llama 3.1's 65,536 is half its 131,072 window (see Reading, section 11); DeepSeek-V4-Pro's 16 × 65,536 = 1,048,576 and Mistral Large 3's 36 × 8,192 = 294,912 equal theirs. Mistral Large 3's logit factor is shown as 1 because its config switches the YaRN temperature off. Every port agrees with transformers 5.20.1's own functions (src/code/hf_check.py). Gemma 3's trained length of 32K is from its report, not its config. Mirrors are used where the official repository is gated, and the values were checked against the papers where they state them.
The census behind Reading's base chart: what carries position in every config this topic holds, field by field (src/census/census.py). "Rotated dims" is the number of dimensions RoPE turns per head (head × partial factor, or the decoupled key); "longest wavelength" is the slowest pair's, in tokens.
| Repository | Scheme | Base | Rotated dims | Longest wavelength | Max positions | Scaling | Notes |
|---|
Links open in a new tab; checked 2026-10-18. Times are estimates (knowledge base pages: their Reading tab at 230 words a minute, as their headers state). "Maker" means written by the people who built the method; "third-party" means not.
Why positions, the four answers (absolute, relative bias, rotation, nothing), RoPE derived, bases and variants read from 74 configs, five schemes trained here, what breaks past the trained length (animated on real configs), the scalings drawn per pair and measured on the tiny GPT (the running story moved past 256), recipes, and closed blocks for depth, mistakes and design questions.
Twelve configs with their scaling worked out per pair, and the census of every config's position fields.
The parent: one token through one block and the alternatives for every component; its Block lab, Config calculator, Inside a real model and Architecture map tabs use the same tiny GPT and configs.
The memory and compute side: KV growth and compression, local and global attention, effective context. Its past-length measurements use the same windows as this page.
What each token stores: MHA, GQA, MLA (and why its RoPE key is decoupled), sliding windows, sparse attention, sinks.
The whole block from an empty file, including the ablation that removes positions.
SSMs, linear attention and hybrids, the models whose attention layers carry no positions.
Reading a model card and the per-layer strips of 2026 open models, position included.
What a position counts: one token, not one word or one character.
The RoPE original: eight-pair dials, the shift test on trained weights, Figure 2's decay and its caveat, toy models run past their training length, the spectrum from 2017 to Llama 4.
The sinusoidal encoding, with a heatmap and offset curve, and a toy model retrained without positions.
The relative bias buckets, computed with T5's own function.
Base 500,000 and the six-stage, 800B-token extension to 128K.
ABF to 1,000,000, YaRN and Dual Chunk Attention.
MLA's decoupled RoPE key and the two-phase YaRN extension; the DeepSeek MLA explainer animates it.
The long-context extension stage as a training problem (it holds the former Continued Pretraining page): data, replay, learning rates, forgetting.
How a stretched window is checked: needle tests, RULER and their limits.
Aman Arora, September 2025 (third-party): the best single walkthrough of RoPE, Position Interpolation, NTK-aware, dynamic NTK, NTK-by-parts and YaRN, with code. (50 min)
Sebastian Raschka, November 2026 (third-party): the gentlest correct derivation of RoPE, pair by pair on one sentence with PyTorch asserts (the shift test), then a census of his gallery by position scheme; skip its verdict on partial RoPE. Our article page checks every number. (15 min)
EleutherAI, April 2021 (third-party, with the RoPE authors' input): the canonical explainer with derivation and comparisons against learned and T5 positions. (30 min)
Press, Smith, Lewis 2021 (maker): the linear bias, and the measurement of how far sinusoidal, rotary and T5 positions extrapolate. (45 min)
Peng et al. 2023 (maker): NTK-aware, dynamic and by-parts scaling formalised, the temperature, and the experiments. (45 min)
Chen et al. 2023 (maker): why extrapolation fails, the interpolation bound, 32K in 1,000 steps. (30 min)
Kazemnejad et al. 2023 (maker): the NoPE case. (40 min)
Yang et al. (Cohere) 2025 (maker): the RoPE and NoPE hybrid behind Command A, with attention-mass analysis. (35 min)
Barbero et al. 2024 (third-party analysis): what a trained model actually uses each RoPE frequency for. (40 min)
Hugging Face (implementer): every RoPE type the configs on this page name, as code. (20 min)