Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Linformer: Self-Attention with Linear Complexity

  • Problem Self-attention costs \(O(n^2)\) in time and space with sequence length, which makes Transformers slow to train and serve on long inputs.
  • Method Projects keys and values from length n to a smaller length k with learned n-by-k matrices, so the context mapping costs \(O(nk)\) instead of \(O(n^2)\).
  • Results The n = 512, k = 256 model with shared key-value and layerwise sharing averages 92.30 on four dev tasks, against 92.25 for RoBERTa-base; at n = 512, k = 128, inference is 1.5x faster than the Transformer.

Why self-attention is the bottleneck

Self-attention lets every token draw on every other token in the sequence, which is how long-range information stays available to a Transformer. The context mapping matrix is n by n, so computing it takes \(O(n^2)\) time and space as the sequence grows. The open question is whether attention can avoid this quadratic step without losing accuracy.

Sparse attention lowers the cost to about \(O(n\sqrt{n})\) by letting each token attend to only part of the sequence. The authors report that such methods lose accuracy quickly for little speed: a 2% drop for a 20% speed-up. The Reformer's LSH attention has a theoretical cost of \(O(n\log(n))\), but the efficiency gains it reports only appear for sequences longer than 2048, and its multi-round hashing adds sequential steps.

Table 1 places these architectures side by side on per-layer time complexity and on the minimum number of sequential operations. Linformer is listed there with \(O(n)\) complexity per layer and \(O(1)\) sequential operations.

Evidence that attention is low rank

The spectrum check uses pretrained RoBERTa-base and RoBERTa-large models, with masked language modeling on Wiki103 and classification on IMDB. For each layer and head, the singular values of the context mapping matrix are computed and the normalized cumulative sum is averaged over 10k sentences. The curves have a long tail, so a few leading singular values carry most of the information, and higher layers are more skewed than lower ones.

At the 128th of 512 singular values, higher layers have concentrated more of the mass, which means their rank is lower.

Theorem 1 says that for a column vector of the value projection, a matrix \(\tilde P\) of rank \(\Theta(\log(n))\) exists whose product with that vector is within relative error \(\epsilon\) of \(P w^T\), with probability greater than \(1-o(1)\). The proof draws R as a k-by-n matrix with i.i.d. N(0, 1/k) entries and applies the distributional Johnson–Lindenstrauss lemma, which gives \(k = 5\log(n)/(\epsilon^2-\epsilon^3)\).

A truncated singular value decomposition of P gives a low-rank approximation, and the paper ties its accuracy to the Eckart–Young–Mirsky Theorem. That route needs an SVD for every self-attention matrix, which adds cost of its own, so the authors look for a construction that avoids it.

Projecting keys and values to length k

Each head keeps the usual query, key and value projections and adds two learned matrices, \(E_i\) and \(F_i\), each of size n by k. Keys and values are multiplied by these matrices before attention, so each head's projected key and value are k by d rather than n by d.

Each head is computed as a softmax over \(QW^Q_i(E_iKW^K_i)^T/\sqrt{d_k}\), which gives an n-by-k matrix \(\bar P\), and this matrix multiplies \(F_iVW^V_i\), a k-by-d matrix. Because \(\bar P\) has only k columns, this step costs \(O(nk)\) in time and space, so a small projected dimension k is what keeps the cost low.

Theorem 2 sets the required k as \(k = \min\{\Theta(9d\log(d)/\epsilon^2), 5\Theta(\log(n)/\epsilon^2)\}\). Under that choice, there exist \(E_i\) and \(F_i\) such that for a row vector w of \(QW^Q_i(KW^K_i)^T/\sqrt{d}\), the projected softmax output is within relative error \(\epsilon\) of the exact one, with probability greater than \(1-o(1)\).

The first term does not depend on n, which is why the authors describe the choice of k as independent of sequence length, while the second term still depends on log(n).

The proof sets \(E_i = \delta R\) and \(F_i = e^{-\delta R}\), where R is a k-by-n Gaussian matrix and \(\delta\) is a small constant. Applying the single-row result to every row of A gives a bound with \(k = 5\log(nd)/(\epsilon^2-\epsilon^3)\), and the authors then use the rank of A being d, on a submatrix of 2d rows, to replace the dependence on n with one on log(d).

Sharing and sizing the projections

