Deep Analysis of LLM Position Embedding: From RoPE to NoPE

Sebastian Raschka comprehensively summarizes various methods of encoding positional information in the latest LLM architectures. From the absolute position embedding of GPT-2 to the RoPE (Rotary Positional Embedding) adopted by MiniMax-M3, and the concept of NoPE which omits position embedding, he explains the mechanisms, formulas, and PyTorch implementations. He also previews which positional encoding methods open-weight models will choose in 2026. It shows that causal masks alone cannot distinguish distances between positions, making explicit positional information still essential.

Why Is Positional Information Still Necessary?

In transformer-based LLMs, token embeddings alone cannot express order information. "The red fox jumps over the gray fox" and "The gray fox jumps over the red fox" have the same set of tokens but completely different meanings. As pointed out in the original text, the causal mask provides implicit order information by restricting reference to previous tokens, but it cannot distinguish between "tokens one space apart" and "tokens ten spaces apart." Therefore, position embedding is essential to explicitly inject this distance information.

Causal masks only determine which tokens are accessible and do not distinguish between positions. Thus, explicit positional methods are still useful or essential.

Absolute Position Embedding: The GPT-2 Method

GPT-2 adds learned absolute position vectors to token embeddings and passes them to the first transformer block. It retrieves the embedding $\mathbf{e}_p$ for position $p$ from a lookup table and adds it to the token embedding $\mathbf{x}_p$.

$$ \mathbf{h}_p = \mathbf{x}_p + \mathbf{e}_p $$

This method is simple to implement, but there is an extrapolation problem where performance degrades due to the absence of position embeddings when inferring with sequence lengths not seen during training.

How Relative Position Embedding and RoPE Work

Relative position embedding adds a bias to the attention scores that depends only on the distance $i-j$ between tokens. RoPE implements this through rotation operations, rotating the query and key vectors according to their positions. The key idea is to use rotation in the complex plane.

RoPE Formula

The dimension $d$ is divided into $d/2$ pairs, and for each pair, a rotation angle $\theta_p = p \cdot \theta_k$ is applied based on position $p$.

$$ \text{RoPE}(\mathbf{q}_p, p) = \mathbf{q}_p \odot \cos(\theta_p) + \text{rotate}(\mathbf{q}_p) \odot \sin(\theta_p) $$

This operation is applied equally to queries and keys, and has the property of relying only on the relative distance $p-q$ during attention score calculation.

FeatureAbsolute Position Embedding (GPT-2)RoPE (LLaMA, MiniMax-M3, etc.)
Injection PointImmediately after embedding layer (once)Inside all attention layers (repeated)
Distance RepresentationAbsolute position $p$Relative distance $p-q$
Extrapolation PerformanceLimitedExcellent (utilizes rotation periodicity)
Implementation ComplexityLowMedium (requires rotation matrix)

Positional Encoding Choices in Latest Architectures (2026 Preview)

The original text previews the choices of major open-weight models in 2026 in Section 6. The main trends are as follows:

RoPE70
ALiBi15
NoPE10
Others5

Key Points for PyTorch Implementation

The minimal implementation provided in the original text consists of the following steps:

1. Frequency Basis Calculation: $\theta_k = 10000^{-2k/d}$ for $k=0,\dots,d/2-1$ 2. Generate Rotation Matrices by Position: Pre-calculate $\cos(\theta_p), \sin(\theta_p)$ 3. Apply Query/Key Rotation: Perform rotation operations for odd/even dimension pairs 4. Attention Calculation: Conduct standard scaled dot-product attention with rotated queries/keys

```python def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0): freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim)) t = torch.arange(end, device=freqs.device) freqs = torch.outer(t, freqs) return torch.polar(torch.ones_like(freqs), freqs) # complex64 ```

This implementation efficiently handles rotations using complex operations.

Practical Implications and Remaining Challenges

While RoPE has effectively become the standard, issues with rotation periodicity breaking in ultra-long contexts (128K+ tokens) have been reported. To address this, extension techniques such as YaRN (Yet another RoPE extensioN), LongRoPE, and PI (Position Interpolation) are actively being researched. Additionally, approaches like NoPE, which omit position embeddings and learn order through data and model scale, are gaining attention.

Developers should verify whether RoPE variant support aligns with context window requirements when selecting models, and assess the impact of freezing position embedding parameters during fine-tuning on performance.

Verified figures

Our take

While RoPE has effectively become the industry standard, the limitations of rotation periodicity due to context window expansion remain a key unresolved challenge. Verified benchmarks are needed to assess how reliably extension techniques like YaRN and LongRoPE operate in practice.

Open questions

Source

Back to catalog