Reformer

Reformer makes Transformers practical on long sequences by combining locality-sensitive hashing attention with reversible residual layers.

Metadata

FieldValue
PaperReformer: The Efficient Transformer
AuthorsNikita Kitaev, Lukasz Kaiser, Anselm Levskaya
Year2020
VenueICLR 2020
arXiv2001.04451
OpenReviewrkgNKkHtvB
Statusfull note started

One-Line Takeaway

Reformer attacks two different Transformer bottlenecks:

through locality-sensitive hashing attention, and:

through reversible residual layers.

Question

Standard Transformer self-attention forms:

This gives:

Training also stores intermediate activations for backpropagation:

where is the number of layers. Reformer asks whether a Transformer can keep similar modeling behavior while reducing both long-sequence attention cost and depth-related activation memory.

Architecture Contract

ItemContract
Inputlong token sequence
Main attention operatorLSH attention
Key memory operatorreversible residual layer
Additional memory trickchunked feed-forward computation
Main efficiency targetlower attention cost and lower activation storage
Main use caselong sequence modeling where dense attention and deep activation storage are limiting
Main riskapproximate hashing changes the attention neighborhood and can affect training dynamics

Reformer is not only an attention paper. It is an efficient Transformer architecture package:

LSH Attention

Dense attention compares every query to every key. Reformer instead tries to compare each query mostly to keys likely to be similar.

Let a hash function map vectors to buckets:

The intended property is:

Then each query attends within a smaller candidate set:

The attention output becomes:

This is approximate attention. It does not compute all pairwise scores.

Shared Query-Key Space

Reformer uses the same vector as query and key for LSH attention:

This matters because hashing should group vectors that are similar under the same comparison space. If queries and keys came from unrelated projections, hash buckets would be harder to interpret as approximate nearest-neighbor groups.

The basic intuition is:

Sorting and Chunking

After hashing, tokens are sorted by hash bucket. Attention is then computed in chunks containing nearby sorted positions.

At a high level:

This makes the computation more structured than arbitrary sparse attention. The model avoids computing a full attention matrix, but it still uses dot-product attention inside each selected bucket or chunk.

Multiple Hash Rounds

One hash round can miss useful neighbors. Reformer therefore can use multiple hash rounds:

More rounds increase the chance that similar tokens share a bucket:

This is the central quality-efficiency trade-off in LSH attention.

Reversible Residual Layers

Standard residual blocks store activations:

Backpropagation usually needs saved intermediate activations for every layer. Reversible layers split the hidden state:

A reversible block computes:

The input can be reconstructed from the output:

This means training can recompute activations during backward pass instead of storing every layer’s activations:

The trade-off is extra recomputation.

Chunked Feed-Forward Computation

Transformer feed-forward layers often expand dimension:

The FFN is token-wise:

Because tokens can be processed independently in the FFN, Reformer can chunk this computation:

and evaluate:

This is an implementation-level memory saving. It should not change the numerical function if done exactly.

Relation to Other Efficient Attention Notes

PaperRouteWhat Changes
Longformersparse local/global attentionhand-designed local and task-global pattern
BigBirdsparse local/global/random attentiongraph connectivity through random sparse links
ReformerLSH attention plus reversibilityapproximate nearest-neighbor attention and activation reconstruction
Linformerlow-rank sequence projectioncompresses keys and values before attention
Performerkernel feature approximationapproximates softmax attention algebraically
FlashAttentionIO-aware exact attentionkeeps dense attention exact but avoids materializing full matrix in HBM

Reformer is closest to approximate nearest-neighbor attention. It is not simply a sparse mask, and it is not an exact dense attention kernel.

Evidence to Read

ClaimEvidence TypeWhat It SupportsCaveat
LSH attention reduces attention complexitycomplexity analysis and runtime experimentslong sequences become more practical than dense attentionhash quality and implementation details matter
reversible layers reduce activation memoryarchitecture constructiondepth-related activation storage can be reducedrecomputation cost is paid during backward pass
chunked FFN reduces memoryimplementation equivalenceFFN intermediate memory can be controlledmostly a memory engineering trick, not a new model function
performance stays close to Transformerempirical tasks and ablationsefficiency changes can preserve useful modeling behaviortask coverage is narrower than modern LLM practice

Implementation Reading

Check:

  • number of hash rounds ;
  • bucket size and chunk size;
  • whether causal masking is preserved after sorting;
  • whether queries and keys are shared;
  • whether attention is allowed to attend to duplicate or same-token positions;
  • memory saved by reversibility versus extra recomputation time;
  • whether benchmark gains come from longer sequence length rather than a better inductive bias.

The most important implementation detail is that sorting/hash bucketing must not break the task mask. Approximate neighbor selection is useful only if the resulting information flow still matches the problem.

Limitations

  • LSH attention is approximate; important token pairs may be missed.
  • Hashing and sorting add implementation complexity.
  • Reversible layers trade memory for recomputation.
  • The architecture was influential, but many later long-context systems prefer sparse patterns, kernel tricks, FlashAttention-style exact kernels, or state-space models.
  • Efficiency claims depend heavily on sequence length, hardware, batching, and implementation quality.

Common Misreadings

MisreadingCorrection
”Reformer is just another sparse attention mask.”LSH attention selects candidates by hash buckets, not only by a fixed position pattern.
”Reversible layers make the model free to train.”They reduce activation storage but require recomputation.
”LSH attention is exact attention.”It approximates the relevant attention neighborhood.
”All efficient Transformers solve the same problem.”Reformer targets approximate attention and activation memory; FlashAttention targets IO for exact dense attention.

What to Remember

Reformer is the canonical efficient Transformer paper for:

Keep it as a distinct route from Longformer, BigBird, Performer, FlashAttention, and S4.