Positional Encodings

How a transformer knows where each token is: learned and sinusoidal tables, relative biases (T5, ALiBi), RoPE as a rotation, its base and variants read from 74 real configs (partial, decoupled, NoPE layers), what breaks past the trained length, and the scalings that stretch it (PI, NTK, YaRN, Llama 3, LongRoPE). Five schemes trained here on the topic's tiny GPT and run past their length (Apple M1 Pro). A child of Topic: llm-architecture. Data as of October 2026. Reading: 40 min, plus 21 in closed details.

The idea in one screen

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

  1. A head is a row of dials. The tiny GPT (head 32, base 10,000, trained on 256 tokens) has 16 pairs of dimensions, each a dial turning at its own speed: pairs 0 to 6 in the front row, 7 to 15 behind. After one token pair 0 has turned 1 radian (57°) and pair 15 has barely moved. Under each dial, its wavelength: 6.3 tokens for pair 0 up to 35,333 for pair 15.
  2. Training covers 256 tokens. Shaded is every angle a pair reached in training: pairs 0 to 6 turn at least once within 256 tokens (full disc, blue), so they have seen every angle; pairs 7 to 15 only cover a wedge (green), pair 15 just 2.6 degrees.
  3. Distance 300, just past the trained 256. All nine slow pairs point outside their wedges (orange), at angles no training example produced, while the fast pairs point at angles they have seen many times. The scores those slow pairs feed are untested.
  4. YaRN ×8 slows the slow dials. The tiny GPT's own scaling divides the frequency of pairs 7 to 15 by 8 (÷ above each dial), ramps pairs 1 to 6 between ÷1.14 and ÷4 and keeps pair 0: at distance 300 every hand is back inside the angles it learned.
  5. And at 2,048, eight times the trained length, every hand is still inside. That is all a context-extension method does; section 8 measures what it buys on real text.

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.

Absolute, relative
"where is this token" (added once to the input) against "how far apart are these two" (acting on each attention score, in every layer).
Embedding, encoding
a learned table of position vectors against a fixed function of position. The naming is loose: RoPE is "rotary position embedding" although nothing in it is learned.
Pair, θi, wavelength
RoPE turns dimensions two at a time; pair i turns θi radians per token and completes a turn every λi = 2π/θi tokens.
Base
rope_theta: θi = base−2i/d, so a larger base makes the slow pairs slower.
L, s
the length the model was pretrained at, and the stretch factor s = Lnew / L.
Fast, slow pair
wavelength shorter or longer than L: a fast pair has seen every angle in training, a slow pair only a wedge.
NoPE, partial RoPE
no position signal at all (the causal mask still orders tokens); rotating only some of a head's dimensions.
The six schemes in one table, with the tiny GPT's measured losses (reference)
SchemeWhat it changesLearned?Past the trained lengthTiny GPT, held-out loss at 256 measuredTiny GPT, loss at 1,024 to 2,047 measuredIn the 2026 configs read here
Learned absoluteAdds one trained vector per position to the inputYes, one row per positionNo row exists: a hard errorGPT-2, BERT; none of the 2026 models
SinusoidalAdds fixed sines and cosines to the inputNoDefined, but the model never saw those vectorsThe 2017 Transformer
T5 biasAdds one learned scalar per distance bucket to each score, per headYes, 32 per headAll distances from 128 on share one bucketnot run herenot run hereT5 and its descendants; Inkling (2026) learns a relative bias of its own, form unconfirmed
ALiBiSubtracts slope × distance from each scoreNo, a fixed slope per headNothing goes out of rangeBLOOM, MPT (2022 to 2023)
RoPERotates each pair of query and key dimensions by position × frequency, in every layerNoSlow pairs meet unseen angles; fixed by RoPE scaling of the configs
NoPENothing; the causal mask is the only order signalNoNo angles to break, but attention past the trained length is still untrainedSome 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.

