EasyDeepLearn

How do Performer / Linformer / linear attention reduce O(n2)O(n^{2})?

hard

Answer

  • Performer: replace exp(qk  /  sqrt(d))\operatorname{exp}(q \cdot k\; / \;\mathrm{sqrt}(d)) with a positive-feature kernel φ(q)·φ(k) that lets you re-associate the matmul as (KT  V)(K^{T}\;V)(QT)(Q^{T})O(n    d2)O(n\; \cdot \;d^{2}) instead of O(n2    d)O(n^{2}\; \cdot \;d).
  • Linformer: project the sequence-length dimension of K, V from n to a small constant k → O(n * k * d).
  • Trade-offs: approximation error, sometimes worse quality on long-range benchmarks vs full attention.
Check yourself — multiple choice
  • Same as vanilla attention
  • Kernel approximation (Performer) or low-rank projection (Linformer) → O(nd2)O(n \cdot d^{2}) or O(n·k·d) but with approximation
  • Removes softmax exactly
  • No trade-offs

Performer / Linformer: kernel or low-rank tricks → linear-in-n attention with approx error.

#attention#efficient-attention#transformers

Practise Deep Learning

214 interview questions in this topic.

Related questions