TL;DR
This paper introduces MemoryFormer, a novel transformer architecture that drastically reduces computational complexity by replacing computationally expensive fully-connected (FC) layers with a new "Memory Layer." This layer uses locality-sensitive hashing to retrieve pre-stored vectors, achieving similar functionality to matrix multiplication with significantly fewer operations, while maintaining comparable performance on NLP benchmarks.
What Problem Does This Paper Address?
The paper tackles the escalating computational cost of large language models (LLMs), which are built upon the Transformer architecture. While advancements like linear attention and flash-attention have improved efficiency, the overall model size and computational demands continue to grow rapidly in pursuit of better performance. The authors identify that a significant portion of the computational burden in standard Transformers comes not from the self-attention mechanism, but from the fully-connected (FC) layers within the feed-forward network (FFN) modules. This realization prompts them to seek a more efficient alternative for these FC layers.
Methods
The core innovation is the Memory Layer, which replaces the matrix multiplication operations of FC layers. Instead of performing explicit calculations, the Memory Layer leverages Locality-Sensitive Hashing (LSH).
Here's how it works:
- In-Memory Hash Tables: A set of hash tables are pre-populated with a large number of discrete vectors.
- Hashing Input Embeddings: For an input token embedding, a simplified LSH function is applied. This function binarizes the input vector into a hash code.
- Vector Retrieval: This hash code is used to retrieve a correlated subset of vectors from the pre-stored hash tables.
- Weighted Aggregation: The retrieved vectors are then combined with learned weights to form the output embedding. This process approximates the result of a matrix multiplication.
To manage memory constraints, the input vector is split into multiple chunks, and separate hash tables are used for each chunk. The entire Memory Layer is designed to be trainable end-to-end via backpropagation, with a novel mechanism to handle the non-differentiable nature of the hashing operation by introducing a probability distribution over hash buckets.
Datasets
The paper uses the Pile dataset for training. For evaluation, they employ a suite of six widely-used NLP benchmarks:
- PIQA
- WinoGrande
- WSC
- ARC-E
- ARC-C
- LogiQA
Key Insights and Ideas
- FC Layers are the Bottleneck: The paper convincingly argues that FC layers, not self-attention, are the primary computational bottleneck in standard Transformers for typical sequence lengths. This shifts the focus of efficiency improvements.
- Memory as Computation: The Memory Layer re-frames computation as a retrieval process from memory, rather than explicit arithmetic operations. This is a fundamentally different approach to efficiency.
- LSH for Approximation: Locality-Sensitive Hashing is shown to be an effective tool for approximating complex operations like matrix multiplication, offering a significant computational speedup.
- Hardware-Software Co-design Potential: The proposed method not only offers algorithmic improvements but also provides insights for future hardware design, suggesting benefits from wider bus widths and higher cache hit rates.
Key Results
- Significant FLOPs Reduction: MemoryFormer achieves a substantial reduction in computational complexity. For instance, a MemoryFormer block requires approximately 19% of the FLOPs of a baseline Transformer block for a sequence length of 2048 and hidden size of 2048.
- Comparable Performance: Despite the drastic reduction in computation, MemoryFormer models achieve performance comparable to, and in many cases better than, baseline Transformer models (e.g., Pythia) across various NLP benchmarks.
- Scalability: The efficiency gains are demonstrated across different model sizes (70M, 160M, 410M parameters), suggesting the approach scales well.
- Comparison with Other Efficient Transformers: MemoryFormer outperforms other efficient transformer methods (Linformer, CosFormer, Performer) in terms of both performance and FLOPs reduction, especially when considering the contribution of FC layers.
Limitations and Future Work
- Memory Usage: While computational complexity is reduced, the Memory Layer's storage requirements can grow significantly with the bit-width of the sub-vectors. The paper explores a trade-off between bit-width and memory usage.
- Hyperparameter Tuning: The performance is sensitive to hyperparameters like the temperature parameter
tand the number of hash tablesK. - Future Work: The authors suggest that further exploration of the trade-offs between memory and computation, as well as potential hardware optimizations for LSH-based retrieval, could lead to even greater efficiency gains. They also note the potential for integrating other efficient self-attention techniques.
Summary updated