Transformers are Multi-State RNNs

Matanel Oren, Michael Hassid, Yarden Nir, Yossi Adi, Roy Schwartz

Abstract

This paper reveals that decoder-only Transformers are a generalized form of Recurrent Neural Networks (RNNs) characterized by an "unbounded" hidden state. To mitigate the linear memory growth associated with this state—the Key-Value (KV) cache—we introduce TOVA (Token Omission Via Attention). TOVA is a training-free compression policy that dynamically prunes the KV cache based on attention signals. Our results demonstrate that TOVA can reduce the memory footprint by up to 88% and boost throughput by 4.8x while maintaining nearly full-model performance across long-context tasks.

Introduction

Large Language Models (LLMs) are increasingly deployed for long-context tasks like document summarization and multi-turn dialogue. However, their inference efficiency is bottlenecked by the KV cache, which stores representations of all previous tokens to avoid redundant computation. As sequences grow, the KV cache expands linearly, leading to a "memory wall" that limits sequence length and slows down processing. Existing compression methods often rely on static heuristics, such as local windows, which risk discarding critical long-range dependencies.

Transformers as Multi-State RNNs

A key contribution of this work is the formal redefinition of decoder-only Transformers as Multi-State RNNs (MSRNNs). In this framework, the KV cache is viewed as the recurrent state of the model. Standard Transformers are "unbounded" MSRNNs because their state size increases with every new token generated.

Standard Transformers function as unbounded MSRNNs where the query attends to the entire history of KV pairs.

By framing Transformers this way, the challenge of long-context inference becomes a problem of state management: how can we bound the size of this multi-state memory without losing essential information?

TOVA: Token Omission Via Attention

To create a "bounded" MSRNN, we propose TOVA, a "plug-and-play" policy that requires no additional training. TOVA leverages the model's internal attention mechanism to decide which tokens are worth keeping in the cache. At each decoding step:

  1. The model generates a new token and computes attention scores for all tokens in the current cache.
  2. These scores are averaged across all attention heads within a layer.
  3. If the cache reaches its predefined capacity, the token with the lowest average attention score is evicted.
TOVA creates a bounded MSRNN by selectively retaining high-importance tokens while omitting others.

Unlike fixed-window approaches, TOVA allows the model to dynamically preserve "anchor" tokens from the distant past if they remain relevant to the current generation.

Experimental Results

We evaluated TOVA using 7B-parameter models (LLaMA-2, Mistral, Yi) across several benchmarks:

  • Language Modeling (PG-19): TOVA maintained low perplexity even when extrapolating to 70,000 tokens—far beyond the models' original training limits.
  • Long-range Understanding (ZeroSCROLLS): On tasks like SQuALITY (summarization) and QASPER (QA), TOVA matched full-model performance using only 1/8th of the original cache size.
  • Efficiency: By reducing memory pressure, TOVA enabled larger batch sizes, resulting in a 4.8x increase in throughput.

Key Insights

Our analysis of TOVA's retention patterns yielded several insights into Transformer behavior:

  • The First Token Anchor: TOVA almost never evicts the very first token. This token serves as an "attention sink," a phenomenon where the model directs residual attention to a fixed position.
  • Linguistic Selectivity: The policy disproportionately retains proper nouns and possessive markers (e.g., "'s"), suggesting these are vital for maintaining narrative coherence.
  • Non-Local Importance: While recent tokens are frequently important, they only constitute ~75% of the retained cache; the remaining 25% are critical tokens scattered throughout the history.

Conclusion

By treating Transformers as Multi-State RNNs, we provide a theoretical foundation for KV cache compression. TOVA demonstrates that the attention mechanism itself is a powerful heuristic for state management, allowing for massive gains in efficiency without sacrificing the long-range capabilities that make Transformers so effective.

Summary updated

BibTeX
@inproceedings{oren2024transformers,
  author = {Matanel Oren and Michael Hassid and Yarden Nir and Yossi Adi and Roy Schwartz},
  title = {{Transformers are Multi-State RNNs}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.1043},
}
Figure