When Attention Sink Emerges in Language Models: An Empirical View

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Gu, Xiangming, Pang, Tianyu, Du, Chao, Liu, Qian, Zhang, Fengzhuo, Du, Cunxiao, Wang, Ye, Lin, Min
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866912254430019584
author Gu, Xiangming
Pang, Tianyu
Du, Chao
Liu, Qian
Zhang, Fengzhuo
Du, Cunxiao
Wang, Ye
Lin, Min
author_facet Gu, Xiangming
Pang, Tianyu
Du, Chao
Liu, Qian
Zhang, Fengzhuo
Du, Cunxiao
Wang, Ye
Lin, Min
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2410_10781
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle When Attention Sink Emerges in Language Models: An Empirical View
Gu, Xiangming
Pang, Tianyu
Du, Chao
Liu, Qian
Zhang, Fengzhuo
Du, Cunxiao
Wang, Ye
Lin, Min
Computation and Language
Artificial Intelligence
Machine Learning
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.
title When Attention Sink Emerges in Language Models: An Empirical View
topic Computation and Language
Artificial Intelligence
Machine Learning
url https://arxiv.org/abs/2410.10781