NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Selective Attention Improves Transformer

Yaniv Leviathan, Matan Kalman, Yossi Matias

TL;DR

Selective Attention is a parameter-free modification to the standard Transformer architecture that allows tokens to "mask out" previous entries in the context buffer they deem irrelevant. This simple change not only boosts model quality—matching the performance of standard models with twice the attention parameters—but also enables massive inference speedups by pruning up to 47x of the memory required for the attention module.

The Problem: The Hoarding Habit of Transformers

Transformers are famously "hoarders." By design, the standard attention mechanism forces every new token to look back at every single previous token in its history. While this allows for perfect recall (useful for tasks like copying text), it creates two major issues:

  1. Noise: As the context grows, irrelevant or ambiguous tokens act as "noise," making it harder for the model to focus on what actually matters.
  2. Efficiency: Storing and processing every token leads to the well-known quadratic ($O(n^2)$) cost in memory and computation, which becomes a massive bottleneck for long-sequence inference.

While Recurrent Neural Networks (RNNs) and State Space Models (SSMs) try to solve this by compressing history into a fixed-size "sketch," they often lose the ability to perform tasks requiring precise recall. This paper asks: Can we design a model that persists just the right amount of context?

Methods: The Mechanics of Forgetting

The authors introduce Selective Attention, a mechanism where a token can decide that a previous token is no longer needed, effectively "masking" it for all future tokens.

  • The Selection Function: Instead of adding new weights, the model reuses the output of one of its existing attention heads to determine which tokens to forget. This makes the method entirely parameter-free.
  • Accumulation: The model produces a masking matrix. If token $B$ decides token $A$ is irrelevant, it adds to a cumulative "forgetting" score. Future tokens then subtract this score from their attention logits before the softmax step.
  • Constraints: To keep training stable, the authors apply three simple rules: they use a ReLU to ensure they only reduce attention (never boost it), they never mask the "Beginning of String" (<BOS>) token, and tokens are forbidden from masking themselves.
  • Context Pruning: During inference, once a token’s forgetting score crosses a certain threshold, it is evicted from the KV-cache entirely. This turns a soft masking mechanism into a hard memory saving.
Visualization of Selective Attention masking tokens across various tasks.

Key Insights

  • Quality through Forgetting: The most striking insight is that "forgetting" actually makes the model smarter. By removing unneeded elements, the circuitry of the attention mechanism can focus on relevant signals. A model with selective attention performs as well as a standard model with ~2X more heads and parameters in its attention modules.
  • The "Absorption" Hypothesis: The authors observed that tokens often mask previous ones after they have "absorbed" their meaning. For example, in the name "Barack Obama," the final token "Obama" might mask "Barack" because the semantic entity is now fully captured.
  • Dynamic Memory Budgets: Unlike "sliding window" attention (which forgets based on distance), Selective Attention forgets based on content. Some layers remain "dense" (keeping almost everything), while others become "sparse," keeping only a few critical tokens for long periods.

Key Results

The researchers evaluated Selective Attention across language modeling (C4, WikiText) and downstream reasoning benchmarks (ARC, HellaSwag, PiQA, etc.), as well as synthetic tasks testing logic and recall.

Validation log-perplexity improvements across context lengths and model parameters.
  • Performance Boost: Selective Attention consistently improved perplexity across all model sizes ($d=16$ to $d=28$) and context lengths. On the ARC-Easy benchmark, the selective model ($d=28$) achieved 46.95% zero-shot accuracy compared to the baseline's 45.64%.
  • Massive Memory Reductions: Because the model learns what is useless, those tokens can be thrown away during inference. When matching the validation perplexity of a standard Transformer, Selective Attention models required:
  • 16X less memory for a 512-token context.
  • 25X less memory for a 1,024-token context.
  • 47X less memory for a 2,048-token context.

Limitations and Future Work

  • Scale: The experiments were conducted on models up to ~1.1B parameters. Testing on "frontier-scale" models (100B+ parameters) remains for future work.
  • Architecture Variants: The study focused on decoder-only Transformers. More research is needed for multi-query and group-query attention variants.
  • Training Efficiency: Currently, the memory savings are realized during inference. The authors suggest that future work could explore reducing the context buffer during training to speed up the learning process itself.
  • Fine-tuning: The current results are based on pre-training. It is yet to be seen how easily this can be integrated into existing pre-trained models via fine-tuning.

Summary updated

BibTeX
@inproceedings{leviathan2025selective,
  author = {Yaniv Leviathan and Matan Kalman and Yossi Matias},
  title = {{Selective Attention Improves Transformer}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=v0FzmPCd1e},
}
Figure