Hugging FacePatrick von PlatenExplainer
The Reformer - Pushing the limits of language modeling
Summary
Standard transformer models hit memory bottlenecks on long sequence modeling tasks due to the quadratic asymptotic memory complexity of global self-attention and oversized positional embedding matrices. The Reformer architecture overcomes these constraints to train sequences of up to half a million tokens using under 8GB of RAM. It re-engineers transformer operations using local and Locality Sensitive Hashing self-attention, chunked feed forward layers, reversible residual layers, and axial positional encodings. In empirical benchmarks using google/reformer-crime-and-punishment, axial positional encodings reduce the model parameter count from over 136 million to approximately 2.58 million by factorizing the positional dimensions. This architectural change cuts inference memory consumption from 959 MB down to 447 MB for evaluated benchmark workloads.
Context
Standard transformer models face a memory bottleneck in global self-attention, where the inner dot-product tensor exhibits quadratic memory complexity. This constraint restricts models like BERT to short sequences of 512 tokens or forces sequence truncation on NLP tasks that require long contexts, such as summarization and question answering.
Approach / What changed
The Reformer re-engineers standard transformer layers to optimize memory efficiency via four components: local and Locality Sensitive Hashing self-attention, chunked feed-forward layers, reversible residual layers, and axial positional encodings. Local self-attention segments input sequences into chunks with configurable preceding and following overlap, while axial positional encodings factorize high-dimensional position matrices into smaller tensor parameter lists.
Takeaways
Global self-attention generates an O(n^2) memory bottleneck in the inner dot-product tensor, restricting models like bert-base-uncased to a maximum position embedding size of 512 tokens.
Local self-attention partitions inputs into chunks of length l_c and adds overlap from preceding and following chunks to maintain access to immediate neighboring token context.
In benchmarks on half-million token sequences, axial positional encodings cut total model parameters from 136,572,416 to 2,584,064 and reduce inference memory from 959 MB to 447 MB at batch size 8.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.