1. Why attention needs positions at all

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

  1. Shuffle the first 255 tokens; NoPE's first block does not notice. Each column is how much token 255's residual stream changes, ‖h − hshuffled‖ / ‖h‖, after the embedding (column 0) and after each of the six blocks, on the running sequence. For NoPE the change after block 1 is 2 × 10−7, rounding error: one layer sees a set.
  2. Its second block does. From block 2 on NoPE's change grows (4% after block 2, 45% after block 6): each earlier token saw a different prefix, so the stack can count.
  3. Every scheme with positions notices at once. Learned and sinusoidal (the run with embeddings × 16) change by 21% and 42% after block 1, because the shuffle moved their position vectors; ALiBi by 39% and RoPE by 5%, because their scores depend on distances.
  4. Now the probe: where position is written. The same columns, now R2 of the linear probe. The learned and sinusoidal schemes write position into the input (0.99 and 0.98 at the embedding); NoPE has none there (−0.04) and builds it in the middle blocks, 0.94 by block 3 and 0.97 by block 4.
  5. RoPE and ALiBi leave little in the stream. Their R2 stays at or below about 0.27 in every block: a relative scheme acts inside attention, on q and k or on the scores, and never needs to write an absolute position anywhere.
Predict: in the NoPE model, where does a linear probe find absolute position best?

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.

2. Four answers: add a vector, bias the score, rotate, or nothing

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

  1. One token, twice. The same 64-number content vector (seeded random, illustrative) sits at the key, position 16, and again 4 tokens later as the query, position 20. Content alone scores 9.19 in every lane (q · k / √d with q = k); the bar shows what position does to it.
  2. Add a vector (sinusoidal). The sinusoids p(16) and p(20) are added to the two inputs before anything else; their cross terms with the content and with each other add +4.28 to the score. Position now lives in the residual stream, mixed with content.
  3. Bias the score (ALiBi, head 1). Nothing touches the vectors; the score gets −slope × distance = −0.5 × 4 = −2.00, in every layer. T5 does the same with one learned scalar per distance bucket.
  4. Rotate q and k (RoPE). Each pair of the query and the key is turned by its position times its frequency (pair 0 drawn, 1 radian per token); the score drops by 2.93, and that number depends only on the distance.
  5. Nothing (NoPE). The score is content alone; only the causal mask orders the tokens.
  6. Move both tokens 256 places along. Key at 272, query at 276, the same distance. Only the absolute lane changes, from +4.28 to +5.96 (its old bar dotted): the same two tokens at the same distance get a different score at a different place. ALiBi, RoPE and NoPE give exactly what they gave before; RoPE's hands turned, the angle between them did not.

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.

Only the absolute schemes change when the same pair of tokens moves along the sequence

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).

The exact formula behind each curve (depth)
Sinusoidal, learned
(x + pm)·(x + pm−k)/√d − x·x/√d = (x·pm−k + pm·x + pm·pm−k)/√d, with the 2017 sinusoid or a random 512-row table (illustrative, untrained)
T5
bh(bucket(k)): the real learned biases of T5-base's decoder self-attention (32 buckets × 12 heads, read by byte range from the released safetensors file), bucketed by T5's own function
ALiBi
−mh·k, with the paper's 8-head slopes mh = 2−h
RoPE
Σi (x2i2 + x2i+12)(cos kθi − 1)/√d, θi = base−2i/d
NoPE
0

Absolute: a learned table, or fixed sinusoids

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:

PE(m, 2i) = sin(m / 100002i/d),   PE(m, 2i+1) = cos(m / 100002i/d)
m, i, d
position, frequency index (0 to d/2 − 1) and model width; each pair of dimensions is a clock, from one radian per token down to 1/10,000
sin and cos together
for any offset k, PE(m + k) is a fixed rotation of PE(m), so PE(m) · PE(n) depends only on m − n; the cross terms with content do not, which is why the scheme stays absolute

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.

Relative biases: T5 and ALiBi

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, DeBERTa, MPT's slopes, the T5 outlier bucket and the code (depth)

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 ).


Measured mistake: sinusoids need the √d scale
Without the scale the model ends at 4.29 against 2.29 with it.

