Block-Recurrent Transformers

DeLesley Hutchins, Imanol Schlag, Yuhuai Wu, Ethan Dyer, Behnam Neyshabur
3/11/2022
169 citations
cs.LGcs.AIcs.NE
transformer-attention

Official code: google-research/meliad (261 stars, Python, Apache-2.0, last commit 2025-06-06).

Abstract

We introduce the Block-Recurrent Transformer, which applies a transformer layer in a recurrent fashion along a sequence, and has linear complexity with respect to sequence length. Our recurrent cell operates on blocks of tokens rather than single tokens during training, and leverages parallel computation within a block in order to make efficient use of accelerator hardware.

Show full abstract

The cell itself is strikingly simple. It is merely a transformer layer: it uses self-attention and cross-attention to efficiently compute a recurrent function over a large set of state vectors and tokens. Our design was inspired in part by LSTM cells, and it uses LSTM-style gates, but it scales the typical LSTM cell up by several orders of magnitude. Our implementation of recurrence has the same cost in both computation time and parameter count as a conventional transformer layer, but offers dramatically improved perplexity in language modeling tasks over very long sequences. Our model out-performs a long-range Transformer XL baseline by a wide margin, while running twice as fast. We demonstrate its effectiveness on PG19 (books), arXiv papers, and GitHub source code. Our code has been released as open source.

View on arXivView PDF

Code Implementations(1)

Apache-2.0
26127PythonMay 26, 20221 years agoApache-2.0

Similar Papers

Cite this paper

@article{hutchins2022blockrecurrent,
  title  = {Block-Recurrent Transformers},
  author = {DeLesley Hutchins and Imanol Schlag and Yuhuai Wu and Ethan Dyer and Behnam Neyshabur},
  year   = {2022},
  eprint = {2203.07852},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2203.07852}
}

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/2203.07852.svg)](https://codeofpaper.com/paper/2203.07852)

Discussion