Articles · 2026 · Reading: 15 min, plus 1 in closed details.
Article · explainer · Ahead of AI (magazine.sebastianraschka.com) · updated 19 November 2026

Understanding Positional Embeddings in Modern LLMs

Sebastian Raschka · published 15 November 2026

In one line: A free long explainer (about 40 minutes, 38 numbered figures, PyTorch code) that derives RoPE pair by pair on one eight-word sentence and checks its relative-offset property in code, then sorts the entries of the author's own LLM Architecture Gallery by position scheme: RoPE in every attention layer is still the most common choice but its share fell from 2025 to 2026, RoPE and NoPE mixes grew, most 2026 RoPE entries rotate only part of each head, and Inkling's learned relative bias is the one new design; the groups are small, as the author says.

13 after any shift
the first pair's share of the query-key dot product, (1, 5) rotated to 100° and 40°, so 26 cos 60°; shifting both tokens by three, or by a 100-token prefix, leaves it unchanged
worked by hand, then asserted in PyTorch · in the article: Section 3.5
64 of 128 dims rotated
MiniMax-M3's partial RoPE per head; at its 1M-token context that halves the cosine and sine tables, a saving of 128 MiB in BF16
config read 2026-11-27; arithmetic checked · in the article: Section 6.1
3 of 4 layers with RoPE
SmolLM3 skips RoPE in every fourth of its 36 layers (NoPE), which its authors say helped long context
SmolLM3 blog and config · in the article: Section 6.2

How far to trust it: Correct wherever we recomputed it (every worked number, the table sizes, the parameter shares), and the clearest pair-by-pair RoPE derivation with code we know. Read Section 6 as a dated count over one curated gallery, and do not take its verdict on partial RoPE: it weighs only the cosine and sine tables, not the reasons models rotate part of a head. The evidence, judged.

Updated: on 19 November the author moved material he had trimmed (plus ALiBi and YaRN) into an optional appendix page and linked it from the post (announced in the comments); the first archived copy, 15 November 12:15 UTC, holds only a script shell, so the post's text could not be diffed.

The idea in one sentence: Raschka teaches position on one eight-word sentence: GPT-2 adds a position vector to each token once, RoPE instead rotates each pair of query and key numbers by its position so that a score depends only on how far apart two tokens are, and recent open models have started to rotate only part of each head, to skip RoPE in some layers, or (Inkling) to learn a bias on the score instead.

What this page is for. Everything the article teaches is already owned by Positional Encodings, which derives RoPE, measures five schemes on the tiny GPT and reads 74 configs. So this page does not teach the mechanism again. It follows the article's argument briefly, says what its framing adds (a hand-checkable worked pair, a three-line unit test, a dated census of 2026 models, a toy for how NoPE counts), judges where it is loose or weak, and lists what our owner page should take from it.

You need: what attention computes, scores q · k / √d, a softmax and a weighted sum of values (The transformer from zero); RoPE itself is on Positional Encodings, section 3.

New terms: split-half and interleaved pairing (which two numbers of a head RoPE turns together: i with i + d/2, or neighbours); partial RoPE (only some pairs of each head are rotated); NoPE layer (a layer with no explicit position signal; the causal mask still orders tokens); learned relative position bias (a number added to each score before the softmax that depends on the distance between query and key).

Position can enter at five places in one layer, and the article walks through them in order
One token through one attention layer (left), and where each scheme the article covers adds position (right). §2: added once to the input embedding (GPT-2's learned table, the 2017 sinusoids). §3 to 5: every pair of q and k rotated by position (full RoPE, used by most models). §6.1: only some pairs rotated (partial RoPE; MiniMax-M3 rotates 64 of each head's 128 numbers). §6.2: no rotation in this layer (a NoPE layer; SmolLM3 skips RoPE in every fourth of its 36 layers). §6.3: a learned bias by distance added to the score (Inkling; T5 did a simpler version in 2019). Values are never touched by any of them.

1. Where position enters, and why it is needed

Sections 1 and 1.1

