不过,Barbero 等人(2024)也给出了两项重要修正:第一,有限个离散频率之和在局部区间上并非严格单调递减,甚至存在特定间距使远端打分回弹的反例;第二,训练后的 Transformer 会分化频段——高频驱动局部句法,低频承载全局语义并随距离衰减,与下一节 <BOS> 注意力汇共同解释了 Lost in the Middle(Liu et al., 2023)。
Jianlin Su et al. (2021). RoFormer: Enhanced Transformer with Rotary Position Embedding (RoPE). arXiv:2104.09864 · 科学空间原帖:8265 / 9675 / 9948 / 10122
Shouyuan Chen et al. (2023). Extending Context Window of Large Language Models via Positional Interpolation (PI). arXiv:2306.15595
bloc97 (2023). NTK-Aware Scaled RoPE allows LLaMA models to have extended (8k+) context size without any fine-tuning. Reddit r/LocalLLaMA
Nelson F. Liu et al. (2023). Lost in the Middle: How Language Models Use Long Contexts. arXiv:2307.03172
Bowen Peng et al. (2023). YaRN: Efficient Context Window Extension of Large Language Models. arXiv:2309.00071
Guangxuan Xiao et al. (2023). Efficient Streaming Language Models with Attention Sinks. arXiv:2309.17453
DeepSeek-AI (2024). DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model (MLA & Decoupled RoPE). arXiv:2405.04434
Federico Barbero et al. (2024). Round and Round We Go! What Makes Rotary Positional Encodings Useful?arXiv:2410.06205
Haonan Wang, Qian Liu, Chao Du (2024). When Precision Meets Position: BFloat16 Breaks Down RoPE in Long-Context Training. arXiv:2411.13476
Zihan Qiu et al. / Qwen Team (2025). Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free. arXiv:2505.06708
OpenAI (2025). gpt-oss-120b & gpt-oss-20b Model Card. arXiv:2508.10925
DeepSeek-AI (2025). DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models. arXiv:2512.02556
Marin Team / OpenAthena (2025). Marin 535B Architecture. OpenAthena Blog
Natural language exhibits strong shift invariance: moving "the black cat sat on the mat" from position 10 to position 10,000 leaves its local syntax intact. Adding fixed sinusoidal vectors straight onto token embeddings entangles word identity with absolute position inside $W_Q$ and $W_K$, whereas T5-style additive relative biases modify attention score matrices at every layer and complicate fused kernels and paged caching.
RoPE (Rotary Position Embedding, Su et al., 2021) frames the requirement algebraically (see Su's original derivation post): can we apply an independent map $f(\cdot, \text{pos})$ to individual vectors $q_m$ and $k_n$ so that their dot product depends strictly on content and relative displacement $m - n$?
1. Deriving 2D Complex Rotation From Shift Invariance#
Begin on the 2D Euclidean plane $\mathbb{R}^2 \cong \mathbb{C}$. We ask for transforms $f(q, m)$ and $f(k, n)$ satisfying:
Express both mapped vectors in complex polar form: $f(q, m) = R_f(q, m)\, e^{i\Theta_f(q, m)}$ and $f(k, n) = R_f(k, n)\, e^{i\Theta_f(k, n)}$. Because $\langle a, b\rangle = \mathrm{Re}[a\, b^*]$, a sufficient solution sets the full complex product equal to a function of $m - n$: $f(q, m) f^*(k, n) = R_g(q, k, m - n)\, e^{i\Theta_g(q, k, m - n)}$. Matching modulus and phase yields two decoupled constraints:
Modulus condition: $R_f(q, m) R_f(k, n) = R_g(q, k, m - n)$. Choosing norm-preserving maps $R_f(q, m) = \|q\|$ satisfies the magnitude constraint while keeping attention score variance independent of position.
Phase condition: $\Theta_f(q, m) - \Theta_f(k, n) = \Theta_g(q, k, m - n)$.
Three algebraic steps lock the phase map uniquely. First, apply the zero-position initial conditions $\Theta_f(q, 0) = \Theta(q)$ and $\Theta_f(k, 0) = \Theta(k)$ at $m = n = 0$ to evaluate $\Theta_g(q, k, 0) = \Theta(q) - \Theta(k)$. Next, substitute $n = m$ into the general phase condition:
$$\Theta_f(q, m) - \Theta_f(k, m) = \Theta_g(q, k, 0) = \Theta(q) - \Theta(k)$$
Rearranging separates content variables across the equality: $\Theta_f(q, m) - \Theta(q) = \Theta_f(k, m) - \Theta(k)$. Because the left side depends only on $(q, m)$ and the right only on $(k, m)$ for arbitrary $q$ and $k$, both must equal a content-free position function $\Phi(m)$, giving $\Theta_f(q, m) = \Theta(q) + \Phi(m)$ (with $\Phi(0) = 0$). Substituting back into general $(m, n)$ (and setting $n=0$ to equate the right-hand side) yields the additive functional equation:
Taking steps of size $1$ ($m - (m - 1) = 1$) forces equal increments $\Phi(m) - \Phi(m-1) = \Phi(1) = \theta$, uniquely selecting linear phase progression $\Phi(m) = m\theta$ so $\Theta_f(q, m) = \Theta(q) + m\theta$. Inside a Transformer, RoPE is applied per-layer right after the $W_Q$ and $W_K$ projections—never added to the token embedding at input, and leaving Value vectors $V$ unrotated:
Across a full attention head (such as $d_{\text{head}} = 128$), coordinates group into $d/2 = 64$ independent 2D planes rotating at hardcoded geometric angular velocities $\theta_i = \mathrm{base}^{-2i/d}$—either in interleaved pairs (2i, 2i+1) (used by RoFormer and MLA) or split-half pairs (i, i+d/2) (common in HuggingFace's rotate_half). Hardcoding a geometric ladder (spanning wavelengths from ~6 to ~54K tokens at base=10000) gives a zero-parameter multi-scale ruler across every offset.
Crucially, mixing up interleaved and split-half pairing fails silently with zero shape mismatch errors, quietly corrupting attention geometry—a real integration pitfall highlighted when DeepSeek-V3.2 noted its Indexer RoPE expects non-interleaved layout while MLA RoPE expects interleaved inputs.
⤢ Zoom
Figure 1: Implementation of Rotary Position Embedding (RoPE) rotating 2D Query/Key subspaces by position-proportional angles (arXiv:2104.09864). (Source: Su et al., 2021, Fig. 1)
Walking through the diagram clarifies the layout: the top dashed $d=2$ zoom box isolates a single interleaved pair $(x_1, x_2)$ at position $m$ rotated counterclockwise by $m\theta_1$ into $(x'_1, x'_2)$, while the bottom panel shows full Query / Key rows at positions 1..6 partitioned into color-coded 2D blocks $(\theta_1, \theta_2, \dots, \theta_{d/2})$ rotated independently.
There is also a precision hazard in low-bit training: Wang et al. (2024, arXiv:2411.13476) showed that representing positions or computing rotary angles in bfloat16 (only 7 mantissa bits) triggers BF16 position collision right at $m = 2^8 = 256$—where $1\text{ ULP} = 2^{8-7} = 2$, so bf16(256) and bf16(257) collapse to identical floats before interacting with RoPE's diagonal slash attention pattern. Production kernels therefore compute positions, frequencies, and trigonometric terms in FP32 before casting back:
Using $64$ geometrically separated frequencies serves the same role as hands on a mechanical clock (also framed by Su via $\beta$-base positional coding). Fast planes advance rapidly per token, separating adjacent syntactic dependencies while wrapping every few tokens; slow planes avoid phase ambiguity across thousands of tokens, yet turn too little between neighboring positions to resolve local word order on their own.
With base = 10000, d = 128, the fastest plane rotates at $\theta_0 = 1.0\text{ rad/tok}$ ($\approx 57.3^\circ$) and the slowest turns at $\theta_{63} \approx 0.0001155\text{ rad/tok}$ (one full revolution every ~54,410 tokens). If pretraining finishes at 4K context (4,096 tokens), that slowest coordinate pair has only swept across $0^\circ\text{–}27.1^\circ$. Evaluating directly at 16K rotates it into $108.4^\circ$—untrained phase space where attention logits misfire and perplexity spikes.
Tracking a 3-band toy head ($d=6$, base = 10000, $\theta_i = \text{base}^{-i/3}$, extending 4K $\to$ 16K by factor $s = 4$) clarifies how extension recipes differ (see Su's context-extension retrospective):
Band
4K Rate
PI · $\div 4$
NTK · $b{\times}8$
YaRN · Banded
Fast $i=0$
$1.0$
$0.25$ · 4× tighter step
$1.0$ · intact
$1.0$ · untouched
Mid $i=1$
$0.0464$
$0.0116$
$0.0232$ · 2× slower
$1 \to 1/4$ linear ramp
Slow $i=2$
$0.00215$
$0.00054$ · inside 4K arc
$0.00054$ · 4× slower
$0.00054$ · PI-scaled
Position Interpolation (PI, Chen et al., 2023): Divides every position index uniformly by scale factor $s = 4$, slowing all rotation bands proportionally. Slow planes remain inside the trained 4K arc (note that in the $d=6$ toy head $\theta_2 = 10000^{-2/3}$ sweeps $\approx 505.6^\circ$ over 4K and dividing by 4 maps 16K back inside that exact arc), but local angular separation on fast bands shrinks $4\times$, requiring sustained continued pretraining to recover short-range sharpness.
NTK-Aware Base Scaling (bloc97, 2023): Scales the geometric base instead of position indices. Equating $(b')^{-(d-2)/d} = b^{-(d-2)/d} / s$ yields the general rule:
$$b' = b \cdot s^{\frac{d}{d - 2}}$$
At $d = 6, s = 4$, this gives $b' = b \cdot 4^{6/4} = 8b = 80{,}000$ (explaining the $8\times$ base multiplier in the table above), whereas on a realistic $d = 128, s = 4$ head it gives $b' = b \cdot 4^{128/126} \approx 4.09\,b$. Because $\theta_0 = \mathrm{base}^0 = 1$, the fastest local band stays untouched while the slowest band decelerates by $s$.
YaRN (Peng et al., 2023): Uses each band's wavelength ratio $r_i = L_{\text{train}} / \lambda_i$ ($\lambda_i = 2\pi/\theta_i$) with a linear ramp $\gamma(r)$ and a logit temperature factor $1/t$:
Each band takes $\theta_i' = \big(1 - \gamma(r_i)\big)\frac{\theta_i}{s} + \gamma(r_i)\theta_i$: fast bands ($r_i > \beta, \gamma=1$) stay untouched, slow bands ($r_i < \alpha, \gamma=0$) take full PI scaling, and middle bands ramp linearly, while $Q$ and $K$ scale by mscale $= \sqrt{1/t}$ to prevent long-context Softmax entropy inflation. Modern production runs go further via ABF (Adjusted Base Frequency): raising rope_theta natively during pretraining and long-context midtraining (e.g., 500,000 in LLaMA-3 and 1,000,000 in Qwen2.5) so slow bands retain ample phase headroom from the start.
Interactive · RoPE Multi-Frequency Clocks (d=128)
Position m 4096Within 4K training arc
Figure 3: Drag position m or switch PI / NTK / YaRN (d=128, 4x scale) to inspect θ₀ vs. θ₆₃ rotation angles and attention temperature.
3. Four Structural Complications at Long Context and With MLA#
As context lengths push past 100K tokens and models adopt low-rank KV compression, rotating query and key content vectors directly introduces four structural drawbacks.
A natural puzzle arises right at the cosine formula: each individual rotation plane contributes $\cos(\Delta\theta_i)$, which is strictly periodic—so why doesn't the inner product simply oscillate back up at large distances instead of decaying?
For aligned weights $h_i$ across bands, the rotated inner product reads $\mathrm{Re}\!\sum_{i=0}^{d/2-1} h_i e^{i\Delta\theta_i}$. At $\Delta = 0$, three sample bands align at $0^\circ$ to sum to $\mathbf{+3}$; once $\Delta$ separates phases to $60^\circ, 180^\circ, 300^\circ$, the sum cancels to $0.5 - 1.0 + 0.5 = \mathbf{0}$. Defining partial phase sums $S_k = \sum_{j=0}^{k} e^{i\Delta\theta_j}$, Abel summation by parts isolates weight differences from phase cancellation:
Because larger $\Delta$ keeps the geometric phase sums $S_i$ bounded, the overall envelope decays with distance.
Barbero et al. (2024) clarify two important refinements: first, finite discrete frequencies prevent strictly monotonic decay everywhere, and specific rebound distances exist; second, trained models specialize bands—fast planes drive local syntax while slow planes carry high-level semantics alongside decay, combining with <BOS> sinks to produce the Lost in the Middle U-curve (Liu et al., 2023).
Because Softmax weights sum to $1$ under causal masking, functional tokens requiring little context dump spare probability mass onto <BOS> at position $0$ (Xiao et al., 2023)—a mechanism rooted in causal Softmax normalization rather than RoPE alone, so it also appears in NoPE layers. Standard full-head RoPE compounds the problem because it rotates the exact same 128 semantic coordinates in-place without appending separate unrotated slots. A fast $60^\circ/\text{tok}$ plane cannot hold a long-range anchor because [10, 0] rotates by $180^\circ$ in just 3 tokens, flipping from +100 to -100; a slow $0.01^\circ/\text{tok}$ plane rotates only $10^\circ$ over 1,000 tokens, staying at $100\cos 10^\circ \approx \mathbf{+98.5}$. Thus the network packs massive anchor magnitudes into the slowest dimensions:
Figure 4: Comparison of Dense Attention, Window Attention, Sliding Window w/ Re-computation, and StreamingLLM with Attention Sinks (arXiv:2309.17453). (Source: Xiao et al., 2023, Fig. 1)
Comparing panels (b) and (d) shows why those slow-channel sinks matter operationally: in (b) Window Attention, evicting the initial tokens from the cache collapses long-text perplexity to PPL: 5158; in (d) StreamingLLM, keeping just the yellow initial Attention Sink tokens alongside the $L$-token sliding window restores PPL: 5.40 at $O(TL)$ cost—matching sliding-window recomputation (5.43 in panel c) without recomputing history, because those slow-rotating initial sinks stabilize Softmax normalization across the sequence.
A full 4D "magnet hijack" example illustrates the collateral damage on semantic recall. Let dims (0, 1) serve as fast syntactic coordinates and dims (2, 3) serve as slow semantic coordinates occupied by $k_{\text{BOS}} = [0, 0, 10, 0]$. Suppose "Alice" at position 1000 stores $k_{\text{Alice}} = [0, 0, 2, 0]$, and at position 1002 the pronoun "she" emits query $q_{\text{she}} = [0, 0, 2, 0]$. Across $\Delta = 2$, the genuine coreference logit is only $q_{\text{she}}^\top k_{\text{Alice}} = \mathbf{+4}$, whereas <BOS> scores $q_{\text{she}}^\top k_{\text{BOS}} \approx \mathbf{+20}$—hijacking Softmax probability away from the real referent.
Recent architectures address this along three routes: GPT-OSS (OpenAI, 2025) places a learnable scalar sink logit $s_{\text{sink}}$ directly in the Softmax denominator,
so $e^{s_{\text{sink}}}$ absorbs idle probability mass cleanly; Qwen Gated Attention (Qiu et al., 2025) and Qwen3-Next add a per-head sigmoid output gate right after SDPA to suppress sink spikes; and Partial RoPE (p-RoPE) (see Su's base-selection note) rotates only the fastest $25\%\text{–}50\%$ dimensions, reserving slow dimensions for unrotated semantic matching.
DeepSeek's MLA (Multi-Head Latent Attention) stores only a compact latent vector $c_n$ in the KV cache and recovers keys through up-projection $W_{UK}$. Without RoPE, matrix associativity allows inference engines to fold ("absorb") $W_{UK}$ into the query projection ahead of runtime, computing queries straight against cached $c_n$:
Because $R_{n-m}$ varies with $(m, n)$, $W_{UK}$ can no longer be folded statically into $W_Q$. DeepSeek-V2 resolved this via Decoupled RoPE, splitting queries and keys into two parallel streams.
⤢ Zoom
Figure 5: DeepSeekMoE and Multi-Head Latent Attention (MLA) with Decoupled RoPE inside the Transformer block (arXiv:2405.04434). (Source: DeepSeek-AI, 2024, Fig. 2)
Tracing the bottom-right MLA panel in the diagram above (where hatched circles mark tensors cached during inference) shows how the two parallel KV paths work: first, the compressed latent branch projects input hidden state $\mathbf{h}_t$ to $\mathbf{c}_t^{KV}$ (cached), then up-projects unrotated per-head keys $\{\mathbf{k}_{t,i}^C\}$ ($W^{UK}$) and values $\{\mathbf{v}_{t,i}^C\}$ ($W^{UV}$) so $W^{UK}$ remains absorbable into the query weights; second, the separate Decoupled RoPE branch projects $\mathbf{h}_t$ to a head-shared (MQA-style) vector $\mathbf{k}_t^R \in \mathbb{R}^{64}$ (also cached alongside $\mathbf{c}_t^{KV}$), applies RoPE, and concatenates it onto every head to form $\{[\mathbf{k}_{t,i}^C;\, \mathbf{k}_t^R]\}$, paired with per-head rotated $\{\mathbf{q}_{t,i}^R\}$ concatenated onto $\{\mathbf{q}_{t,i}^C\}$. Relative positioning thus costs only 64 extra scalars per token in the shared cache.
Finally, pure relative rotation reports only pairwise spacing $m - n$ rather than absolute distance from sequence start. Think of holding a rope with 1,000 evenly spaced knots in the dark: feeling the span between your two hands tells you how many knots separate them ($m - n$), not whether you are near knot #5 or knot #995.
In language modeling, that missing global anchor complicates coordinate-sensitive tasks—distinguishing an opening title from a mid-body quote or tracking narrative position. Because each layer infers absolute indices indirectly from <BOS>, it reinforces the Attention Sink feedback loop—motivating hybrid architectures that drop RoPE completely on global layers in favor of NoPE, examined in What Replaces RoPE? Implicit Position in NoPE, Short Conv, and KDA.
Practically speaking, pure full-head low-base RoPE with post-hoc scaling looks increasingly obsolete for 128K–1M backbones. Pairing ABF high-base pretraining with 25%–50% Partial RoPE and a dedicated sink-mitigation mechanism (output sigmoid gates or learnable sink logits) is far cleaner than retrofitting frequencies after training, while global retrieval layers keep shifting toward NoPE or decoupled MLA.