Introduction
The Reformer introduces two key innovations—Locality-Sensitive Hashing (LSH) attention and reversible residual layers—to slash the memory and computational costs of the Transformer architecture. These changes allow the model to handle sequences up to 64,000 tokens on a single GPU, shifting the complexity of attention from $O(L^2)$ to $O(L \log L)$ without sacrificing state-of-the-art performance.
The Long-Sequence Bottleneck
Since their introduction, Transformers have dominated natural language processing, but they are notoriously "memory-hungry." As researchers push for longer context windows to process entire books or high-resolution images, they hit two major bottlenecks:
- The Attention Bottleneck: Standard dot-product attention compares every token to every other token. For a sequence of length $L$, this requires $O(L^2)$ time and memory. A 64K sequence would require a massive 16GB just to store the attention matrix.
- The Activation Bottleneck: To perform backpropagation, standard models store the activations for every single layer. In a deep model with $N$ layers, memory usage scales linearly with $N$, making it impossible to fit large models on consumer-grade hardware.
The Reformer aims to make these models efficient enough to run on a single accelerator while maintaining the modeling capacity of the original Transformer.
Core Innovations
Locality-Sensitive Hashing (LSH) Attention
Instead of computing all $L^2$ pairs, the Reformer uses Locality-Sensitive Hashing (LSH) to group similar vectors into "buckets." Because the softmax function in attention is dominated by the largest elements (i.e., the most similar key-query pairs), the model only needs to compute attention for pairs that fall into the same bucket.
To make this efficient, the Reformer uses Shared-QK attention, where the Query and Key projections are identical ($Q=K$). Surprisingly, forcing the model to use the same weights for Queries and Keys does not hurt performance, and it ensures that queries and keys that should attend to each other end up in the same LSH buckets.
As shown above, the sequence is first bucketed using LSH, sorted by those buckets, and then chunked to parallelize computation. Tokens then only attend to other tokens within the same bucket in their own chunk and the previous chunk. This reduces the overall attention complexity to $O(L \log L)$. Because LSH is probabilistic, multiple rounds of hashing can be performed to close any accuracy gap with full attention.
Reversible Residual Layers
Borrowing from RevNets, the authors replace standard residual layers with reversible ones. In a reversible layer, the activations of layer $i$ can be mathematically recomputed from the activations of layer $i+1$. This means the model only needs to store a single copy of activations for the entire network during training, rather than $N$ copies, breaking the linear memory scaling with depth.
Feed-Forward Chunking
The authors save additional memory by processing the large intermediate feed-forward layers in smaller chunks. Since these computations are independent across the sequence dimension, they can be calculated sequentially, trading a small amount of compute time for a massive reduction in peak memory usage.
Key Results and Performance
The Reformer was evaluated on several tasks requiring long-range dependencies, including enwik8 (character-level language modeling up to 64K tokens), imagenet-64 (image generation treating pixels as sequences), and WMT 2014 English-to-German translation.
- Performance Parity: On the WMT translation task, the Reversible Transformer achieved a BLEU score of 29.1, nearly identical to the "big" Transformer baseline (29.3), proving that reversibility doesn't sacrifice quality.
- Efficiency on Long Sequences: On the enwik8 task, the Reformer matched the performance of full-attention models while being significantly faster and more memory-efficient as sequence length increased. While regular attention speed drops off a cliff as sequences get longer, LSH attention speed remains nearly flat.
- Hardware Accessibility: Thanks to these optimizations, the Reformer successfully trained 20-layer models on 64K sequences on a single accelerator—a feat that previously required massive compute clusters.
Limitations and Future Directions
While highly efficient for long sequences, LSH does introduce overhead. For shorter sequences (e.g., standard sentences), the hashing process might actually make LSH slower than standard attention. Additionally, implementing causal masking (preventing the model from "looking into the future") is more complex in the LSH framework than in the standard triangular-mask approach.
Ultimately, the Reformer proves that memory and compute trade-offs—like recalculating values in reversible layers or chunking feed-forward networks—can bypass hardware limitations. This opens the door for applying Transformers to even more demanding modalities, such as video processing or long-form music generation, where sequence lengths far exceed traditional limits.
Summary updated