Reformer: The Efficient Transformer

TL;DR

Reformer combines reversible residual layers and locality-sensitive hashing (LSH) attention, reducing complexity from O(L^2) to O(L log L) for long sequences.

cs.LG 🔴 Advanced 2020-01-14 51 views
Nikita Kitaev Łukasz Kaiser Anselm Levskaya
deep learning Transformer efficiency long sequences hash attention

Key Findings

Methodology

The Reformer model introduces reversible residual layers (Gomez et al., 2017) to eliminate the need to store activations for each layer, significantly reducing memory. It employs Chunking to split feed-forward layers into manageable parts, and uses locality-sensitive hashing (LSH) to approximate attention, limiting the scope to local neighborhoods. The LSH attention employs random rotations to hash queries and keys into buckets, enabling approximate nearest neighbor search with complexity O(L log L). Multi-round hashing further improves accuracy. The architecture maintains performance comparable to standard Transformers while drastically improving memory efficiency and speed, especially for sequences of length 64K or more.

Key Results

  • On the enwik8 dataset with 64K tokens, Reformer achieves near-identical perplexity to full attention models but with over 10x memory savings and 50% faster training. In image generation tasks on ImageNet-64, it matches baseline performance while using significantly less memory. Ablation studies confirm that shared QK spaces and reversible layers do not impair accuracy. Multi-round hashing (nrounds=8) nearly matches full attention, validating the approximation's effectiveness.
  • Synthetic duplication tasks demonstrate that multi-hash configurations (nrounds=8) can reach 100% accuracy, confirming the method's robustness. Experiments show that the model scales well with sequence length, maintaining performance while reducing computational costs.
  • The results highlight that the combination of reversible layers and LSH attention allows training larger models on longer sequences with limited hardware, opening new avenues for NLP, vision, and multimodal applications.

Significance

This work addresses the critical bottleneck of quadratic complexity in Transformer attention, enabling efficient training and inference on sequences of unprecedented length. It paves the way for deploying large-scale models in resource-constrained environments, democratizing access to powerful deep learning architectures. The integration of hashing-based approximate attention and reversible networks offers a scalable solution that balances accuracy, speed, and memory footprint, impacting both academia and industry in NLP, computer vision, and beyond.

Technical Contribution

The key innovations include: • Introducing locality-sensitive hashing (LSH) into attention to approximate nearest neighbors efficiently; • Employing reversible residual layers to eliminate the need for storing activations, drastically reducing memory; • Combining Chunking with multi-round hashing to handle feed-forward and attention layers at scale; • Demonstrating that approximate attention can match full attention performance with minimal accuracy loss, validated across multiple tasks. These contributions enable scalable, memory-efficient Transformer architectures.

Novelty

This is the first comprehensive integration of LSH-based approximate attention within Transformer models, combined with reversible residual networks, to handle ultra-long sequences efficiently. Unlike prior sparse or external memory methods, Reformer achieves near-identical performance with significantly reduced resource requirements, representing a major step forward in scalable deep learning architectures.

Limitations

  • LSH attention may lose some information in extremely noisy or highly irregular data, potentially impacting accuracy in certain scenarios.
  • Multi-round hashing introduces additional computation, requiring careful tuning to balance speed and precision.
  • Reversible layers, while memory-efficient, can sometimes cause training instability if not properly regularized or initialized.
  • Further research is needed to adapt these techniques to diverse modalities and tasks with different data distributions.

Future Work

Future directions include developing adaptive hashing schemes that dynamically balance accuracy and efficiency, integrating sparse attention with external memory for even larger models, and extending these techniques to multimodal and reinforcement learning tasks. Additionally, exploring hybrid models combining reversible and traditional layers could further optimize performance and stability.

AI Executive Summary

Transformers have revolutionized natural language processing and multimodal tasks, yet their quadratic attention complexity limits scalability, especially for long sequences. As models grow larger, the computational and memory demands become prohibitive, restricting their deployment to resource-rich environments. To address this, the Reformer introduces a suite of innovations that fundamentally change how long sequences are processed.

At the core of Reformer is the use of reversible residual layers, inspired by Gomez et al. (2017), which allow the model to reconstruct activations during backpropagation without storing them explicitly. This innovation alone reduces memory consumption by a factor of the number of layers, enabling deeper and larger models. Complementing this, Chunking techniques split large feed-forward layers into smaller chunks, further reducing intermediate memory requirements.

The most significant breakthrough is the integration of locality-sensitive hashing (LSH) into the attention mechanism. Instead of computing full dot-product attention with quadratic complexity, LSH hashes queries and keys into buckets based on their angular proximity, limiting attention computations to local neighborhoods. This approximation reduces complexity from O(L^2) to O(L log L), making it feasible to process sequences of 64K tokens or more efficiently.

Experimental results demonstrate that Reformer matches the performance of standard Transformers on tasks like enwik8 and ImageNet-64, while using an order of magnitude less memory and training faster. Synthetic duplication tasks confirm the effectiveness of multi-round hashing in preserving attention accuracy. These advances open new possibilities for deploying large models in constrained environments, broadening the scope of long-sequence applications.

While promising, the approach has limitations, such as potential information loss in noisy data and the need for careful hyperparameter tuning. Future work will focus on adaptive hashing, hybrid architectures, and extending these techniques across modalities. Overall, Reformer represents a significant step toward scalable, efficient deep learning models capable of handling the demands of real-world long-sequence data.

Deep Dive

Abstract

Large Transformer models routinely achieve state-of-the-art results on a number of tasks but training these models can be prohibitively costly, especially on long sequences. We introduce two techniques to improve the efficiency of Transformers. For one, we replace dot-product attention by one that uses locality-sensitive hashing, changing its complexity from O($L^2$) to O($L\log L$), where $L$ is the length of the sequence. Furthermore, we use reversible residual layers instead of the standard residuals, which allows storing activations only once in the training process instead of $N$ times, where $N$ is the number of layers. The resulting model, the Reformer, performs on par with Transformer models while being much more memory-efficient and much faster on long sequences.

cs.LG cs.CL stat.ML