Transformers are Multi-State RNNs

Matanel Oren, Michael Hassid, Nir Yarden, Yossi Adi, Roy Schwartz
1/11/2024
cs.CL

Official code: schwartz-lab-NLP/TOVA (129 stars, Apache-2.0, last commit 2024-10-13).

Abstract

Transformers are considered conceptually different from the previous generation of state-of-the-art NLP models - recurrent neural networks (RNNs). In this work, we demonstrate that decoder-only transformers can in fact be conceptualized as unbounded multi-state RNNs - an RNN variant with unlimited hidden state size. We further show that transformers can be converted into $\textit{bounded}$ multi-state RNNs by fixing the size of their hidden state, effectively compressing their key-value cache. We introduce a novel, training-free compression policy - $\textbf{T}$oken $\textbf{O}$mission $\textbf{V}$ia $\textbf{A}$ttention (TOVA). Our experiments with four long range tasks and several LLMs show that TOVA outperforms several baseline compression policies. Particularly, our results are nearly on par with the full model, using in some cases only $\frac{1}{8}$ of the original cache size, which translates to 4.8X higher throughput. Our results shed light on the connection between transformers and RNNs, and help mitigate one of LLMs' most painful computational bottlenecks - the size of their key-value cache. We publicly release our code at https://github.com/schwartz-lab-NLP/TOVA

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Token Omission Via Attention

1296PythonJan 10, 20242 years agoApache-2.0

Similar Papers

Cite this paper

@article{oren2024transformers,
  title  = {Transformers are Multi-State RNNs},
  author = {Matanel Oren and Michael Hassid and Nir Yarden and Yossi Adi and Roy Schwartz},
  year   = {2024},
  eprint = {2401.06104},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2401.06104v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2401.06104.svg)](https://codeofpaper.com/paper/2401.06104)

Discussion