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

Cottention: 基于余弦注意力的线性变换器

Cottention: Linear Transformers With Cosine Attention

Lyle School of Engineering(莱尔工程学院);Southern Methodist University(南卫理公会大学)

Gabriel Mongaras, Trevor Dohm, Eric C. Larson

AI总结:

Cottention通过引入余弦相似度替代softmax注意力,实现线性内存复杂性,从而更高效地处理长序列。

摘要:

注意力机制,特别是softmax注意力,在基于变换器的模型如GPT的成功中发挥了关键作用。然而,softmax注意力相对于序列长度的二次内存复杂性对处理更长的序列提出了重大挑战。我们引入了Cottention,一种新的注意力机制,用余弦相似度取代softmax操作。通过利用余弦相似度的性质并重新排列注意力方程,Cottention实现了与序列长度成正比的线性内存复杂性,使其本质上比softmax注意力更节省内存。我们证明Cottention可以重新表述为具有有限隐藏状态的循环神经网络(RNN),在推断过程中允许常数内存使用。我们在双向BERT和因果GPT任务上评估了Cottention,证明其性能与softmax注意力相当,同时显著减少了内存需求。为了确保高效计算,我们为Cottention开发了一个定制的CUDA内核。我们的结果表明,Cottention是softmax注意力的一种有前途的替代方案,能够处理更长的序列而不牺牲性能,由于其固有的线性内存复杂性和在推断过程中保持恒定内存足迹的能力。

英文摘要:

Attention mechanisms, particularly softmax attention, have been instrumental in the success of transformer-based models such as GPT. However, the quadratic memory complexity of softmax attention with respect to sequence length poses significant challenges for processing longer sequences. We introduce Cottention, a novel attention mechanism that replaces the softmax operation with cosine similarity. By leveraging the properties of cosine similarity and rearranging the attention equation, Cottention achieves native linear memory complexity with respect to sequence length, making it inherently more memory-efficient than softmax attention. We demonstrate that Cottention can be reformulated as a recurrent neural network (RNN) with a finite hidden state, allowing for constant memory usage during inference. We evaluate Cottention on both the bidirectional BERT and causal GPT tasks, demonstrating comparable performance to softmax attention while significantly reducing memory requirements. To ensure efficient computation, we develop a custom CUDA kernel for Cottention. Our results show that Cottention is a promising alternative to softmax attention, enabling the processing of longer sequences without sacrificing performance, due to its native linear memory complexity and ability to maintain a constant memory footprint during inference.

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

↑