The article opens on two architectures side by side: GPT-2 adds position before the first block, MiniMax-M3 adds it inside attention, in every block. Its running example is "The red fox jumps over the gray fox" against "The gray fox jumps over the red fox": both "fox" tokens get the same embedding, and without positions attention cannot tell which fox jumps. It then makes the point our owner page makes with a permutation test, in one sentence: the causal mask already gives a decoder some order, but in one layer it does not distinguish a separation of one position from a separation of ten. Our page shows the same thing measured (NoPE's first block does not notice a shuffle, its second does) in Positional Encodings, section 1.

2. Adding a vector: GPT-2's table and the 2017 sinusoids

Section 2

The learned table's cost is framed as a share of the model, which is a framing our page lacks. GPT-2 Medium's 1,024 position rows are 0.30% of its weights; stretched to a 100,000-token context they would make up >22% of the total. Recomputed here: 1,024 × 1,024 = 1.05M of about 355M is 0.30%, and 100,000 × 1,024 = 102.4M of 456M is 22.4% (derived, the parameter count from GPT-2 Medium's published size). Our page gives the cost in absolute terms (786,432 parameters in GPT-2) and the hard cap.

On the 2017 sinusoids, the article adds one reason we only measured. The Transformer multiplies token embeddings by √dmodel before adding the sinusoids, which its paper never explains; Raschka's reading is that it is meant to put the token embeddings and sinusoidal positional encodings on comparable scales at initialisation, and that GPT-2 needed no such factor because its code initialises token embeddings at standard deviation 0.02 and position embeddings at 0.01. That is his hypothesis, from a discussion, not a source. Our owner page has the measured consequence (the tiny GPT without the scale ends at 4.29 against 2.29), and Attention Is All You Need draws the sinusoids.

3. RoPE, one pair at a time

Sections 3.3 to 3.5

The core of the article is one feature pair worked by hand, small enough to check on paper. Query "the" at position 5 and key "fox" at position 2 both start as the pair (1, 5); at 20° per position the key turns 40° and the query 100°. Both keep length √26, they end 60° apart, and their exact dot product is 26 × cos 60° = 13. Move the key one place closer and the score becomes 26 × cos 40° ≈ 19.92; shift both tokens by three and it is 13 again. Our page's worked example (θ = 0.5, q = k = (1, 0), 0.5403 = cos 1) is the same derivation with numbers that are less memorable: Raschka's 13 and √26 are integers a reader can carry, and the sentence is the one the whole article is about.

The motivation is the system prompt, which is the best one-line answer to "why relative". Put 100 tokens in front of the sentence and "fox" and "the" move to 102 and 105, but a prefix of any length shifts both positions equally, so the pair's contribution stays 13. He adds the caveat our page leaves implicit: this holds for fixed unrotated vectors, and in a real model a new prefix of 100 tokens can change them, by changing what earlier layers attend to. RoPE makes the position part of a score invariant to the shift, not the whole score.

One loose end: after the single pair, the article prints whole eight-number vectors If we rotate all 4 pairs without giving their frequencies. Recomputed here, they use 20°, 2°, 0.2° and 0.02° per position for the four pairs, a base-10 version of the schedule that Section 4 then introduces with base 10,000 (which would give 1, 0.1, 0.01 and 0.001 radians). The numbers are right for that schedule; a reader recomputing them from Section 4 would not get them. Our page draws the whole head as a bank of clocks (its Fig. 4) and the RoFormer page the paper's eight-pair dials.

4. The frequencies and the PyTorch code

Sections 4 and 5

The code section is short, correct and better than ours in one respect: it ends with a test any implementation can run. rope_params returns two tables, cosine and sine of position × θi with θi = 10,000−2i/d, one row per position and one column per pair (1,024 × 64 for a 128-wide head), computed once and broadcast over the batch and every head; rope_split_half rotates pair (i, i + d/2) with them. Then, adding 3 to each position should change the positions but not the scores: the code recomputes the scores at positions + 3 and checks them with torch.testing.assert_close. Our page tells the reader to check a RoPE setup by comparing loss with a reference; the shift test is cheaper and catches position bugs (queries and keys rotated at mismatched positions, broken cosine and sine tables) before any loss is measured. It does not replace the loss check: a wrong base or pairing applied to both q and k still gives scores that depend only on the offset, so it passes, and convention errors are found only by comparing the loss against a reference.

Split-half against interleaved, shown as a permutation. The original paper and Meta's first LLaMA code pair neighbours (0, 1), (2, 3); most code now pairs i with i + d/2. Reordering the features as [0, 4, 1, 5, 2, 6, 3, 7] before the interleaved rotation gives identical outputs and scores, while applying the two layouts to the original vector gives different ones. Our page has the consequence measured (loading the wrong layout takes the tiny GPT's loss from 1.96 to 3.61 with no error) and Hugging Face's conversion permutation; the article's three asserts are the cleanest proof that the two layouts differ only by a reordering of WQ and WK.

5. What recent models do instead of full RoPE

Section 6

Partial RoPE: MiniMax-M3 rotates 64 of each head's 128 numbers. Its config, read on 27 November 2026, says head_dim 128, rotary_dim 64 (partial_rotary_factor 0.5), rope_theta 5,000,000 and 1,048,576 positions. The article measures the gain by the tables: halving them at a 1M context saves 1,048,576 × 32 pairs × 2 tables × 2 bytes = 128 MiB in BF16, or 36 MiB in NVFP4 with its block scales (both rechecked here), while the KV cache still stores the full key. It cites the Fractional Rotation paper, where rotating around 10% of each head's features matched full RoPE in 1B to 8B models, and concludes that partial RoPE is hardly worth it. The arithmetic is right and the conclusion does not follow; see the next section.

NoPE layers: a toy for how the causal mask becomes a position. Suppose one value feature is 1 for "The" and 0 elsewhere, and a head attends uniformly to everything the mask allows. At "fox" (position 2) it averages three values and outputs 1/3, at "jumps" 1/4: the output feature equals one over the prefix length, which a later layer can read as a position. This is Kazemnejad et al.'s construction made concrete, and it is the mechanism behind what our owner page only measures (its probe finds absolute position in NoPE's middle blocks, R² 0.94 by block 3). The paper's 107M models generalised to longer inputs best with NoPE (NoPE ranked first overall across the ten tasks), but its 1.3B code model's predictions got worse at the longest lengths. Hence mixtures: SmolLM3 applies RoPE in three layers and skips it in the fourth, and its authors report better long context.

