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

注意力机制作为循环神经网络

Attention as an RNN

Mila(米拉研究所);Borealis AI(博雷亚利斯人工智能公司);Université de Montréal(蒙特利尔大学)

Leo Feng, Frederick Tung, Hossein Hajimirsadeghi, Mohamed Osama Ahmed, Yoshua Bengio, Greg Mori

AI总结:

针对Transformer推理时计算昂贵的问题,本文提出将注意力视为RNN,并引入Aaren模块,可并行训练且高效更新新token,在38个数据集上性能媲美Transformer且更高效。

摘要:

Transformer的出现标志着序列建模领域的重大突破,提供了一种能够利用GPU并行性的高性能架构。然而,Transformer在推理时计算成本高昂,限制了其应用,尤其是在资源受限的环境(如移动和嵌入式设备)中。针对这一问题,我们(1)首先展示了注意力机制可以被视为一种特殊的循环神经网络(RNN),能够高效计算其“多对一”的RNN输出。接着(2)展示了诸如Transformer等流行的基于注意力的模型可以被视为RNN的变体。然而,与传统RNN(如LSTM)不同,这些模型无法高效地使用新token进行更新,而这在序列建模中是一个重要特性。为解决这一问题,我们(3)基于并行前缀扫描算法,引入了一种高效计算注意力“多对多”RNN输出的新方法。基于新的注意力公式,我们(4)引入了Aaren,一种基于注意力的模块,它不仅(i)可以像Transformer一样并行训练,而且(ii)可以高效地使用新token进行更新,推理时仅需常数内存(如传统RNN)。实验上,我们展示了Aaren在涵盖强化学习、事件预测、时间序列分类和时间序列预测这四种流行序列问题设置的38个数据集上,性能与Transformer相当,同时在时间和内存效率上更具优势。

英文摘要:

The advent of Transformers marked a significant breakthrough in sequence modelling, providing a highly performant architecture capable of leveraging GPU parallelism. However, Transformers are computationally expensive at inference time, limiting their applications, particularly in low-resource settings (e.g., mobile and embedded devices). Addressing this, we (1) begin by showing that attention can be viewed as a special Recurrent Neural Network (RNN) with the ability to compute its \textit{many-to-one} RNN output efficiently. We then (2) show that popular attention-based models such as Transformers can be viewed as RNN variants. However, unlike traditional RNNs (e.g., LSTMs), these models cannot be updated efficiently with new tokens, an important property in sequence modelling. Tackling this, we (3) introduce a new efficient method of computing attention's \textit{many-to-many} RNN output based on the parallel prefix scan algorithm. Building on the new attention formulation, we (4) introduce \textbf{Aaren}, an attention-based module that can not only (i) be trained in parallel (like Transformers) but also (ii) be updated efficiently with new tokens, requiring only constant memory for inferences (like traditional RNNs). Empirically, we show Aarens achieve comparable performance to Transformers on $38$ datasets spread across four popular sequential problem settings: reinforcement learning, event forecasting, time series classification, and time series forecasting tasks while being more time and memory-efficient.

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

↑