Remember to Forget: Gated Adaptive Positional Encoding
summary
The gist
The gist The GAPE (Gated Adaptive Positional Encoding) introduces a drop-in augmentation for Rotary Positional Encoding that decouples distance-based suppression from token importance through
In short
The GAPE augmentation modifies Rotary Positional Encoding by adding adaptive gates that control how context is contracted and which key positions are protected from distance-based suppression. This decouples distance penalties from token importance, allowing the model to maintain long-context robustness up to eight times the training length while selectively suppressing irrelevant background information.
Key concepts
- GAPE Augmentation
- A method that adds adaptive gates (query and key dependent) over attention logits to modify Rotary Positional Encoding. It selectively suppresses distant, irrelevant context while preserving important, distant tokens without changing the underlying geometry of RoPE.
- Query Gate (gi)
- Controls how strongly a specific query token modulates the contraction of its context. This gate adapts based on the retrieval regime: close targets induce stronger contraction, while far targets keep it near zero, helping preserve a broader effective positional horizon.
- Landmark Gate (lj)
- Continuously protects selected keys from distance-based suppression. As lj approaches 1, protection becomes full. This mechanism ensures that important distant information is preserved even when the structural penalty for distance is applied.
- Structural Bias Realization
- The structural bias introduced by GAPE is realized exactly as a rank-at-most-two correction to the pre-softmax logits using the same matrix multiplication employed in standard attention mechanisms, ensuring compatibility with existing hardware and architectures.
Terminology used across episodes
This episode discusses
- Remember to Forget: Gated Adaptive Positional Encoding · Paper Radio
- Round and Round We Go! What makes Rotary Positional Encodings useful?
- Extending Context Window of Large Language Models via Positional Interpolation
- FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- LongRoPE: Extending LLM Context Window Beyond 2 Million Tokens
- The Llama 3 Herd of Models · Paper Radio
- RULER: What's the Real Context Size of Your Long-Context Language Models?
- Functional Interpolation for Relative Positions Improves Long Context Transformers
- Forgetting Transformer: Softmax Attention with a Forget Gate
- Scaling Laws of RoPE-based Extrapolation
- Base of RoPE Bounds Context Length
- Olmo 3
- YaRN: Efficient Context Window Extension of Large Language Models
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Gemma: Open Models Based on Gemini Research and Technology
- Frayed RoPE and Long Inputs: A Geometric Perspective
- FlashAttention-4: Algorithm and Kernel Pipelining Co-Design for Asymmetric Hardware Scaling
The paper
Remember to Forget: Gated Adaptive Positional Encoding · Read on arXiv
Riccardo Ali, Alessio Borgi, Mario Severino, Pietro Liò, Christopher Irwin
Department of Computer Science and Technology, University of Cambridge · Department of Information Engineering, University of Padua · Department of Computer, Control and Management Engineering, Sapienza University of Rome
Rotary Positional Encoding (RoPE) is widely used in modern large language models. However, when sequences are extended beyond the range seen during training, rotary phases can enter out-of-distribution regimes, leading to spurious long-range alignments, diffuse attention, and degraded retrieval. Existing remedies only partially address these failures, as they often trade local positional resolution for long-context stability. We propose GAPE (Gated Adaptive Positional Encoding), a drop-in augmentation for positional encodings that introduces a content-aware bias directly into the attention logits while preserving the rotary geometry. GAPE decouples distance-based suppression from token importance through a query-dependent gate that contracts irrelevant context and a key-dependent gate that preserves salient distant tokens. We show that weakly protected distant context is exponentially attenuated as a function of the query gate, while selected keys can remain accessible through landmark protection. We further show that GAPE can be implemented within standard scaled dot-product attention. Empirically, GAPE improves long-context robustness across controlled retrieval and language-modeling experiments, extrapolating up to 8x the training length. We further retrofit GAPE into a pretrained 7B model, maintaining performance on standard benchmarks and improving performance at the longest evaluated context. These results support adaptive context suppression as a complement to positional representation for long-context generalization.
Transcript
Introduction to the show: ident: AI Radio. Generated commentary on the latest Artificial Intelligence papers.
Tom: Today's paper: "Remember to Forget: Gated Adaptive Positional Encoding".
Jane: The gist The GAPE (Gated Adaptive Positional Encoding) introduces a drop-in augmentation for Rotary Positional Encoding that decouples distance-based suppression from token importance through querydependent and keydependent gates,
Tom: First, who's behind it and why it matters.
Title and authors: Tom: So we're looking at this paper, "Remember to Forget: Gated Adaptive Positional Encoding," and it’s authored by Riccardo Ali, Alessio Borgi, Mario Severino, and Pietro Liò. The title itself suggests something about forgetting or remembering context.
Jane: Yeah, that sounds intriguing because it tackles a known problem with Rotary Positional Encoding, which is RoPE. We've heard that when you extend the sequence length beyond what the model was trained on, those rotary phases can get into out-of-distribution regimes, leading to spurious long-range alignments and degraded retrieval.
Lu: Exactly. Existing fixes like p-RoPE are trying to mitigate this trade off by leaving some channels unrotated, but they’re effectively just increasing the wavelengths, so they're still exposed to the same underlying instabilities that RoPE has.
Meng: So what's new here? Is it just another tweak to the rotation angles? We need something that handles context importance differently than just distance.
Tom: That’s right. GAPE introduces a drop-in augmentation for positional encodings that uses a content-aware mask directly on the attention logits, which preserves the underlying rotary geometry but adds adaptive routing signals.
Jane: So how does it actually work in plain terms? It seems to decouple distance-based suppression from what's actually important about each token.
Lu: It achieves this through two adaptive routing signals: a query gate that controls how strongly a query token contracts its context, and a key landmark that protects keys from distance-based penalization.
Meng: A key landmark sounds like it’s essentially marking important tokens so they don't get penalized by the distance calculation. That’s what I need to see if it actually helps at scale.
Tom: It does, and this mechanism selectively suppresses irrelevant background context while preserving distant useful information without changing the underlying rotary geometry itself.
Jane: That selective suppression sounds like exactly what we need when dealing with long documents where you want the model to focus on specific relevant pieces of information rather than getting lost in noise.
The paper's summary: Tom: Let’s talk about the core idea of "Remember to Forget: Gated Adaptive Positional Encoding." The authors are proposing GAPE as a way to address the limitations we talked about earlier with RoPE and its variants.
Jane: So, what is this paper actually saying in terms of solving that problem? It seems they recognize that robust long-context modeling needs both high-resolution local structure and stable, selective attenuation of irrelevant distant information.
Lu: They argue that RoPE keeps the precise local relative geometry, but it lacks a native way to explicitly attenuate irrelevant long-range context. Conversely, additive encodings like ALiBi stabilize contexts through explicit distance penalties but impose rigid suppression that can erase useful distant signals.
Meng: So GAPE is trying to combine those two things without forcing a fixed trade off between local detail and long-range stability.
Tom: Precisely. GAPE augments the native rotary geometry with a data-dependent content-aware mask over the attention logits, introducing these two adaptive routing signals. The query gate, which we can call 'gi', controls how strongly each query token contracts its context.
Jane: And then you have the key landmark 'lj', which continuously protects selected keys from distance-based suppression. It’s like a switch for how much protection a specific key gets from that distance penalty.
Lu: The paper shows that these components work together to suppress irrelevant long-range context while preserving distant information, complementing RoPE’s positional geometry with adaptive structural routing.
Tom: They even report improved perplexity in 2B-parameter models when they use this method, which is a pretty strong signal for the stability of the model's behavior <ref:2605.10414#pg1>.
Jane: That’s significant because it shows that this isn't just a theoretical fix; it translates into better performance on actual language modeling tasks under extended contexts.
The paper's improvements: Tom: So, let’s look at the specific improvements the authors detail in "Remember to Forget: Gated Adaptive Positional Encoding." They break down how this works structurally.
Jane: The core idea is that the query gate 'gi' adapts to the retrieval regime; close targets induce larger values and therefore stronger contraction, whereas far targets keep gi near zero, which preserves a broader effective horizon.
Lu: And then you have the key landmark 'lj' continuously protecting selected keys from distance-based suppression; it approaches one, meaning full protection for those specific keys.
Meng: So the query gate is dynamic based on the query itself, and the landmark gate is dynamic based on which key we’re looking at. That seems like a lot of computation if you have to calculate these gates for every token in every layer.
Tom: The good news from their analysis is that this structural bias is realized exactly as a rank-at-most-two correction to the pre-softmax logits through the same matrix multiplication used for attention.
Jane: That means it's implemented in a way that’s compatible with things like FlashAttention, which is great because it keeps the computational cost manageable.
Lu: They also show that GAPE learns non-uniform head-wise masks, where some heads develop strong biases while others remain weakly biased, which suggests the model learns to specialize its attention routing.
Meng: So if we deploy this, we have to worry about head specialization. Does that mean different parts of the model will behave very differently depending on what they’re processing?
Tom: It means different heads learn different routing strategies based on their specific task needs, which is a sign of a flexible architecture.
Conclusion: Jane: So to wrap up this discussion on "Remember to Forget: Gated Adaptive Positional Encoding," the main implication is that GAPE successfully separates context contraction from key preservation. The query gate 'gi' controls how strongly the current query contracts distant context, while the landmark gate 'lj' continuously modulates how strongly each key is exposed to that contraction.
Tom: And the head-specific amplitude, h, calibrates the overall strength of this structural pathway. It retains selected distant information while suppressing weakly protected background context, and its factorized form is compatible with fused SDPA and FlashAttention.
Lu: The results support the complementary roles of positional extrapolation and adaptive structural routing, showing how they can work together effectively in practice.
Meng: From an engineering standpoint, the fact that this can be retrofitted into a pretrained 7B model without degrading standard capabilities suggests it’s a very practical enhancement for production systems.
Lalam: I'm confident in my assessment; GAPE retains selected distant information while suppressing weakly protected background context, and its factorized form is compatible with fused SDPA and FlashAttention.
Tom: So, the big picture here is that we have a mechanism that handles long-context generalization better than before, achieved through adaptive structural routing. That’s what we’ve got on "Remember to Forget: Gated Adaptive Positional Encoding."
More episodes
- 2510.25599-Uncertainty Quantification for Regression: A Unified Framework based on kernel scores
- 2602.19661-PaReGTA: A Temporally Aware LLM-Based Patient Representation Framework for EHR Analytics
- 2509.25606-Effective Model Pruning: Measure The Redundancy of Model Components
- 2605.07808-The Minimax Rate of Perturbed Second-Order Calibration
- 2601.22879-Synthetic Time Series Generation via Complex Networks
- 2605.12174-Expected Batch Optimal Transport Plans and Consequences for Flow Matching
- 2606.01081-Decision-Focused On-Policy Learning for Contextual Linear Optimization with Partial Feedback
- 2610.07713-Neuromotor Hierarchy Network: Physiological Inductive Biases for Robust Generalization in sEMG Decoding
- 2510.04440-Fractional Heat Kernel for Semi-Supervised Graph Learning with Small Training Sample Size
- 2604.07341-ReCodeAgent: A Multi-agent Workflow for Language-Agnostic Translation and Validation of Large-Scale Repositories