A learned relative bias returns, in Inkling. Thinking Machines' Inkling (975B parameters, 41B active, released 15 July 2026) adds a learned number to each score before the softmax that, in Raschka's description, depends on the query token's hidden state and on how far back the key is. T5's 2019 bias depended only on the bucketed distance. Thinking Machines' announcement says only that a relative positional embedding beat RoPE and extrapolated better; the dependence on the hidden state is the article's reading and was not checked here (unconfirmed).

The census, from his own gallery. Sorting the entries of his LLM Architecture Gallery (snapshot of 9 November 2026) by release date: 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; and among RoPE entries, partial RoPE became more common from 2025 to 2026, from a minority to a majority. He adds that the groups are still small. The exact shares are only in his bar charts, so they are not quoted here. His forecast: RoPE stays dominant and I think this will carry over into 2027, perhaps with more Inkling-like designs.

How much of this to believe

The mechanics are correct wherever we recomputed them. The rotated pairs (−2.448, 4.473) and (−5.098, 0.117), the dot products 13 and 19.92, the frequencies 1, 0.1, 0.01 and 0.001 for d = 8, the 0.30% and 22% shares, and the 128 MiB and 36 MiB table savings all come out as printed (closed block below). The code is the standard split-half RoPE and its asserts hold by the algebra our owner page derives. For an explainer this is the main test, and it passes.

