- Introduced by
- Nikita Kitaev, Łukasz Kaiser & Anselm Levskaya
- Year
- 2020
- Type
- Memory-efficient attention-based sequence model
- Family
- Time-series forecasting
What does it do?
The Reformer is an efficient variant of the Transformer, introduced by Kitaev, Kaiser, and Levskaya at ICLR 2020.
It targets the cost of standard self-attention, which grows quadratically with sequence length, using two mechanisms: locality-sensitive hashing (LSH) attention, which restricts each query to a subset of keys, and reversible residual layers, which reduce the activations that must be stored during training.
The intuition behind the method
Standard attention compares every position with every other position. LSH attention first groups vectors that are likely to be similar into buckets, so each position attends only to positions in its own bucket. For long inputs this means far fewer comparisons. Reversible layers address the second cost: instead of storing every intermediate activation for the backward pass, the network recomputes them from the layer above. Together these allow longer sequences to fit in memory than a standard Transformer of comparable depth would allow.
History
Kitaev, Kaiser, and Levskaya introduced the Reformer at ICLR 2020 to reduce the memory and compute costs that limit Transformers on long sequences. It combines locality-sensitive hashing, drawn from the information-retrieval literature, with reversible residual networks based on RevNet. The paper reports training on sequences of up to 64 000 tokens. Forecasting use of the architecture is an adaptation rather than the setting the method was originally built around.
When to use it
Choose the Reformer when the input sequence is long enough that standard self-attention is the binding memory or compute constraint, and when a Transformer-style model is the intended family. The original paper evaluated language modelling, image generation and similar long-sequence tasks, not forecasting. Using the Reformer for forecasting with long historical context is an adaptation, and its accuracy must be validated on held-out data against a standard Transformer baseline. Do not choose it for short sequences, where full attention is affordable and the hashing overhead can outweigh the saving; a standard Transformer is then the simpler baseline. Avoid it when exact attention weights are required, since LSH attention is an approximation. Compare against the vanilla Transformer and the other long-sequence models listed in this library before committing.
Limitations and considerations
- LSH attention is an approximation: a relevant long-range pair is missed if its query and key do not share a bucket in any hashing round
- Additional hashing rounds improve recall but add computation and implementation complexity, so recall and cost must be traded off
- Reversible layers change the residual wiring of standard blocks and require recomputing activations during backpropagation, which adds compute and complicates integration with existing model code
- For short sequences the bucketing overhead can make the Reformer slower than standard attention, so the efficiency advantage is not automatic
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Replaces full pairwise self-attention with bucket-restricted attention, reducing the cost from O(L²) to O(L log L) for long sequences
- Reversible residual layers reduce activation memory from O(depth × L) to O(L) by recomputing intermediate activations during the backward pass, which makes deeper models feasible on long inputs
- Chunked feed-forward evaluation lowers peak memory without changing the output, because the sublayer acts independently at each position
- Keeps the Transformer block structure, so an existing encoder design can be adapted by changing the attention and residual wiring rather than the whole model
Applications
- Long-document language modelling, the setting in which the architecture was introduced
- Long-sequence generation tasks such as image generation
- Long-horizon forecasting with extended historical context, as an adaptation of the architecture
- Analysis of long biological sequences, such as genomic data, as a candidate application
How it works
How it works
Queries and keys share a single projection (shared-QK), and the shared vectors are hashed into buckets using random projections, so similar vectors are likely to share a bucket. Tokens are sorted by bucket, the sorted sequence is split into fixed-size chunks, and each chunk attends within itself and to the neighbouring chunk, so the softmax sums run only over keys in the same bucket or adjacent chunk rather than over all L positions. In decoder use a causal mask also applies. Under these choices the cost falls from O(L²) toward O(L log L); this is an approximation that depends on the bucketing and chunking. Several independent hashing rounds are run, which raises the chance that a relevant pair shares a bucket in at least one round, at additional cost.
Formula
\text{Attention}(Q,K,V) \approx \sum_{i} \frac{\exp(q_i \cdot k_{\pi(i)} / \sqrt{d_k})}{\sum_j \exp(q_i \cdot k_{\pi(j)} / \sqrt{d_k})} v_{\pi(i)}, \quad \pi = \text{LSH-bucket sort}The hidden state is split into two streams, x1 and x2, and each layer updates one stream using a function of the other, following the RevNet scheme. Because a layer's inputs can be recovered exactly from its outputs, the backward pass can recompute activations instead of storing them. Activation memory then no longer grows with network depth, at the cost of extra computation during backpropagation.
Formula
x_1^{l+1} = x_1^l + F(x_2^l), \quad x_2^{l+1} = x_2^l + G(x_1^{l+1})The position-wise feed-forward sublayer is applied to the sequence in chunks of size c. Its computation is independent across positions, so chunking gives the same output while limiting peak memory to one chunk rather than the full sequence.
Formula
\text{FF}(x) = W_2 \, \text{ReLU}(W_1 x), \quad \text{computed in chunks of size } c \ll LA forecasting head is not part of the original design and is not defined in the Reformer paper. In a forecasting adaptation, the final hidden state h_T is mapped by a linear layer W_o to H future values. The head is a user-side design choice rather than a property of the Reformer, and it is usually trained with a regression loss such as MSE or MAE on sliding windows.
Formula
\hat{y}_{t+1:t+H} = W_o \, h_T, \quad h_T \in \mathbb{R}^{d_{\text{model}}}Common pitfalls
- Too few hashing rounds underestimate long-range dependencies, while too many rounds erode the efficiency gain; the round count should be tuned on validation data
- Assuming the approximation error is negligible without checking on held-out data can hide accuracy loss, because the model still trains and produces plausible-looking forecasts
- Reporting the Reformer alone hides the cost of approximation: always report a full-attention baseline at the same sequence length and on the same split, and measure the accuracy change alongside wall-clock time and memory use
- Using the Reformer on short sequences trades speed and often accuracy for little gain; a simpler baseline is usually the better first step
- Setting the bucket size or chunk count without regard to sequence length can give a poor memory-accuracy balance; both should be set together and checked empirically
Frequently asked questions
How does LSH attention differ from standard multi-head attention?
Standard multi-head attention computes dot products between every query-key pair, giving O(L²) cost. LSH attention first hashes queries and keys into buckets using random projections, then restricts attention to within-bucket pairs. Because similar vectors tend to land in the same bucket, most relevant interactions are preserved while cost drops to O(L log L). Multiple hash rounds increase recall at proportional cost.
What are reversible residual layers and why do they save memory?
Reversible layers, adapted from RevNet, split the residual stream into two halves updated alternately. Given the output of a layer, its input can be exactly recomputed during backpropagation, so intermediate activations do not need to be stored. This reduces activation memory from O(depth × L) to O(L), which is the main saving that lets deep Reformers run on long sequences.
Is the Reformer suitable for short time-series tasks?
Generally not. When sequences are short, full attention is affordable, and the bucketing and recomputation overhead may make the Reformer slower without an accuracy gain. A standard Transformer or a simpler baseline is a more sensible first choice. No single length threshold is established for this decision. The deciding questions are whether standard attention memory is the binding constraint on your hardware and whether the approximation error is acceptable on held-out data.
Related methods
Sources
Kitaev, N., Kaiser, Ł., & Levskaya, A. (2020). Reformer: The efficient transformer. ICLR.
Open publication reference