Abstract
Rotary Position Embedding (RoPE) has become the standard for encoding sequence order in modern Large Language Models (LLMs). However, as context lengths scale, RoPE often induces "massive activations" and "attention sinks" that degrade performance. We present DoPE (Denoising Rotary Position Embedding), a training-free framework that identifies "noisy" attention heads using truncated matrix entropy and selectively suppresses them. Our method significantly improves long-context extrapolation, boosting Needle-in-a-Haystack retrieval accuracy from 40.4% to 70.1% at 64k tokens without additional training.
Introduction
Modern LLMs like Llama and Qwen utilize Rotary Position Embedding (RoPE) to capture relative positional information. While effective, RoPE is prone to instabilities in long-context scenarios. Specifically, it can cause "attention sinks," where the model assigns disproportionately large attention weights to initial tokens (e.g., the <s> token), regardless of their relevance. This phenomenon is often accompanied by "massive activations"—outlier values in hidden states that disrupt the model's reasoning capabilities.
The Problem: RoPE as a Structured Amplifier
The authors provide a spectral analysis revealing that RoPE's low-frequency components act as "structured noise." Theoretically, they prove that under certain conditions, these low-frequency bands accumulate energy along the sequence length, leading to the observed directional anomalies. This suggests that for many attention heads, explicit positional encoding becomes a source of interference rather than useful information.
Methodology: The DoPE Framework
DoPE introduces a two-step, training-free intervention to stabilize long-context attention.
1. Identifying Noisy Heads via Truncated Matrix Entropy
To capture the directional anomalies caused by RoPE, the researchers employ truncated matrix entropy ($H_h^r$). Unlike standard norm-based metrics, this looks at the top $r$ singular values of an attention head's Gram matrix. A low entropy score indicates a "low-rank" head dominated by a few directions—the signature of an attention sink.
2. Selective Denoising Strategies
Once noisy heads are identified, DoPE applies one of three reparameterization strategies:
- DoPE-by-parts: Removes only the low-frequency RoPE components while preserving high-frequency signals.
- DoPE-by-all: Completely masks the positional encoding for the selected heads, relying on the model's implicit ability to learn position from causal attention.
- DoPE-by-Gaussian: The most robust variant, which replaces the attention maps of noisy heads with an isotropic Gaussian distribution. This effectively turns the sink-dominated head into a neutral background, allowing the model to focus on relevant content in other heads.
Experimental Results
Long-Context Retrieval
On the Needle-in-a-Haystack (NIH) benchmark at 64k tokens, DoPE-by-Gaussian improved retrieval accuracy from a baseline of 40.4% to 70.1%. In "noisy" setups where sink tokens were intentionally placed near the target information, DoPE maintained a high accuracy of 84.4% at 24k tokens, compared to the baseline's 75.4%.
Many-shot Reasoning
Using the MATH dataset for Many-shot In-Context Learning (MICL), the authors tested reasoning with prompts containing hundreds of examples (up to 16k tokens). While standard methods like Positional Interpolation often saw performance collapse to near 0%, DoPE maintained significantly higher accuracy, demonstrating its utility for complex reasoning tasks in extended contexts.
Discussion and Conclusion
DoPE demonstrates that LLMs do not require explicit positional encoding across all attention heads. Some heads are naturally "extrapolative" and benefit from RoPE, while others are "denoised" and perform better when the explicit signal is suppressed. By treating attention sinks as a denoising problem, DoPE provides a powerful, training-free tool for extending the functional context window of existing models. Future work may involve integrating these denoising principles directly into the training phase to prevent the formation of attention sinks entirely.
Summary updated