arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2411.04013cs.LGcs.DS
收藏

$k$NN 注意力机制解析:可扩展 Transformer 的理论探索

$k$NN Attention Demystified: A Theoretical Exploration for Scalable Transformers

Boston University(波士顿大学)

Themistoklis Haris

AI总结:

本文为 $k$NN 注意力建立理论框架,将其重构为 softmax 期望,并利用惰性 Gumbel 采样和马尔可夫链估计提出次二次算法,实证验证了其在训练和推理中的效率优势。

摘要:

尽管 Transformer 功能强大,但由于自注意力的二次复杂度,其在处理长序列时面临挑战。为解决这一局限,引入了如 $k$ 最近邻($k$NN)注意力等方法 [Roy, Saffar, Vaswani, Grangier, 2021],使每个 token 仅关注其 $k$ 个最近的 token。虽然 $k$NN 注意力在提升 Transformer 效率方面已显示出经验上的成功,但其精确的近似保证尚未得到理论分析。在本工作中,我们为 $k$NN 注意力建立了理论框架,将自注意力重新表述为对 softmax 分布的期望,并利用带 $k$NN 索引的惰性 Gumbel 采样 [Mussmann, Levy, Ermon, 2017] 进行高效近似。基于此框架,我们还提出了新颖的次二次算法,通过利用高效采样技术(如基于马尔可夫链的估计)来近似自注意力梯度。最后,我们通过实证实验展示了这些算法的实际有效性,彰显了其在训练和推理中的优势。

英文摘要:

Despite their power, Transformers face challenges with long sequences due to the quadratic complexity of self-attention. To address this limitation, methods like $k$-Nearest-Neighbor ($k$NN) attention have been introduced [Roy, Saffar, Vaswani, Grangier, 2021] enabling each token to attend to only its $k$ closest tokens. While $k$NN attention has shown empirical success in making Transformers more efficient, its exact approximation guarantees have not been theoretically analyzed. In this work, we establish a theoretical framework for $k$NN attention, reformulating self-attention as expectations over softmax distributions and leveraging lazy Gumbel sampling [Mussmann, Levy, Ermon, 2017] with $k$NN indices for efficient approximation. Building on this framework, we also propose novel sub-quadratic algorithms that approximate self-attention gradients by leveraging efficient sampling techniques, such as Markov Chain-based estimation. Finally, we demonstrate the practical effectiveness of these algorithms through empirical experiments, showcasing their benefits in both training and inference.

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

↑