Home Knowledge Base Reformer

Reformer is a memory-efficient transformer that introduces two key innovations: Locality-Sensitive Hashing (LSH) attention (reducing complexity from O(n²) to O(n log n)) and reversible residual layers (reducing memory from O(n_layers × n) to O(n)) — targeting extremely long sequences (64K+ tokens) where both compute and memory are prohibitive, by replacing exact full attention with an efficient approximation that attends only to similar tokens.

What Is Reformer?

Innovation 1: LSH Attention

ConceptDescription
Core IdeaTokens with similar Q/K vectors will have high attention weights. Hash Q and K into buckets; only attend within same bucket.
LSH HashRandom projection-based hash function that maps similar vectors to the same bucket with high probability
Bucket SizeSequence divided into ~n/bucket_size buckets; attention computed within each bucket
Multi-RoundMultiple hash rounds (typically 4-8) for coverage — reduces chance of missing important attention pairs
ComplexityO(n log n) vs O(n²) for full attention

How LSH Attention Works

StepActionComplexity
1. HashApply LSH to Q and K vectors → bucket assignmentsO(n × rounds)
2. SortSort tokens by bucket assignmentO(n log n)
3. ChunkDivide sorted sequence into chunksO(n)
4. Attend within chunksFull attention within each chunk (small, ~128-256 tokens)O(n × chunk_size)
5. Multi-roundRepeat with different hash functions, average resultsO(n × rounds × chunk_size)

Innovation 2: Reversible Residual Layers

Standard TransformerReformer (Reversible)
Store activations at every layer for backpropagationOnly store final layer activations
Memory: O(L × n × d) where L = layersMemory: O(n × d) regardless of depth
Forward: y = x + F(x)Forward: y₁ = x₁ + F(x₂), y₂ = x₂ + G(y₁)
Backward: need stored activationsBackward: recompute x₂ = y₂ - G(y₁), x₁ = y₁ - F(x₂)

Reformer vs Other Efficient Attention

MethodComplexityExact?MemoryBest For
Full AttentionO(n²)YesO(n²)Short sequences (<2K)
FlashAttentionO(n²) FLOPs, O(n) memoryYesO(n)Standard training (exact, fast)
Reformer (LSH)O(n log n)No (approximate)O(n)Very long sequences (64K+)
LongformerO(n × w)Exact (sparse)O(n × w)Long documents (4K-16K)
PerformerO(n)No (approximate)O(n)When linear complexity critical

Reformer is the pioneering memory-efficient transformer for very long sequences — combining LSH attention (O(n log n) approximate attention that groups similar tokens via hashing) with reversible residual layers (O(n) activation memory regardless of depth), demonstrating that both the compute and memory barriers of standard transformers can be dramatically reduced for processing sequences of 64K+ tokens, trading exact attention for efficient approximation.

reformerfoundation model

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.