arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2210.10340cs.CLcs.LG
收藏

线性Transformer中的魔鬼

The Devil in Linear Transformer

SenseTime Research(商汤科技研究院);Australian National University(澳大利亚国立大学);OPPO Research Institute(OPPO研究院);Shanghai AI Laboratory(上海人工智能实验室);The University of Hong Kong(香港大学)

Zhen Qin, XiaoDong Han, Weixuan Sun, Dongxu Li, Lingpeng Kong, Nick Barnes, Yiran Zhong

摘要:

线性Transformers的目标是降低vanilla Transformers的二次空间-时间复杂度。然而,他们通常遭受各种任务和语料的性能下降。在本文中,我们研究了现有的基于内核的线性Transformers,并确定了两个关键问题,导致这种性能差距:1)在注意力计算的无界梯度的线性Transformer模型的收敛性产生不利影响; 2)注意力稀释,平凡地分布在长序列的注意力得分,而忽略了相邻的结构。为了解决这些问题,我们首先确定注意力矩阵的缩放是无界梯度中的魔鬼,这在线性注意力中是不必要的,因为我们从理论和经验上证明了这一点。为此,我们提出了一个新的线性注意力,取代了缩放操作的归一化,以稳定梯度。对于注意力稀释的问题,我们利用对角注意力将注意力限制在早期层中的相邻标记上。受益于稳定的梯度和改进的注意力,我们的新线性Transformer模型transNormer在文本分类和语言建模任务以及具有挑战性的Long-Range Arena基准测试中表现出卓越的性能,明显超过了vanilla Transformer和现有的线性变体,同时具有更高的时空效率。该代码可在https://github.com/OpenNLPLab/Transnormer上获得。

英文摘要:

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. 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 .

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