Attendre: Wait To Attend By Retrieval With Evicted Queries in Memory-Based Transformers for Long Context Processing

Zi Yang, Nan HuaarXiv 2024 · DOI

Abstract

Large Language Models (LLMs) face significant challenges in processing long sequences due to the quadratic complexity of self-attention and the limitations of unidirectional causal memory. We present ATTENDRE, a novel architecture that enables bidirectional attention in a streaming context by delaying query processing. By buffering queries in a dedicated memory and utilizing importance-based eviction policies (LRA/LFA), ATTENDRE achieves superior performance and memory efficiency compared to standard FIFO-based memory systems.

Introduction

The ability to process long contexts is critical for tasks like multi-document reasoning and long-form summarization. While chunking and Key-Value (KV) memory provide a partial solution, they are typically constrained by causality—queries can only attend to past tokens. This prevents the use of bidirectional architectures in streaming scenarios. Furthermore, standard memory management often relies on First-In, First-Out (FIFO) eviction, which fails to preserve the most relevant information.

Methodology

The ATTENDRE Layer

The core innovation of this work is the ATTENDRE layer, which introduces a "wait-and-see" approach to attention. Instead of immediate execution, queries are stored in a Query-memory (Q-memory). As the model ingests subsequent text chunks into its KV-memory, the buffered queries eventually reach their "future" context.

Figure 3: (a) High-level architecture of the ATTENDRE layer. (b) Detailed flow showing how queries are buffered and eventually matched against a populated KV-memory.

When a query is evicted from the Q-memory, it performs retrieval against the current state of the KV-memory, which now contains tokens that were originally ahead of it in the sequence. This mechanism effectively bridges the gap between streaming efficiency and bidirectional modeling.

Streaming and Temporal Shifting

To maintain consistency across layers, the model employs a temporal shift. This ensures that at any given step, the memory contains a sufficient window of context for the delayed queries to produce meaningful outputs.

Figure 5: Visualization of the streaming process across multiple Transformer layers. The grey boxes indicate zero-padding or shifted contexts used to manage the temporal delay.

Smart Eviction Policies

Beyond the architectural shift, we propose two attention-aware eviction policies:

  • Least Recently Attended (LRA): Prioritizes tokens that have been frequently accessed by recent queries.
  • Least Frequently Attended (LFA): Maintains tokens with high cumulative attention scores over the entire sequence.

These policies treat attention scores as a proxy for token importance, allowing the model to retain "globally useful" information while discarding noise.

Experimental Setup

We evaluated ATTENDRE on the TriviaQA dataset, a benchmark for long-context reading comprehension. We tested two primary model architectures:

  1. PaLM 2-S: A decoder-only model.
  2. FLAN-T5 XXL: An encoder-decoder model, which traditionally requires bidirectional attention for optimal performance.

Results and Discussion

Our experiments demonstrate that ATTENDRE significantly improves both efficiency and accuracy.

  • Memory Efficiency: Smart eviction (LRA/LFA) allows a memory of just 128 slots to match the performance of a 2,048-slot FIFO memory, representing a 16x improvement in memory utilization.
  • Performance Gains: On TriviaQA, the PaLM 2-S model with ATTENDRE achieved an Exact Match (EM) score of 63.40, outperforming the full-sequence baseline (59.27).
  • Bidirectional Support: ATTENDRE enabled FLAN-T5 XXL to scale to long contexts in a streaming fashion, a feat previously difficult for encoder-decoder models using standard causal memory.

Conclusion

ATTENDRE offers a robust solution for long-context processing by rethinking the temporal constraints of attention. By delaying queries and using importance-based memory management, we can achieve bidirectional capabilities with high memory efficiency. Future work will explore differentiable eviction mechanisms and broader task evaluations.

Summary updated

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
TriviaQAOriginal PaLM 2-S (no memory)mean EM59.27input-sequence-length=4,196
Source quote
L191: Our first observation is that even when we set M to 128, i.e. we keep the attendee pool size identical to the vanilla attention mechanism, the LRA and LFA policies can still achieve reasonable performance (up to 50.74), much higher than the MT and the AS baselines, and close to the original PaLM 2-S model when the sequence length is 2,048 (53.88). The AS policy, which keeps the four initial positions, including the initial two tokens in the question, helps it outperform the MT. When we further increase M to 2,048, we see the performance of the baseline methods MT and AS greatly improves (+2,062.39% and +344.11% respectively), suggesting the benefit of additional attendees in the extended context windows. However, the performance of our methods only marginally improves (+4.4%), suggesting that the LRA and LFA policies can effectively select positions to keep in the memory even when the memory size is small. We also see that our methods continue to outperform the baselines, confirming the effectiveness of the proposed automatically adaptive LRA and LFA policies. Then, we add the Q memory and set the size of the Q memory (N) to half the size of the K/V memory (M). We see that, in contrast to the baseline methods, our methods continue to benefit from the additional Q memory. With 1024 K/V memory slots and 512 Q memory slots, the LFA\textsubscript{max} policy enables the PaLM 2-S model, using a chunk size of 128, to achieve an average EM of 63.40, higher than the EM obtained by the original PaLM 2-S model using an input length of 4,196 (59.27).
TriviaQAOriginal FLAN-T5 XXL (no memory)mean EM57.80input-sequence-length=4,196
Source quote
L204: 3.53 │ 8.24 │ 17.86 │ 31.70 │ 48.77 │ 57.80
TriviaQAOriginal PaLM 2-S (no memory)mean EM53.88input-sequence-length=2,048
Source quote
L163: 2.26 │ 9.62 │ 24.24 │ 39.94 │ 53.88 │ 59.27
BibTeX
@misc{yang2024attendre,
  author = {Zi Yang and Nan Hua},
  title = {{Attendre: Wait To Attend By Retrieval With Evicted Queries in Memory-Based Transformers for Long Context Processing}},
  year = {2024},
  eprint = {2401.04881},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.04881},
}
Figure