The Devil in Linear Transformer

Zhen Qin, XiaoDong Han, Weixuan Sun, Dongxu Li, Lingpeng Kong +2 more
10/19/2022
cs.CLcs.LG
transformer-attention

Official code: OpenNLPLab/Transnormer (64 stars, Python, last commit 2023-07-30).

Abstract

Linear transformers aim to reduce the quadratic space-time complexity of vanilla transformers. However, they usually suffer from degraded performances on various tasks and corpus.

Show full abstract

In this paper, we examine existing kernel-based linear transformers and identify two key issues that lead to such performance gaps: 1) unbounded gradients in the attention computation adversely impact the convergence of linear transformer models; 2) attention dilution which trivially distributes attention scores over long sequences while neglecting neighbouring structures. To address these issues, we first identify that the scaling of attention matrices is the devil in unbounded gradients, which turns out unnecessary in linear attention as we show theoretically and empirically. To this end, we propose a new linear attention that replaces the scaling operation with a normalization to stabilize gradients. For the issue of attention dilution, we leverage a diagonal attention to confine attention to only neighbouring tokens in early layers. Benefiting from the stable gradients and improved attention, our new linear transformer model, transNormer, demonstrates superior performance on text classification and language modeling tasks, as well as on the challenging Long-Range Arena benchmark, surpassing vanilla transformer and existing linear variants by a clear margin while being significantly more space-time efficient. The code is available at https://github.com/OpenNLPLab/Transnormer .

View on arXivView PDF

Code Implementations(1)

[EMNLP 2022] Official implementation of Transnormer in our EMNLP 2022 paper - The Devil in Linear Transformer

645Python, ShellOct 19, 20223 years ago

Similar Papers

Cite this paper

@article{qin2022devil,
  title  = {The Devil in Linear Transformer},
  author = {Zhen Qin and XiaoDong Han and Weixuan Sun and Dongxu Li and Lingpeng Kong and Nick Barnes and Yiran Zhong},
  year   = {2022},
  eprint = {2210.10340},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2210.10340}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2210.10340.svg)](https://codeofpaper.com/paper/2210.10340)

Discussion