Radar: Fast Long-Context Decoding for Any Transformer

Yongchang Hao, Mengyao Zhai, Hossein Hajimirsadeghi, Sepidehsadat Hosseini, Frederick Tung

TL;DR

Radar is a training-free, "plug-and-play" method that dramatically speeds up Transformer inference on long documents. By using random features to quickly find the most relevant parts of the context, it reduces the standard quadratic time bottleneck to a much more manageable sub-linear complexity per step. Crucially, it achieves this while maintaining high accuracy and requiring zero model retraining.

The Problem: The Quadratic Bottleneck of Attention

The "Achilles' heel" of the Transformer architecture is its self-attention mechanism. To generate a new word, the model must compare it against every single previous word in the conversation or document. This "dot-product attention" scales quadratically ($O(t^2)$): doubling the length of your text requires four times as much computational work.

For modern applications like analyzing entire codebases or parsing long legal documents, this becomes a massive bottleneck. Existing solutions usually fall into two camps:

  1. Retraining: Modifying the architecture to be more efficient, which is incredibly expensive for large, pre-trained models.
  2. Heuristic Eviction: Simply "forgetting" or deleting older tokens to save space. However, this often leads to "information loss"—for example, a coding assistant might forget a critical function definition that appeared 5,000 tokens ago, causing the model's logic to fail.

Radar provides a third way: keep the full context accessible, but search it intelligently and efficiently.

Methods: A Hierarchical Approach to Attention

Radar (which stands for range search decoding accelerated by random features) introduces a hierarchical approach to attention that avoids exhaustive token-by-token comparisons.

  • Hierarchical Segments: Instead of looking at every token individually, Radar groups the context into contiguous segments.
  • Random Feature Mapping: It uses a technique called "attention kernelization" (specifically the Positive Random Features method). This maps high-dimensional keys and queries into a space where their importance can be approximated by a simple, fast inner product.
  • Summarization Representations: Each segment is assigned a "summary" vector, calculated as the average of the random features of the tokens within it.
Radar's two-step search mechanism

When generating a new token, Radar employs a Two-Step Search:

  1. Coarse Search: The model first compares the new query against the segment summaries to find the top-$k$ most important segments.
  2. Fine Attention: It then performs exact, standard attention only on the tokens within those selected segments (alongside a small "sliding window" of the most recent tokens).

To keep the math optimal, Radar periodically resizes its segments as the document grows, ensuring the per-step complexity stays at $O(\sqrt{t})$ rather than $O(t)$, reducing the total complexity of generating $t$ tokens from $O(t^2)$ to $O(t^{1.5})$.

Key Results and Insights

The authors evaluated Radar across several challenging long-context scenarios, including PG-19 (long-form books), The Stack (large-scale source code), and LongBench (a comprehensive benchmark featuring 16 subtasks like multi-doc QA and summarization).

Unlike heuristic methods that rely on "gut feelings" about which tokens to keep, Radar is backed by mathematical proofs guaranteeing it will identify the most important segments with high probability. Because it doesn't permanently "evict" tokens, a piece of information that is irrelevant now can be "rediscovered" later if it becomes important for a future query.

Perplexity and Elapsed Time comparisons
  • Significant Speedup: Radar achieved more than a 2x speedup compared to vanilla attention on long sequences. Its generation throughput stays relatively stable as context grows.
  • Minimal Quality Loss: In perplexity tests, Radar stayed within ~0.2 points of the "perfect" (but slow) vanilla attention. In contrast, eviction-based methods like StreamingLLM saw their error rates skyrocket as they deleted critical context.
  • Superior Accuracy: On the LongBench suite, Radar consistently outperformed other training-free methods like StreamingLLM, H2O, and SnapKV, often achieving the highest average scores across different model architectures.
  • High Efficiency: Remarkably, on Mistral-7B, Radar achieved performance close to the full-attention baseline while only actually computing attention over about 13% of the total tokens.

Limitations and Future Work

While Radar is significantly faster, it does not solve the "KV cache" memory problem. It still stores all tokens in memory (and uses slightly more memory to store the segment summaries); it simply avoids computing attention over all of them.

Currently, Radar selects contiguous blocks of tokens, but exploring non-contiguous or "sparse" segmenting strategies might yield further improvements. Additionally, integrating Radar with low-level hardware kernels like FlashAttention could unlock even greater speed gains in practical deployments.

Summary updated

BibTeX
@inproceedings{hao2025radar,
  author = {Yongchang Hao and Mengyao Zhai and Hossein Hajimirsadeghi and Sepidehsadat Hosseini and Frederick Tung},
  title = {{Radar: Fast Long-Context Decoding for Any Transformer}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=ZTpWOwMrzQ},
}
Figure