Linformer

Linformer makes self-attention linear in sequence length by projecting keys and values along the sequence dimension, based on the claim that the attention matrix can be approximated as low-rank.

Metadata

FieldValue
PaperLinformer: Self-Attention with Linear Complexity
AuthorsSinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, Hao Ma
Year2020
VenuearXiv preprint
arXiv2006.04768
Statusseed note

One-Line Takeaway

Linformer is the canonical low-rank attention paper in this wiki:

Keep it separate from sparse attention, LSH attention, random-feature attention, and exact attention kernels.

Question

Standard self-attention computes:

For a sequence length :

The quadratic object is the attention score or attention probability matrix:

The paper asks:

If yes, full attention does not need every token to keep an independent key/value slot.

Main Claim

Linformer claims that self-attention can often be approximated by a low-rank matrix. The architecture then reduces sequence length inside attention by learned projection matrices.

Let:

Instead of attending to all key and value positions, Linformer computes:

where:

Attention becomes:

The score matrix shape changes from:

If is fixed or grows slowly compared with , the attention cost is linear in .

Architecture Contract

ItemContract
Inputsequence representations
Baseline blockTransformer self-attention
Changed partkey/value sequence dimension is compressed before attention
Main assumptionattention matrix is effectively low-rank
Projection size, with
Cost target instead of attention cost
Main riskuseful information can be lost if is too small or the low-rank assumption fails

Linformer is an attention replacement. It is not a new tokenizer, language-model objective, or pretraining recipe.

Shape Walkthrough

Start with hidden states:

Linear projections produce:

with:

Dense attention builds:

Linformer first compresses the token axis:

with:

The attention score becomes:

Then:

The output still has one vector per input token. Only the key/value memory being attended over is compressed.

Complexity

Dense self-attention:

for score computation, plus:

for the attention matrix.

Linformer attention:

after projecting keys and values to length .

The projection itself costs:

if implemented as a dense sequence projection. The intended regime is:

So the useful comparison is:

AttentionScore ShapeSequence Cost
dense attention
Linformer

Calling this “linear” assumes is treated as a chosen projection dimension rather than another value that scales like .

Low-Rank View

The attention probability matrix is:

A low-rank approximation would mean:

Linformer does not explicitly compute an SVD of . Instead, it learns projections that reduce the key/value sequence axis before the attention matrix is formed.

The architecture bet is:

If that bet is true, a compressed key/value memory can preserve enough behavior.

Relation to Other Efficient Attention Papers

PaperRouteWhat Changes
Longformersparse local/global attentionattention graph is hand-designed
BigBirdlocal/global/random sparse attentionsparse graph adds random and global connectivity
ReformerLSH attentioncandidate keys are selected by approximate similarity buckets
Linformerlow-rank projectionkeys and values are compressed along sequence length
Performerrandom-feature kernel attentionsoftmax attention is approximated algebraically
FlashAttentionIO-aware exact attentiondense attention remains exact but is tiled efficiently

The important distinction:

Sparse attention changes connectivity. Linformer changes rank. Performer changes kernel approximation. FlashAttention changes the implementation schedule for exact dense attention.

Evidence to Read

ClaimEvidence TypeWhat It SupportsCaveat
attention maps can be low-rankempirical spectrum analysismotivates sequence-length projectionrank can depend on layer, task, model, and input distribution
linear attention reduces memory/timecomplexity analysis and runtime experimentslong inputs can become cheaperprojection overhead and implementation constants matter
performance stays close to Transformerbenchmark comparisonscompression can preserve useful behaviorthe best is a hyperparameter and may not transfer
sharing projection matrices is possibleablation/config variantsmemory can be reduced furthersharing may reduce flexibility

Read the paper as a claim about the structure of attention matrices, not as a universal replacement for full attention.

Implementation Reading

Check:

  • the chosen projection dimension ;
  • whether and are shared across heads, layers, or key/value paths;
  • whether projections are learned, fixed, convolutional, or otherwise constrained;
  • whether causal masking is needed and how it interacts with sequence projection;
  • maximum training length and test length;
  • whether speedups include projection overhead;
  • whether memory measurement includes activations, attention matrices, and optimizer state;
  • whether comparisons use the same depth, width, objective, and token budget.

Common Misreadings

MisreadingCorrection
”Linformer proves all attention is low-rank.”It argues and tests a useful low-rank approximation regime; the assumption can fail.
”Linformer is the same as Performer.”Performer uses kernel random features; Linformer compresses key/value sequence length.
”Linear complexity means free long context.”, projection overhead, kernels, and quality tradeoffs still matter.
”The output sequence is shortened.”The output remains length ; only the attended key/value memory is compressed.
”Low-rank attention is just LoRA.”Linformer compresses attention over sequence positions; LoRA adapts weight matrices with low-rank updates.

What to Remember

Linformer should be remembered as:

It is useful because it gives an architecture-level way to ask:

That question remains relevant even when modern systems choose sparse attention, FlashAttention, recurrent memory, or state-space models instead.