Executive Summary
MemoryFormer is a novel Transformer architecture that drastically slashes computational costs by replacing power-hungry fully-connected (FC) layers with efficient in-memory lookup tables. By utilizing a "compute-less" hashing algorithm to retrieve pre-stored vectors instead of performing massive matrix multiplications, MemoryFormer reduces FLOPs by up to 80% while maintaining—and often exceeding—the performance of standard models like Pythia.
The Problem: The Hidden Cost of Fully-Connected Layers
While the AI community has been heavily focused on solving the "quadratic bottleneck" of self-attention (using techniques like FlashAttention or linear attention), the authors of MemoryFormer highlight a frequently neglected reality: in most practical scenarios, the vast majority of a Transformer's computation actually occurs in the fully-connected (FC) layers, not the attention mechanism.
For a standard model with a hidden size of 4096, multi-head attention (MHA) only becomes the dominant computational cost when the sequence length exceeds 24,000 tokens. For typical tasks, the linear projections and feed-forward networks (FFN) are the real "FLOPs hogs." Furthermore, modern hardware often has massive amounts of idle RAM and CPU cores during GPU-heavy inference. MemoryFormer aims to bridge this gap by strategically trading memory capacity for computational efficiency.
The MemoryFormer Architecture
The core innovation of this paper is the Memory Layer, which replaces the standard $y = xW$ matrix multiplication found in traditional Transformers.
- Compute-less Hashing: Instead of multiplying an input vector by a dense weight matrix, the model splits the input into $K$ chunks. It then uses a simple Locality-Sensitive Hashing (LSH) algorithm—specifically taking the
signof the input values—to generate an index. This operation requires almost zero floating-point operations (FLOPs). - In-Memory Lookup: This index points to a specific "bucket" in a large, pre-stored lookup table (the "Memory"). Each bucket contains a learnable discrete vector.
- Differentiable Retrieval: To make this system trainable via backpropagation, the authors use a "soft" retrieval method. They calculate a probability for the hash bucket based on scaled cosine similarity, allowing gradients to flow back to both the input and the memory tables.
- Architecture Integration: MemoryFormer replaces nearly every linear layer in the Transformer—including the $Q, K, V$ projections and the two-layer FFN—with these Memory Layers. The only standard FC layer remaining is the final classifier head.
Training and Evaluation
To ensure a fair comparison, the authors trained MemoryFormer from scratch using The Pile, a massive 825 GiB corpus of diverse text data. The model was then evaluated across six widely-used NLP benchmarks: PIQA (physical commonsense), WinoGrande (anaphoric resolution), WSC (reasoning), ARC-Easy/Challenge (science questions), and LogiQA (logical reasoning).
Key Insights
- The Compute-Memory Trade-off: The paper successfully demonstrates that we can "buy" computational efficiency by leveraging more memory. By storing "answers" to common projections in lookup tables, the model skips the heavy math.
- Redundant Non-linearities: In a traditional FFN, activation functions like ReLU or GELU are essential. The authors found that in MemoryFormer, these are redundant because the hashing operation itself is inherently non-linear. Removing them had no negative impact on performance.
- Sparse Updates: Because only a subset of the memory is accessed for any given input, the gradients are sparse. To compensate, using a 3x higher learning rate for the memory tables was essential for convergence.
- Hardware Synergy: The design is a nod to future hardware paradigms. While current GPUs are heavily optimized for dense math, MemoryFormer is perfectly suited for systems with high memory bandwidth and large caches.
Performance and Efficiency Gains
MemoryFormer achieves impressive efficiency gains without the "accuracy tax" usually seen in compressed or efficient models.
- Massive FLOPs Reduction: For a model equivalent to Pythia-410M, MemoryFormer reduced the FLOPs per block from 34.4G to 10.2G (a ~70% reduction). In specific configurations, a single block required only ~19% of the baseline FLOPs.
- Superior Performance: On average across the six benchmarks, "MF-base" (0.458) outperformed the baseline Pythia-410M (0.435).
- Beating Efficient Baselines: MemoryFormer significantly outperformed other "efficient" architectures like Linformer, cosFormer, and Performer in both accuracy and computational efficiency.
Limitations and Future Directions
- Memory Footprint: While FLOPs are exceptionally low, the memory requirement for the lookup tables can be significant. A high-capacity setup might require over 150 MB per layer just for the hash tables.
- Hardware Optimization: The paper notes that while theoretical FLOPs are reduced, actual "wall-clock" speedups depend heavily on memory bus width and cache hit rates. This may require specialized hardware kernels to fully realize on current GPUs.
- Scaling: The current study scales up to 410M parameters. Testing the architecture at the 7B or 70B parameter scale remains a critical task for future research.
- Code Availability: The authors noted that code and data would not be made public at this time, which may temporarily hinder community reproduction and adoption.
Summary updated