Where it simplifies or is loose (none of it changes what a reader learns about the mechanism):

  • It calls RoPE relative positional embeddings (aka RoPE) in the introduction. RoPE rotates each vector by its own absolute position; only the dot product is relative, and the keys are cached already rotated. Section 3 of the article gets this right; the introduction's label does not.
  • RoPE is called a staple in most (open-weight) LLMs since the original LLaMA; GPT-J and GPT-NeoX-20B used it before (GPT-NeoX on 25% of each head, the first partial RoPE), which our owner page's variants table records.
  • Section 3.2 says Figure 12 below follows a token representation; the figure meant is Figure 15. The full-vector rotations in Section 3.3 use a schedule the article never states (section 3 above).
  • The reason given for split-half pairing, that it makes it easier, in code, to rotate all pairs at once, is his reading; interleaved pairing is just as elementwise with strided views, and which layout a checkpoint needs is fixed by how its weights were trained or converted.

The weak spot is the verdict on partial RoPE. The article weighs it only by the cosine and sine tables (point behind partial RoPE? It saves some memory), finds the saving small, and calls the technique hardly worth it. The saving is indeed negligible, and showing that is useful, because the Fractional Rotation paper itself advertises up to 10× savings of the "RoPE cache". But the tables are not why models rotate part of a head:

  • MLA needs it. DeepSeek-V3, Mistral Large 3 and Kimi K2 rotate a separate 64-number key so that the rest of the key can stay a compressed latent whose up-projection is absorbed into the query; a fully rotated key would block that absorption (Attention variants). Two readers said so in the comments.
  • Unrotated dimensions match on content alone. Barbero et al. found Gemma uses the fastest pairs for positional patterns and prefers the lowest frequencies, which they suspect carry semantic information (Round and Round We Go); Gemma 4's global layers keep only fast pairs, Qwen3-Next only a quarter of each head. Our owner page shows both kinds.
  • The evidence he cites cuts the other way. In the Fractional Rotation paper about 10% rotation matched full RoPE, and NoPE alone could cause loss spikes that a little RoPE or QK-Norm mitigated: so rotating a small part is cheap insurance, not a waste.

Read the census as a dated count over one curated gallery. The gallery is Raschka's own selection of notable open models, each card counted once (so each gallery card counts once, so multiple variants of one family can count several times), split into three small groups. The directions (full RoPE falling, mixes and partial RoPE rising) are consistent with the variants our owner page read from configs in October (partial RoPE in GLM-4.5, Qwen3-Next and Gemma 4; NoPE layers in Llama 4, SmolLM3 and Command A), though that page counted no trend; the sizes of the shifts are not a measurement of the field. The Inkling description goes beyond what its maker has published (above).

The appendix (added 19 November) has one wrong attribution. Its 1.3B zero-shot comparison, ALiBi 43.70, rotary 41.46, learned 41.71 on 112B tokens of OSCAR, is credited to the ALiBi paper; it is Table 2 of Le Scao et al. 2022 (BigScience), the study that chose ALiBi for BLOOM. The WikiText-103 numbers beside it (rotary 20.07 at 512 tokens rising to 31.58 at 2,512; ALiBi 19.73 falling to 18.41) are the ALiBi paper's, as stated.

Verdict. Believe it and use it as the gentlest correct derivation of RoPE with code; take the census as one author's dated view of the trend; replace its partial-RoPE verdict with the reasons above.

What the responses said

No rebuttal, replication or Hacker News thread was found (web search, 27 November 2026); for an explainer that is expected. The post's own comment thread had 16 comments, 280 likes and 31 restacks that day (a dated reading). Three comments add something, and the author added an appendix:

  • reader commentWhy partial RoPE at all, if the memory win is so small?
    a reader, Substack comments, 16 November 2026

    Asks whether a quality reason or legacy code explains partial RoPE in 2026 models. The author answers that he knows of no study; two readers then point to MLA, where rotating only a small decoupled key lets the compressed latent stay compressed (the key up-projection can be absorbed into the query). That is the better reason, and the knowledge base already teaches it.

  • reader commentCheck the loaded rope settings against config.json
    a reader, Substack comments, 16 November 2026

    When Llama 3.1 shipped with rope_type llama3, older transformers versions refused it, and a workaround rewrote it as dynamic, which loads but runs a different scaling. The author replies that this scaling took him a long time to get right in LitGPT.

  • reader commentWhat about PoPE, which removes RoPE's content and position cross term?
    a reader, Substack comments, 18 November 2026

    Points to Gopalakrishnan et al.'s polar coordinate positional embedding (arXiv 2509.10534, v3 June 2026), which argues RoPE entangles what and where; another reader notes its code is released. The author did not reply by 27 November.

  • author's addendumThe appendix, added after publication
    Sebastian Raschka, 19 November 2026

    Adds ALiBi, YaRN and the published comparisons, with each method's numbers. One attribution in it is wrong: the 1.3B zero-shot ablation (ALiBi 43.70, rotary 41.46, learned 41.71) is Table 2 of Le Scao et al. 2022, not of the ALiBi paper.