3. RoPE from zero: position as a rotation

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

  1. One pair, real numbers. Take θ = 0.5 radians per token and q = k = (1, 0). At m = 3 and n = 5 the query is turned by 1.5 radians to (0.0707, 0.9975) and the key by 2.5 radians to (−0.8011, 0.5985); their dot product is 0.0707 × (−0.8011) + 0.9975 × 0.5985 = 0.5403 = cos(1.0).
  2. Move both along. At m = 10, n = 12 the angles become 5 and 6 radians: both hands have turned, the gap is still 1 radian, and the dot product is again 0.5403. θ = 0.5 is illustrative; real pairs run from 1 radian per token down to millionths.
  3. A head is 16 such pairs. A query and a key of the tiny GPT's head shape (32 numbers each, seeded random, illustrative) as 16 dials: in each, the query's pair (orange) and the key's pair (teal) as 2-D vectors. Under each dial, that pair's share of the dot product; unrotated, the shares sum to q · k = −0.91.
  4. Query at 20, key at 24. Pair i of each vector is turned by its position × θi, pair 0 by 1 radian per token and pair 15 by 0.00018: the shares change and sum to −1.79.
  5. Shift both by 100. Query at 120, key at 124: every hand turns, the fast pairs by many turns, yet each pair's share and the total, −1.79, are exactly as before. The score sees only the distance.
  6. Change the distance to 60. Query at 120, key at 180: the fast pairs' shares swing (pair 0 from 0.00 to 0.89) while the slow ones barely move (pair 15 from −0.49 to −0.48); the total becomes −6.40. Fast pairs resolve neighbouring tokens, slow pairs measure long distances.
(R(mθ) q) · (R(nθ) k) = qT R(mθ)T R(nθ) k = qT R((n − m)θ) k
why
a rotation's transpose is its inverse, and two rotations compose by adding their angles: R(α)T R(β) = R(β − α)
in complex numbers
read the pair as q0 + iq1; rotating is multiplying by eimθ, and Re[(q eimθ)(k einθ)*] = Re[q k* ei(m−n)θ]

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).

θi = base−2i/d,   λi = 2π / θi = 2π · base2i/d tokens,   ⟨Rmq, Rnk⟩ = ⟨q, Rn−mk⟩
Rm
the block-diagonal rotation for position m: pair i turned by mθi
base
10,000 in the paper and the tiny GPT; 500,000 in Llama 3; 1,000,000 in Qwen3; up to 1011 in the configs read below
Predict: Llama 3.1 8B has 64 pairs, base 500,000, and was pretrained at 8,192 tokens. How many of its pairs completed at least one full turn within 8,192 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.

The code: transformers and the tiny GPT, and its measured speed (depth)

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).

Interleaved or split-half pairing, and what loading the wrong one does (depth, measured)

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.

4. The base and the variants, read from the configs

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).

transformers 5 renamed the field
From transformers 5, configs are standardised to 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.

Bases have climbed from 10,000 to 106 and beyond as context grew

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.

Which layers carry RoPE: eight 2025 to 2026 configs, one cell per layer

RoPE, local window RoPE, full attention RoPE, full attention, larger base or few pairs no positions, full attention linear attention or SSM (no positions)

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).

Same idea, opposite spectra: Qwen3-Next keeps the slow clocks, Gemma 4's global layers keep only fast ones

