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
| Field | Value |
|---|---|
| Paper | Linformer: Self-Attention with Linear Complexity |
| Authors | Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, Hao Ma |
| Year | 2020 |
| Venue | arXiv preprint |
| arXiv | 2006.04768 |
| Status | seed 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
| Item | Contract |
|---|---|
| Input | sequence representations |
| Baseline block | Transformer self-attention |
| Changed part | key/value sequence dimension is compressed before attention |
| Main assumption | attention matrix is effectively low-rank |
| Projection size | , with |
| Cost target | instead of attention cost |
| Main risk | useful 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:
| Attention | Score Shape | Sequence 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
| Paper | Route | What Changes |
|---|---|---|
| Longformer | sparse local/global attention | attention graph is hand-designed |
| BigBird | local/global/random sparse attention | sparse graph adds random and global connectivity |
| Reformer | LSH attention | candidate keys are selected by approximate similarity buckets |
| Linformer | low-rank projection | keys and values are compressed along sequence length |
| Performer | random-feature kernel attention | softmax attention is approximated algebraically |
| FlashAttention | IO-aware exact attention | dense 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
| Claim | Evidence Type | What It Supports | Caveat |
|---|---|---|---|
| attention maps can be low-rank | empirical spectrum analysis | motivates sequence-length projection | rank can depend on layer, task, model, and input distribution |
| linear attention reduces memory/time | complexity analysis and runtime experiments | long inputs can become cheaper | projection overhead and implementation constants matter |
| performance stays close to Transformer | benchmark comparisons | compression can preserve useful behavior | the best is a hyperparameter and may not transfer |
| sharing projection matrices is possible | ablation/config variants | memory can be reduced further | sharing 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
| Misreading | Correction |
|---|---|
| ”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.