Where it moves the knowledge base

It contradicts nothing our pages say about the mechanism; it adds a few things our owner page should take, and dates one table.

  • Positional Encodings: gains the shift test as a one-line check for position bugs in any RoPE implementation, beside the loss check it cannot replace (section 3, Cost and the one check), the 1/prefix-length toy for how NoPE learns position (section 1, beside the probe), Inkling's learned relative bias as the 2026 return of T5's idea (sections 2 and 10, marked unconfirmed until its code is read), MiniMax-M3's 64-of-128 partial RoPE and the Fractional Rotation result in the variants table (section 4), the 22% share in the learned-table paragraph (section 2), and this article in Further reading.
  • LLM Architecture Gallery: the gallery's own position-scheme counts of 9 November 2026 (full RoPE falling, partial RoPE a majority of 2026 RoPE entries), as a dated reading.
  • RoFormer and Attention Is All You Need: this article in Further reading, as the gentlest walkthrough of each one's position scheme.
  • Attention variants: unchanged; it already holds the reason for partial rotation the article misses.
The article's numbers, recomputed (depth)
  • Pair (1, 5) rotated 40°: (cos 40° − 5 sin 40°, sin 40° + 5 cos 40°) = (−2.448, 4.473); 100°: (−5.098, 0.117). Dot product 26 cos 60° = 13; key at 3: 26 cos 40° = 19.92.
  • Full vectors: the printed key (−2.448, 1.577, 2.951, 3.994, 4.473, 6.125, 7.021, 8.003) at position 2 and query (−5.098, 0.928, 2.877, 3.986, 0.117, 6.256, 7.051, 8.007) at position 5 match a schedule of 20°, 2°, 0.2°, 0.02° per position for the four split-half pairs; with base 10,000 the first pair at position 2 would be (−4.963, −1.171).
  • Learned table: 1,024 × 1,024 / 355M = 0.30%; 100,000 × 1,024 = 102.4M of 456M = 22.4%.
  • MiniMax-M3 tables: 1,048,576 positions × 32 rotated pairs saved × 2 tables × 2 bytes = 134,217,728 bytes = 128 MiB (0.134 GB); in NVFP4, 0.5 byte per value plus one 1-byte scale per 16 values: 36 MiB (0.038 GB).
  • RoPE tables for a 1,024 context and a 128-wide head: two tensors of 1,024 × 64.
Provenance: what was read, fetched and compared

Read on 27 November 2026: the post (fetched that day; published 15 November 12:10 UTC per its page data, about 9,200 words with code, 40 minutes at 230 words a minute); the appendix page in full; all 16 comments through Substack's comment endpoint; MiniMax-M3's config.json; the abstracts of arXiv 2603.11611 (Fractional Rotation, v2 15 October 2026) and 2509.10534 (PoPE); Thinking Machines' Inkling announcement; Table 2 of arXiv 2210.15424 and the WikiText-103 extrapolation tables of arXiv 2108.12409 (ALiBi, appendix), for the appendix's numbers. Every number in the closed block above was recomputed in Python.

The first archived copy (Wayback, 15 November 12:15 UTC) is a script shell without the post's text, so the post could not be diffed against it; the known change is the 19 November appendix, announced by the author in the comments. No Hacker News or Lobsters thread was found. Commenters are not named here: they are readers, not authors of published responses.