发现语言模型注意力集中在首词,且该现象由训练过程决定。
When Attention Sink Emerges in Language Models: An Empirical View
- 通过实验证明注意力陷阱普遍存在于各类模型中,源于预训练过程。
- 注意力陷阱位置与损失函数和数据分布高度相关,非语义重要性所致。
- 用无归一化的sigmoid注意力可消除该现象,适合研究模型偏差者。
语言模型常将大量注意力集中于首个词,即使其语义不重要,这一现象称为注意力陷阱。尽管广泛用于流式生成、缓存优化等场景,但对其机制理解仍不足。本文首次证明,注意力陷阱在多种输入下普遍存在,甚至出现在小型模型中,且在预训练过程中逐渐形成。其出现依赖于充分的优化和足够训练数据,位置受损失函数与数据分布显著影响。更重要的是,注意力陷阱更像是一种键偏置,存储额外注意力分数,可能无实际信息贡献。我们观察到该现象部分源于软最大化归一化导致词间依赖。通过替换为无归一化的sigmoid注意力,10亿参数以内的模型不再出现注意力陷阱。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。