arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2106.06899cs.CLcs.LG
收藏

通过Top- $k$实现内存高效型Transformers注意

Memory-efficient Transformers via Top-$k$ Attention

IBM Research(IBM研究院);Tel Aviv University(特拉维夫大学);Allen Institute for AI(艾伦人工智能研究所)

Ankit Gupta, Guy Dar, Shaya Goodman, David Ciprut, Jonathan Berant

摘要:

随着点积注意力在Transformers中的成功,最近提出了许多近似来解决其关于输入长度的二次复杂性。虽然这些变体是存储器和计算高效的,但是不可能在没有昂贵的校正预训练阶段的情况下将它们直接与使用普通注意力训练的流行的预训练语言模型一起使用。在这项工作中,我们提出了一个简单而高度准确的近似香草注意。我们以块的形式处理查询,并且对于每个查询,计算关于键的前$k$分数。我们的方法提供了几个优点:(a)它的内存使用在输入大小上是线性的,类似于线性注意力变体,例如Performer和RFA;(b)它是香草注意力的直接替代品,不需要任何纠正性的预训练;(c)在将前馈层转换为熟悉的查询-键值框架后,它还可以在前馈层中节省大量内存。我们评估了长距离竞技场基准上的多头注意力层以及多个QA数据集上的T5和UnifiedQA的前馈层的顶级$k$近似的质量。我们表明,我们的方法在多个设置中的准确性与香草注意力几乎相同,包括从头开始训练,微调和zero-shot推理。

英文摘要:

Following the success of dot-product attention in Transformers, numerous approximations have been recently proposed to address its quadratic complexity with respect to the input length. While these variants are memory and compute efficient, it is not possible to directly use them with popular pre-trained language models trained using vanilla attention, without an expensive corrective pre-training stage. In this work, we propose a simple yet highly accurate approximation for vanilla attention. We process the queries in chunks, and for each query, compute the top-$k$ scores with respect to the keys. Our approach offers several advantages: (a) its memory usage is linear in the input size, similar to linear attention variants, such as Performer and RFA (b) it is a drop-in replacement for vanilla attention that does not require any corrective pre-training, and (c) it can also lead to significant memory savings in the feed-forward layers after casting them into the familiar query-key-value framework. We evaluate the quality of top-$k$ approximation for multi-head attention layers on the Long Range Arena Benchmark, and for feed-forward layers of T5 and UnifiedQA on multiple QA datasets. We show our approach leads to accuracy that is nearly-identical to vanilla attention in multiple setups including training from scratch, fine-tuning, and zero-shot inference.

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

↑