The projections can be shared in three ways: headwise sharing uses one E and one F per layer, key-value sharing uses one E per layer for keys and values, and layerwise sharing uses one E across all layers. In a 12-layer, 12-head model these choices leave 24, 12 and 1 distinct projection matrices.

The projected dimension can differ across heads and layers. Because higher layers show more skewed spectra, the authors suggest a smaller k for them.

The projection need not be linear: mean or max pooling, or a convolution with kernel and stride set to n/k, are alternatives, and a convolution has trainable parameters.

Pretraining perplexity across k, sharing and n

Pretraining uses masked language modeling on BookCorpus and English Wikipedia, about 3300M words in total, and Linformer is compared with a RoBERTa baseline that is based on the Transformer. The runs were parallelized across 64 Tesla V100 GPUs for 250k updates.

The authors vary the projected dimension k, using the same k in every layer and head, and plot validation perplexity against updates for maximum sequence lengths of 512 and 1024. Linformer improves as k grows, and at k = 128 with n = 512 or k = 256 with n = 1024 its perplexity is already nearly on par with the Transformer.

With n = 512, using a single projection matrix for all layers gives validation perplexity almost matching the non-shared model. The authors read this as a way to cut extra parameters, and with them memory use, with little cost in quality.

With k fixed at 256, the authors pretrain for n in 512, 1024, 2048 and 4096. After convergence the final perplexities stay about the same as n grows, which the authors take as support for linear-time behavior.

Fine-tuning accuracy on four tasks

The pretrained models are fine-tuned on SST-2, IMDB, QNLI and QQP and compared with RoBERTa, 12-layer BERT-base and 6-layer Distilled BERT. Accuracy is the dev-set score, averaged over the four tasks.

Linformer with n = 512 and k = 128 averages 91.75, against 92.25 for RoBERTa-base. At k = 256, the Linformer with shared key-value and layerwise sharing averages 92.30. BERT-base averages 91.90 and Distilled BERT averages 90.45.

The n = 1024, k = 256 layerwise model averages 92.18, close to the 92.30 of the n = 512, k = 256 counterpart with the same sharing. The authors take this to mean that accuracy depends mainly on k rather than on the ratio of n to k.

All models, including the Transformer baselines, shared the objective, the corpus and up to 250k updates, but Linformer reached those updates in much less wall-clock time and so trained for less time.

Inference speed and memory against the Transformer

Inference speed and memory were measured for Linformer with layerwise sharing against a standard Transformer. Random data up to a chosen sequence length went through full forward passes on a 16GB Tesla V100 GPU, with batch size set to the largest batch that fits in memory.

Holding the total number of tokens fixed, the Transformer slows at longer sequence lengths while the Linformer time stays comparatively flat.

At n = 512 and k = 128, Linformer has 1.5x faster inference and allows a 1.7x larger maximum batch size than the Transformer. At k = 128 the time saved rises to 20x at n = 65536, and the memory saved reaches 60x at the same length and projected dimension. The savings grow with sequence length, so the largest gains appear at the longest sequences tested.

Limits of the measurements and tests

The speed and memory numbers come from random inputs on one 16GB Tesla V100, with batch size set by the largest batch that fits, so they describe this benchmark setting rather than any downstream task. The downstream Linformer models reached 250k updates in much less wall-clock time, so they trained for less time than the baselines.

Pretraining is compared only under masked language modeling on BookCorpus plus English Wikipedia, and downstream accuracy is reported on four tasks. The Reformer comparison rests on efficiency gains reported in prior work, which appear only for sequences longer than 2048.

Theorem 1 is stated for a column vector of the value projection, and Theorem 2 for a row vector of the scaled query-key product, each with probability greater than \(1-o(1)\). The experiments measure perplexity, accuracy and speed or memory, and they do not measure the approximation error of P directly.

Paper info

Authors
Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, Hao Ma
Venue
arXiv · Preprint
First published
2020-6-8
Added
2026-10-20
Updated
2020-6-14
Version
v3
arXiv
2006.04768
Category
cs.LG · stat.ML
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, Hao Ma (2020). Linformer: Self-Attention with Linear Complexity. arXiv:2006.04768v3. https://arxiv.org/abs/2006.04768v3

BibTeX
@misc{wang2020linformer,
  title = {{Linformer: Self-Attention with Linear Complexity}},
  author = {Sinong Wang and Belinda Z. Li and Madian Khabsa and Han Fang and Hao Ma},
  year = {2020},
  eprint = {2006.04768},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2006.04768v3}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up