arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2410.10781cs.CLcs.AIcs.LG
收藏

语言模型中注意力汇聚现象何时涌现:一项实证研究

When Attention Sink Emerges in Language Models: An Empirical View

Sea AI Lab(Sea AI实验室);National University of Singapore(新加坡国立大学)

Xiangming Gu, Tianyu Pang, Chao Du, Qian Liu, Fengzhuo Zhang, Cunxiao Du, Ye Wang, Min Lin

AI总结:

本研究实证揭示了语言模型中注意力汇聚现象在预训练中涌现的机制,发现其源于softmax归一化导致的token内在依赖,并证明替换为无归一化的sigmoid attention可消除该现象。

摘要:

语言模型(LMs)会将显著的注意力分配给第一个 token,即使它在语义上并不重要,这被称为注意力汇聚。这一现象已被广泛应用于流式/长上下文生成、KV cache 优化、推理加速、模型量化等诸多应用中。尽管其应用广泛,但对 LM 中注意力汇聚的深入理解仍然缺乏。在本研究中,我们首先证明注意力汇聚在各种输入的 LM 中普遍存在,甚至在小模型中也是如此。此外,观察到注意力汇聚在 LM 预训练期间涌现,这促使我们研究 LM 预训练中的优化、数据分布、损失函数和模型架构如何影响其涌现。我们强调,注意力汇聚是在充足训练数据上进行有效优化后涌现的。汇聚位置与损失函数和数据分布高度相关。最重要的是,我们发现注意力汇聚的作用更像是关键偏置,存储额外的注意力分数,这些分数可能是无信息的,且不参与价值计算。我们还观察到,这种现象(至少部分)源于 token 对注意力分数的内在依赖,这是 softmax 归一化的结果。通过用其他注意力操作(如无归一化的 sigmoid attention)替换 softmax attention 来放松这种依赖后,在参数量高达 1B 的 LM 中不再出现注意力汇聚。代码可在 https://github.com/sail-sg/Attention-Sink 获取。

英文摘要:

Language Models (LMs) assign significant attention to the first token, even if it is not semantically important, which is known as attention sink. This phenomenon has been widely adopted in applications such as streaming/long context generation, KV cache optimization, inference acceleration, model quantization, and others. Despite its widespread use, a deep understanding of attention sink in LMs is still lacking. In this work, we first demonstrate that attention sinks exist universally in LMs with various inputs, even in small models. Furthermore, attention sink is observed to emerge during the LM pre-training, motivating us to investigate how optimization, data distribution, loss function, and model architecture in LM pre-training influence its emergence. We highlight that attention sink emerges after effective optimization on sufficient training data. The sink position is highly correlated with the loss function and data distribution. Most importantly, we find that attention sink acts more like key biases, storing extra attention scores, which could be non-informative and not contribute to the value computation. We also observe that this phenomenon (at least partially) stems from tokens' inner dependence on attention scores as a result of softmax normalization. After relaxing such dependence by replacing softmax attention with other attention operations, such as sigmoid attention without normalization, attention sinks do not emerge in LMs up to 1B parameters. The code is available at https://github.com/sail-sg/Attention-Sink.

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

↑