Every variant, with its config fields verbatim and sources (reference)
ModelWhat carries positionConfig fields (verbatim)Source
GPT-NeoX-20BRoPE on 25% of each head's dimensions; the rest position-freerotary_pct 0.25, rotary_emb_base 10000config, paper
Phi-2RoPE on 40% of the headpartial_rotary_factor 0.4config
GLM-4.5RoPE on half of each 128-dimension headpartial_rotary_factor 0.5, rope_theta 1000000config
MiniMax-M3RoPE on half of each 128-dimension head, over a million positionshead_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 512config, 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 160000V3 config, V4-Pro config, V3 report §4.3
Qwen2-VL-7BM-RoPE: the 64 frequency pairs split 16 / 24 / 24 among time, height and widthmrope_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 8report §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 150000config
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 8192Meta 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_gptjreport, config (mirror)
SmolLM3-3B
RoPE removed "from every 4th layer"; all layers attend fullyno_rope_layer_interval 4, rope_theta 5000000blog, 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.1params (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 recurrencemla_use_nope true, linear_attn_config.full_attn_layers (24 of 93)config
Nemotron-H, Nemotron 3 Super, Granite 4.0-H, JambaNo 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
The trend in one curated gallery, as of 9 November 2026 (dated reading)

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.

5. Measured here: five schemes on the tiny GPT, equal budgets

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.

Inside the trained length the relative schemes lead, NoPE trails, and most gaps are near seed noise

SchemePosition parametersHeld-out loss, 100 windowsLoss on the running sequenceTokens/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.

6. What breaks past the trained length

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.

Correction to the old page
It said RoPE fails past L "because high-frequency dims see unseen rotation angles". It is the other way round: the low-frequency pairs, whose wavelength exceeds L, are pushed into unseen angles, which is why YaRN leaves high frequencies alone and interpolates the low ones fully (YaRN §3.2). High frequencies matter for the opposite reason: squeezing them (as Position Interpolation does) blurs neighbouring tokens. On the tiny GPT the slow pairs are pairs 7 to 15, wavelengths 353 to 35,333 tokens.

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

  1. A quarter of L: 2,048 tokens. The eight dials are pairs picked evenly from the fastest to the slowest of Llama 3.1 8B (base 500,000, 64 pairs, trained at 8,192); the strip in front is every pair, fastest on the left. The 35 fast pairs (wavelength under L) have seen every angle; the slow ones are a quarter of the way through their wedges.
  2. Half of L: 4,096. The slow hands are halfway along their wedges; nothing is new.
  3. The edge: 8,191. Every slow hand stands at the end of its wedge, the largest angle training produced.
  4. Just past: 12,417. 26 of 64 pairs now point at angles no training example produced (orange), while the fast pairs point at angles they have seen many times.
  5. 18,820 tokens: 25 pairs out of range. A slow pair whose angle has wrapped round into its wedge again counts as seen, so the count can dip.
  6. 28,526 tokens: 25 out of range.
  7. 43,238 tokens: 24 out of range.
  8. The config's own target, s × L = 65,536. 24 pairs at unseen angles, every slow pair turned about 8 times its trained angle: these are the pairs every method of section 7 slows down.

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.

7. Stretching RoPE: the context-extension methods

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:

  • Position Interpolation (PI), Meta, June 2023: divide every position by s, so all angles stay inside the trained range. LLaMA 7B to 65B reached 32,768 tokens "within 1000 steps" of fine-tuning, with "minor degradation" on the original 2,048-token window, regressions of up to 2% on standard benchmarks (Chen et al.). The cost: the fast pairs are slowed by s too, so neighbouring tokens look s times closer. Gemma 3 uses it: pretraining at 32K, then "a scaling factor of 8" on the global layers for 128K (Gemma 3 §5.3); Hugging Face's type is linear.
  • NTK-aware, bloc97, June 2023: raise the base instead, b′ = b · sd/(d−2) (YaRN Eq. 16), "scaling high frequencies less and low frequencies more": pair 0 is untouched and the slowest pair is slowed by exactly s. For the tiny GPT (d = 32) at s = 8, b′ = 91,896 (recompute.py). Good with no fine-tuning, but some pairs end slightly past their trained angles. Dynamic NTK (emozilla) sets s = max(1, l′/L) from the current length l′ at every step, so short inputs run unchanged.
  • YaRN, Peng et al., August 2023: keep pairs that turn more than β times within L (32 for Llama), divide by s those that turn less than α times (1), ramp between, and sharpen the logits with a temperature (formula below). It needed "10x less tokens and 2.5x less training steps than previous methods": Llama 2 7B and 13B were fine-tuned 400 steps at s = 16 (64K) and 200 more at s = 32, which then extrapolated to 128K (Peng et al.). DeepSeek-V2, V3 and V4, Qwen3, gpt-oss, Olmo 3, Kimi K2 and Mistral Large 3 ship it in their configs, and SmolLM3 at inference.
  • Llama 3 scaling (the 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).
  • LongRoPE, Microsoft, February 2024: one rescaling factor per pair, found by evolutionary search, extending "to an impressive 2048k tokens, with up to only 1k fine-tuning steps at within 256k training lengths" on LLaMA2 and Mistral (Ding et al.). Phi-3-mini's 128K version uses it.

Fig. 6, step by step: four methods at s × L

  1. Plain RoPE at s × L = 65,536. Fig. 5's last step on Llama 3.1 8B: 24 pairs at unseen angles. From the next step the strip's height is how much a method slows each pair (log scale, full height ÷8), and the ÷ under each dial is the same number.
  2. Position Interpolation: every pair ÷8. All hands are back inside (0 out of range), but the fast pairs are slowed as much as the slow ones: neighbouring tokens now look 8 times closer, the cost PI pays inside the trained length.
  3. NTK-aware: raise the base to 4,134,231. Pair 0 is untouched and the slowest pair ÷8, a straight ramp between. The middle pairs are slowed less than they need: the fastest slow pair still turns 2.5 times its trained angle (plain: 8 times), and 25 pairs end at unseen angles.
  4. YaRN: keep the fast pairs, divide the slow ones. 19 pairs kept (more than β = 32 turns within L), 29 divided by 8 (less than α = 1 turn), 16 on the ramp between: 0 out of range, and neighbouring tokens keep their resolution.
  5. Llama 3 scaling: the same idea, by wavelength. 29 kept (wavelength under L/4 = 2,048), 29 divided by 8 (wavelength over L), 6 blended: 0 out of range. The config's own method: Llama 3 scaling.

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.

YaRN: θ′i = (1 − γ(ri)) θi/s + γ(ri) θi,   γ(r) = clamp((r − α)/(β − α), 0, 1),   logits × (0.1 ln s + 1)2
ri
L / λi, turns of pair i within the trained length
α, β
1 and 32 for Llama (DeepSeek and gpt-oss configs: beta_slow 1, beta_fast 32); Hugging Face computes the ramp on the pair index between the two boundaries, rounded outwards unless truncate is false
(0.1 ln s + 1)2
the temperature, from √(1/t) = 0.1 ln s + 1 (Eqs. 17, 18, 22): 1.297 at s = 4, 1.459 at 8, 1.813 at 32, 1.874 at 40. It sharpens a softmax that flattens when attention spreads over more tokens. It is one of a family of logit scalings that grow with the log of the context length: softmax's recall capacity grows exponentially with its sharpness, so a context M times longer needs a sharpness that grows only like log M (the reason is derived in the transformers-from-memory article; the other members are in the closed block below). Hugging Face multiplies both cos and sin by 0.1 ln s + 1, so q · k picks up its square. Mistral Large 3 switches it off (apply_scale false).

Each method is a rule for how much to slow each pair: PI all of them, NTK a straight line, YaRN and Llama 3 only the slow ones

Which pairs YaRN keeps, ramps and interpolates, on eight configs (depth)

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.

Provenance and finer points: the original posts, Hugging Face's dynamic base, LongRoPE2, the log-length logit scalings, DeepSeek-V2's temperature, the code (depth)
  • PI's bound. The interpolation bound is "at least ∼600× smaller" than extrapolation's (Theorem 2.1 of Chen et al.); f′(x, m) = f(x, mL/L′). Hugging Face's linear type divides the frequencies by the factor ().
  • NTK-aware, worked. For base 10,000, d = 128 and s = 4, b′ = 40,890. The original posts: NTK-aware, dynamic (Dynamic NTK as defined in YaRN §3.3). Hugging Face's dynamic type uses a slightly different base, b · ((s l′/L) − (s − 1))d/(d−2) ().
  • Phi-3's LongRoPE factors (Phi-3 report §2): 48 "long" factors from 1.07 to 64.76 and 48 "short" ones (1.10 to 3.05).
  • LongRoPE in Hugging Face picks the long factors only when the sequence is longer than the original 4,096 (); Phi-3 calls it "a long context version via LongRope". LongRoPE2 (February 2025) blames the remaining failures on "insufficient training in higher RoPE dimensions", searches the factors with a "needle-driven" perplexity, and adds "mixed context window training" that keeps the original RoPE for short sequences; it extends LLaMA3-8B to a 128K effective length "while retaining over 98.5% of short-context performance, using only 10B tokens", 80 times fewer than Meta's own extension (Shang et al.). LongRoPE also searches progressively, then readjusts at 8K to recover short-context quality.
  • Log-length logit scalings, side by side. With a reference length L and context M: Su (2021) multiplies every logit by log M / log L; the original Qwen's LogN applies the same factor only past L; Scalable-Softmax learns the factor on log M; Llama 4's NoPE layers scale the query by 1 + 0.1 ln(⌊(p+1)/8192⌋ + 1) (section 4's table); and Qwen2.5-1M (§5.1) applies YaRN's (0.1 ln s + 1)2 with s defined as the inference length over the training length, so the factor follows the actual context instead of a fixed config value. In Alex Wang's simulation of random keys (sharpness 8 at L = 1,024, key size 64), plain softmax's interference reaches the signal near 1.2 million keys, while Su's and LogN's rules hold it at about 0.004 of the signal at 2 million and YaRN's at 5.9 × 10−5 (recomputed from his released data on our article page).
  • DeepSeek's temperature. DeepSeek-V2 used 0.0707 instead of 0.1 (√t = 0.0707 ln s + 1, chosen "aiming at minimizing the perplexity", DeepSeek-V2 report; its config's 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):


8. What each method buys, measured on the tiny GPT

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.

Predict before reading on: with no scaling and no fine-tuning, which scheme has the lowest loss at 1,024 to 2,047 tokens, 4 to 8 times its training length?

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.

Predict: YaRN at s = 8 changes two things, the frequencies and a temperature of 1.459 on the logits. On the tiny GPT at 1,024 to 2,047 tokens, which one does most of the work?

Plain RoPE and NoPE climb past 256; ALiBi stays flat; every RoPE scaling flattens the climb at some cost inside 256

Every measured row, by position band (table)
ModelScaling at inference0 to 255256 to 511512 to 1,0231,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.

Same text, same weights: as the story moves past 256, plain RoPE's continuation falls apart and YaRN's holds

Before: plain RoPE
After:

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

  1. Roxy at 0 to 255, inside the trained window. Every pair is in range. Plain RoPE's mean loss on Roxy's tokens is 1.74; YaRN ×8 gives 1.94, which is what the method costs on text the model handles fine.
  2. 128 to 383, partly past 256. At the far end of the window 8 of plain RoPE's 16 pairs are at unseen angles; plain 1.90, YaRN ×8 2.03.
  3. 256 to 511: Roxy starts at the trained edge. Plain 2.40 (8 pairs out), YaRN ×8 2.20: the lines cross.
  4. 384 to 639. Plain 2.87, YaRN ×8 2.11.
  5. 512 to 767. Plain 3.38, and its continuation stops following the story; YaRN ×8 2.26.
  6. 768 to 1,023, three to four times the trained length. Plain 3.56, YaRN ×8 2.10.
  7. 1,024 to 1,279. Plain 3.87, YaRN ×8 2.14.
  8. 1,536 to 1,791, up to seven times the trained length. Plain 3.99, YaRN ×8 2.19. Same text, same weights: only the positions are treated differently.

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.

Not run here, and the code that produced the offsets (depth)

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:


9. Recipes in production

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.

Static scaling costs short inputs: measured
Qwen's card: the open-source frameworks "implement static YaRN, which means the scaling factor remains constant regardless of input length, potentially impacting performance on shorter texts", so it advises adding 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:
Eight models' pretraining length, extension stage and position settings (reference)
ModelPretrainingLong-context stagePositionsWindow
Llama 3.18K, base 500,000Six 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,192128K
Qwen34,096 for the general stagesHundreds 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 default32,768 native, 131,072 with YaRN (card)
DeepSeek-V34K1,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 key128K
DeepSeek-V4-ProOriginal 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 332K; local layers base 10,000, global 1,000,000Rescaled "at the end of pre-training" (report §5.3)PI ×8 on the global layers128K
SmolLM34K4K 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 inference64K trained, 128K with YaRN
Olmo 3Original length 8,192 (config)Extended to 65,536 (config); stage details not checked hereYaRN ×8, base 500,00065,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 = 110M claimed
Phi-3-mini-128k4K defaultLongRoPE (report §2)48 searched factors128K

10. Beyond RoPE

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.

CoPE, FoPE, HoPE and wavelet positions: research not yet used at scale (depth)
  • CoPE (Contextual Position Encoding, Meta, 2024). Positions are counted, not indexed: each key gets a gate gij = σ(qi·kj), the position of key j from query i is the sum of the gates between them, and fractional positions interpolate between learned integer embeddings (§4). A head can therefore measure "the i-th sentence" or "the i-th verb" instead of tokens. It solves the selective copy, counting and Flip-Flop tasks where standard encodings fail and improves perplexity on language modelling and code (Golovneva et al.). Not run here: it needs a trained model and a counting task to mean anything.
  • Fixing the spectrum. FoPE (Fourier Position Embedding, ICML 2025) treats each dimension as a Fourier series and "zero-outs the destructive frequency components", those insufficiently trained because of truncation. HoPE (2024) argues "long-term decay is outdated" and keeps "only high-frequency signals", replacing the others with position-independent components, which is close to what Gemma 4's proportional RoPE ships. Wavelet-based positions (ICLR 2025) capture several window sizes at once "without limiting the model's attention field".

11. Depth: common mistakes and design questions

All closed; the measured mistakes run on the tiny GPT. The pairing-layout and sinusoid-scale mistakes are in sections 3 and 2.

Running a learned-position model past its table
It fails loudly, which is the good case (the IndexError in section 2). The fix is a scheme without a table, or retraining the table at the new length; there is nothing to stretch.
Copying another model's rope_theta into a checkpoint's config
Setting original_max_position_embeddings to the new length
Turning on YaRN for every request
"The config has rope_theta, so the model uses RoPE"
Nemotron 3 Super's config says 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.
"NTK scaling means a base like 500,000"
NTK-aware scaling for s = 4 at d = 128 takes 10,000 to 40,890. 500,000 is Llama 3's pretraining base, chosen before training (ABF, Xiong et al.), not a scaling applied to a trained model.
"factor × original length = the context window"
Llama 3.1's 8 × 8,192 = 65,536 is half its configured 131,072; the model was trained at 128K in its long-context stage, so the rescaled spectrum does not have to cover the window on its own. Gemma 3's 8 × 32,768 = 262,144 is twice its 131,072. DeepSeek-V3's 40 × 4,096 = 163,840, Phi-3's 32 × 4,096 = 131,072, DeepSeek-V4-Pro's 16 × 65,536 = 1,048,576 and Mistral Large 3's 36 × 8,192 = 294,912 do match their configs' max_position_embeddings.
"LongRoPE is behind Phi-3's 2M-token context"
The 2,048K result is the LongRoPE paper's, on LLaMA2 and Mistral. Phi-3-mini uses LongRoPE for 128K.
"NoPE layers are worse at retrieval"
The old version of this page said so. In Yang et al.'s needle tests the NoPE variant put the most attention on the needle; its weakness was on standard benchmarks, which is why it is used in one layer of four rather than everywhere.
Design: you must ship a 128K model, have budget to pretrain at 8K, and must not lose short-context quality. What position recipe?
RoPE with a base chosen for the long target at pretraining (ABF: 500,000 or more at 8K), optionally NoPE or a fast-pair-only RoPE in a few global layers; then a continued-pretraining stage on long documents at increasing lengths with YaRN or Llama 3 scaling (a few billion to hundreds of billions of tokens), mixed with short data; ship the scaling in the config, prefer dynamic scaling at inference so short prompts run unscaled, and verify with needle and multi-hop long-context evaluations plus the short-context suite at every stage.
Design: an agent must handle 1M-token contexts on a hybrid. Where do positions go?
Let the linear or SSM layers carry order (they are recurrent), keep the few full-attention layers position-free or fast-pairs-only so nothing goes out of range at 1M (Kimi K3, Nemotron 3 Super, Gemma 4's global layers), and spend the remaining effort on what long context really costs: KV memory and effective use, owned by the Long context page.
Design: how would you check that RoPE scaling is configured correctly on a checkpoint you were handed?
Print the resolved rope parameters (transformers 5 standardises them into 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).