When Attention Sink Emerges in Language Models: An Empirical View

## Abstract

Abstract 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 .

## 1 Introduction

Xiao et al. () showed that Large Language models (LLMs) allocate significant attention to the initial tokens, irrespective of their semantic relevance. This interesting phenomenon is termed as attention sink and has widespread applications, including streaming/long context generation (Xiao et al., ; Han et al., ; Yang et al., ), KV cache optimization (Ge et al., ; Wan et al., ; Wu & Tu, ), efficient inference (Zhang et al., ; Chen et al., ), model quantization (Liu et al., ; Huang et al., ), and others.

A seminal of works attempted to understand attention sink. Among them, Cancedda () clarified that attention sink primarily appears only on the first token. They found that early FFNs in LLaMA2 blast off the large norm of hidden states of the first token, thus leading to the attention sink in later layers. This is referred to as massive activations (very few activations exhibit extremely large values compared to others) in Sun et al. (). Besides, Sun et al. (); Yu et al. () observed that attention sink may also appear in several word tokens carrying limited semantic information and having no fixed position. Despite the above research efforts, a deep understanding of attention sink is still absent. Therefore, we conduct a comprehensive study to investigate when attention sink emerges.

Based on open-sourced LLMs, we show that the first token acts as biases: the angles between the first key and queries of other tokens are typically small, leading to attention sink. Then we find that attention sink universally exists in auto-regressive LMs across different inputs, even in the small models or with random token sequences. Additionally, attention sink is observed to emerge during the LM pre-training before continual instruction tuning (Ouyang et al., ). This motivates us to focus on the LM pre-training, whose objective can be formulated as:

$$ ${\color[rgb]{1.0,0.44,0.37}\definecolor[named]{pgfstrokecolor}{rgb}{ 1.0,0.44,0.37}\min_{\theta}}\hskip 1.42271pt\mathbb{E}_{{\bm{X}\sim\color[rgb] {0.0,0.2,0.6}\definecolor[named]{pgfstrokecolor}{rgb}{0.0,0.2,0.6}p_{\textrm{ data}}}}\left[{\color[rgb]{1,0.75,0}\definecolor[named]{pgfstrokecolor}{rgb}{ 1,0.75,0}\mathcal{L}}\left({\color[rgb]{0,0.5,0.5}\definecolor[named]{ pgfstrokecolor}{rgb}{0,0.5,0.5}p_{\theta}}(\bm{X})\right)\right]\textrm{.}$ (1) $$

In the remaining part of this paper, we investigate how the optimization (Section 4), data distribution (Section 5), loss function (Section 6), and model architecture (Section 7) influence the emergence of attention sink. We have the following conclusions:

- •
Attention sink emerges after LMs are trained effectively on sufficient training data. It appears less obvious in LMs trained with small learning rates. While weight decay encourages the emergence of attention sink.
- •
The sink position is highly related to the loss function and data distribution and can be shifted to other positions rather than the first token.
- •
Attention sink acts more like key biases, storing extra attention and meanwhile not contributing to the value computation. This phenomenon (at least partially) stems from tokens’ inner dependence on attention scores due to the softmax normalization. After relaxing such dependence by replacing softmax attention with other attention operations, e.g., sigmoid attention without normalization, attention sinks do not emerge in LMs up to 1B parameters.

## 2 Preliminaries on LMs and attention sink

Let $f_{\theta}$ be an auto-regressive LM with $L$ transformer decoder blocks and $\bm{X}\in\mathbb{R}^{T\times|\mathbb{V}|}:=\{\bm{x}_{1}\textrm{,}\,\bm{x}_{2}
\textrm{,}\,\ldots\textrm{,}\,\bm{x}_{T}\}$ are the input tokens, where each token $\bm{x}_{t}$ is a one-hot encoding and $|\mathbb{V}|$ is the vocabulary size of tokenizer $\mathbb{V}$. The LM output is also a sequence $\bm{Y}\in\mathbb{R}^{T\times|\mathbb{V}|}:=\{\bm{y}_{1}\textrm{,}\,\bm{y}_{2}
\textrm{,}\,\ldots\textrm{,}\,\bm{y}_{T}\}=f_{\theta}(\bm{X})$, where $\bm{y}_{t}$ represents the predicted logits of $p(\bm{x}_{t+1}|\bm{x}_{\leq t})$.

Transformer blocks. In the forward pass, $\bm{X}$ is first embedded as $\bm{H}^{0}\in\mathbb{R}^{T\times d}:=\bm{X}\bm{W}_{E}+\bm{P}$, where $\bm{W}_{E}\in\mathbb{R}^{|\mathbb{V}|\times d}$ is the learnable word embedding, $\bm{P}\in\mathbb{R}^{T\times d}$ is the positional embedding, and $d$ is the hidden dimension. We denote $\bm{H}^{l}\in\mathbb{R}^{T\times d}:=\{\bm{h}_{1}^{l}\textrm{,}\,\bm{h}_{2}^{l
}\textrm{,}\,\ldots\textrm{,}\,\bm{h}_{T}^{l}\}\textrm{,}\,1\leq l\leq L$ to be the output of the $l$-th block. Each block comprises a multi-head self-attention (MHSA) operation and a feed-forward network (FFN). The block has either a pre-norm or post-norm structure according to the location of layer normalization (LN) (Ba et al., ; Zhang & Sennrich, ). Most of LLMs consider a pre-norm block, as also shown in Figure 1(*Left*):

$$ $\bm{H}^{l}=\textrm{FFN}(\textrm{LN}(\bm{O}^{l}+\bm{H}^{l-1}))+\bm{O}^{l}+\bm{H }^{l-1}\textrm{,}\,\,\,\,\bm{O}^{l}=\textrm{MHSA}(\textrm{LN}(\bm{H}^{l-1})) \textrm{,}$ (2) $$

while the post-norm transformer block is

$$ $\bm{H}^{l}=\textrm{LN}\left(\textrm{FFN}(\textrm{LN}(\bm{O}^{l}+\bm{H}^{l-1})) +\textrm{LN}(\bm{O}^{l}+\bm{H}^{l-1})\right)\textrm{,}\,\,\,\,\bm{O}^{l}= \textrm{MHSA}(\bm{H}^{l-1})\textrm{.}$ (3) $$

Figure: Figure 1: (*Left*) Architecture of pre-norm transformer block (we highlight the location of post-norm LN using dashed lines). We denote the output of MHSA as $\bm{O}^{l}$ and the output of FFN as $\bm{F}^{l}$. (*Right*) The packing strategy in the LM pre-training. All documents are concatenated with BOS (optional) and EOS tokens as the boundaries. Then it is chunked into equal-sized sequences with context length $C$.
Refer to caption: x1.png

MHSA layers. In the MHSA layer, the input $\bm{H}^{l-1}$ are first transformed into keys, queries, and values: $\bm{K}^{l\textrm{,}h}=\bm{H}^{l-1}\bm{W}_{K}^{l\textrm{,}h}$, $\bm{Q}^{l\textrm{,}h}=\bm{H}^{l-1}\bm{W}_{Q}^{l\textrm{,}h}$, $\bm{V}^{l\textrm{,}h}=\bm{H}^{l-1}\bm{W}_{V}^{l\textrm{,}h}$ for each head $1\leq h\leq H$ (we omit the notation of LN when considering pre-norm design for simplicity). Here $\bm{W}_{K}^{l\textrm{,}h},\bm{W}_{Q}^{l\textrm{,}h},\bm{W}_{V}^{l\textrm{,}h}
\in\mathbb{R}^{d\times d_{h}}\textrm{,}\,d_{h}=d/H$. Then the attention output is computed as

$$ $\bm{A}^{l\textrm{,}h}=\textrm{Softmax}\big{(}{\bm{Q}^{l\textrm{,}h}{\bm{K}^{l \textrm{,}h}}^{T}}/{\sqrt{d_{h}}}+\bm{M}\big{)}\textrm{,}\,\,\,\,\bm{O}^{l}= \textrm{Concat}_{h=1}^{H}\left(\bm{A}^{l\textrm{,}h}\bm{V}^{l\textrm{,}h} \right)\bm{W}_{O}^{l}\textrm{,}$ (4) $$

where $\bm{M}\in\mathbb{R}^{T\times T}$ is an attention mask. For vanilla causal attention, $\bm{M}_{ij}=-\infty$ for $i<j$ and $\bm{M}_{ij}=0$ for $i\geq j$. Finally, the output of final transformer block $\bm{H}^{L}$ is fed into an unembedding layer for prediction: $\bm{Y}=\textrm{LN}(\bm{H}^{L})\bm{W}_{\textrm{cls}}$, where $\bm{W}_{\textrm{cls}}\in\mathbb{R}^{d\times|\mathbb{V}|}$.

Positional embedding. NoPE (Kazemnejad et al., ) considered no explicit positional embedding (PE) in LMs, where $\bm{P}=\bm{0}$. When using absolute PE (Vaswani et al., ), $\bm{P}$ is a periodic function of token positions. Devlin et al. (); Brown et al. () adopted a learnable PE, which means $\bm{P}$ is a learnable embedding of token positions. The dot product between each query and key meets $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\bm{q}_{i}\bm{k}_{j}^{T}$ when using the above three PEs. While for relative PE (Raffel et al., ), ALiBi (Press et al., ), Rotary (Su et al., ), they have $\bm{P}=\bm{0}$. Instead, they modify the dot product $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle$. For relative PE and ALiBi, $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\bm{q}_{i}\bm{k}_{j}^{T}+g(i-j)$, where $g(\cdot)$ is pre-defined function of the distance between two token positions. For Rotary, $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\bm{q}_{i}\bm{R}_{\Theta\textrm
{,}\,j-i}\bm{k}_{j}^{T}$, where $\bm{R}_{\Theta\textrm{,}\,(\cdot)}$ is a pre-defined rotation matrix. We include detailed formulations of the above PEs in Appendix A.

Auto-regressive objective. The pre-training objective of LMs is to maximize the likelihood of input data: $\theta^{*}=\arg\max_{\theta}\mathbb{E}_{\bm{X}\sim p_{\textrm{data}}}\left[
\sum_{t=1}^{T}\log p_{\theta}(\bm{x}_{t}|\bm{x}_{<t})\right]$, where $p_{\textrm{data}}$ refers to the data distribution.

Packing documents in pre-training. Given a large corpus $\mathcal{D}=\{\bm{d}_{1}\textrm{,}\,\bm{d}_{2}\textrm{,}\,\cdots\textrm{,}\,
\bm{d}_{|\mathcal{D}|}\}$, where each $\bm{d}_{i}$ represents a document containing a sequence of tokens. A packing strategy is adopted in the LM pre-training, as present in Figure 1(*Right*). All documents are concatenated and chunked into sequences with a context length of $C$. Each chunk could start with any token within one document or the BOS/EOS token. Then the empirical loss function for each chunk is $\mathcal{L}=\sum_{t=2}^{C}\log p_{\theta}(\bm{x}_{t}|\bm{x}_{<t})$. We note that $p_{\theta}(\bm{x}_{1})$ is ignored since $\bm{y}_{1}=f_{\theta}(\bm{x}_{1})$ is the prediction for the next token $\bm{x}_{2}$.

LM inference. During the inference, a BOS token is fed into the model as the prefix for unconditional generation: $\bm{x}^{\prime}_{t}\sim p_{\theta}(\bm{x}^{\prime}_{t}|\bm{x}^{\prime}_{<t}
\textrm{,}\,\bm{x}\textrm{,}\,\textrm{BOS})$, where $\bm{x}^{\prime}_{t}$ is the $t$-th generated token, $\bm{x}$ is the optional prompt. If there are no BOS tokens in the pre-training, the EOS token is considered as the BOS.

Attention sink. Xiao et al. () revealed that LLMs allocate significant attention scores to specific token positions, e.g. the first token, resulting in “vertical” attention patterns. This holds even when the first token is not a BOS token (Xiao et al., ; Sun et al., ). To represent this, we have the attention scores $\bm{A}_{i\textrm{,}\,1}^{l\textrm{,}\,h}\gg\textrm{mean}(\bm{A}_{i\textrm{,}\,
j\neq 1}^{l\textrm{,}\,h})$.

## 3 Properties of attention sink

Figure: Figure 2: In LLaMA3-8B Base, (*Top*) the first token has significantly larger $\ell_{2}$-norm of hidden states, but much smaller $\ell_{2}$-norm of keys and values than the mean of other tokens; (*Bottom*) cosine similarity instead of norm product contributes to attention sink. We delay more visualizations to Appendix B.3.
Refer to caption: x2.png

### 3.1 The first token acts as biases

Uniqueness of the first token. It is noted that the calculation of hidden states for the first token has no involvement of self-attention $\bm{h}_{1}^{l}=\textrm{FFN}(\textrm{LN}(\bm{o}_{1}^{l}+\bm{h}_{1}^{l-1}))+\bm{
o}_{1}^{l}+\bm{h}_{1}^{l-1}$, where $\bm{o}_{1}^{l}=\textrm{LN}(\bm{h}_{1}^{l-1})\begin{bmatrix}\bm{W}^{l\textrm{,}
1}&\bm{W}^{l\textrm{,}2}&\cdots&\bm{W}^{l\textrm{,}H}\\
\end{bmatrix}\bm{W}_{O}^{l}$. Therefore, $\bm{h}_{1}^{l}$, and corresponding queries/keys/values $\bm{k}_{1}^{l\textrm{,}h}=\textrm{LN}(\bm{h}_{1}^{l-1})\bm{W}_{K}^{l\textrm{,}h}$, $\bm{q}_{1}^{l\textrm{,}h}=\textrm{LN}(\bm{h}_{1}^{l-1})\bm{W}_{Q}^{l\textrm{,}h}$, $\bm{v}_{1}^{l\textrm{,}h}=\textrm{LN}(\bm{h}_{1}^{l-1})\bm{W}_{V}^{l\textrm{,}h}$ could be considered as the MLP output of input word embedding $\bm{x}_{1}\bm{W}_{E}$. Cancedda (); Sun et al. () showed that $\bm{h}_{1}^{l}$ has large norm or massive activations, thus behaving as a bias to absorb the attention. Using LLaMA3-8B Base model (Dubey et al., ), we show that from certain transformer block, e.g., $l=2$, the $\ell_{2}$-norm of $\bm{h}_{1}^{l}$ is significantly larger than that of other tokens $\bm{h}_{t\neq 1}$ in Figure 2(*Top*). Despite the large $\ell_{2}$-norm of hidden states, we observe that the $\ell_{2}$-norm of keys and queries of the first token is significantly smaller than that of other tokens in the same figure. This motivates us to further explore the functionality of massive activations in hidden states.

QK angles contribute to attention sink. In the $l$-th transformer block, we consider the keys and queries after adding PE (Rotary in LLaMA3-8B Base): $\bm{k}_{t}^{l\textrm{,}h}=\textrm{LN}(\bm{h}_{t}^{l-1})\bm{W}_{K}^{l\textrm{,}
h}\bm{R}_{\Theta\textrm{,}\,-t}$, $\bm{q}_{t}^{l\textrm{,}h}=\textrm{LN}(\bm{h}_{t}^{l-1})\bm{W}_{Q}^{l\textrm{,}
h}\bm{R}_{\Theta\textrm{,}\,-t}$, where LN is RMSNorm (Zhang & Sennrich, ): $\textrm{LN}(\bm{h})=\frac{\bm{h}}{\textrm{RMS}(\bm{h})}\odot\bm{g}$ and $\textrm{RMS}(\bm{h})=\sqrt{\frac{1}{d}\sum_{i=1}^{d}\bm{h}_{i}^{2}}$.
Here $\bm{g}$ is a learnable gain parameter. Suppose that $\bm{h}_{1}^{l-1}$ already has massive activations. Since $\bm{h}_{1}^{l}$ has a massive magnitude in specific dimensions, the LN operation retains the magnitude in these dimensions and further reduces the magnitude in other dimensions, leading to that $\bm{q}_{1}^{l\textrm{,}\,h}$, $\bm{k}_{1}^{l\textrm{,}\,h}$, and $\bm{v}_{1}^{l\textrm{,}\,h}$ are distributed on different manifolds, especially for $\bm{k}_{1}^{l\textrm{,}\,h}$.

For the $t$-th query, we know that $\bm{q}_{t}^{l\textrm{,}\,h}{\bm{k}_{1}^{l\textrm{,}\,h}}^{T}$ typically has much larger values than $\bm{q}_{t}^{l\textrm{,}\,h}{\bm{k}_{j\neq 1}^{l\textrm{,}\,h}}^{T}$, as visualized in Figure 2(*Bottom*). We further show that due to the different manifold of $\bm{k}_{1}^{l\textrm{,}\,h}$, the angles between $\bm{k}_{1}^{l\textrm{,}\,h}$ and $\bm{q}_{t}^{l\textrm{,}\,h}$ play an important role. Considering $\bm{q}_{t}^{l\textrm{,}h}{\bm{k}_{j}^{l\textrm{,}h}}^{T}=\left\|\bm{q}_{t}^{l
\textrm{,}h}\right\|\cdot\left\|\bm{k}_{j}^{l\textrm{,}h}\right\|\cdot\textrm{
cos}(\bm{q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{j}^{l\textrm{,}h})$, we visualize the cosine similarity between keys and values, and the product of $\ell_{2}$-norm between keys and values in Figure 2(*Bottom*). Although $\left\|\bm{q}_{t}^{l\textrm{,}h}\right\|\cdot\left\|\bm{k}_{1}^{l\textrm{,}h}\right\|$ is comparatively small, $\textrm{cos}(\bm{q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{j}^{l\textrm{,}h})$ is significantly large, leading to attention sink. This explains why attention sink exists despite the small $\ell_{2}$-norm of keys of the first token. To conclude, the first token leverages its keys to act as biases, thus minimizing the angles between $\bm{k}_{1}^{l\textrm{,}\,h}$ and $\bm{q}_{t}^{l\textrm{,}\,h}$ and exhibiting attention sink.

### 3.2 Measuring attention sink

Figure: Figure 3: The metric $\textrm{Sink}_{1}^{\epsilon}$ (averaged on 100 sequences) tends to decrease with larger token lengths $T$. This tendency becomes more obvious with the more strict definition of attention sink (larger $\epsilon$).
Refer to caption: x3.png

Threshold-based metrics. Xiao et al. () showcased the appearance of attention sink by visualizing attention logits/scores in different heads/blocks. This leads to the intractability of measuring attention sink quantitatively due to the large number of attention heads and blocks. Therefore, we first explore the metrics to measure the attention sink. Within each head, we compute the importance scores for the $k$-th token $\alpha_{k}^{l\textrm{,}h}=\frac{1}{T-k+1}\sum_{i=k}^{T}\bm{A}_{i\textrm{,}\,k}
^{l\textrm{,}\,h}$. We mainly focus on the first token $\alpha_{1}^{l\textrm{,}h}$. It is noted that $\frac{1}{T}\leq\alpha_{1}^{l\textrm{,}\,h}\leq 1$ since $\bm{A}_{1\textrm{,}\,1}^{l\textrm{,}\,h}=1$ and $0\leq\bm{A}_{i\neq 0\textrm{,}\,1}^{l\textrm{,}\,h}\leq 1$. Then we adopt a threshold-based metric, we consider a head has attention sink in the first token if $\alpha_{1}^{l\textrm{,}h}>\epsilon$. Considering that the whole model has $L$ blocks and each block has $H$ heads, we use the following metric to measure the attention sink of the whole LM: $\textrm{Sink}_{k}^{\epsilon}=\frac{1}{L}\sum_{l=1}^{L}\frac{1}{H}\sum_{h=1}^{H
}\mathbb{I}(\alpha_{k}^{l\textrm{,}h}>\epsilon)$.

Selections of thresholds. Typically, the selections of thresholds represent the strictness of quantifying attention sink. Generally, a larger $\epsilon$ represents a strict definition for attention sink. There is no principal way to find an optimal threshold and we only use this metric to quantify the emergence of attention sink empirically. Based on Figure 3, we prefer to select a threshold that is both strict in quantifying attention sink and less sensitive to the token length $T$. This gives us the selection of $\epsilon=\textrm{0.3}$. For fair comparisons, we need to fix $T$ when computing the metric, e.g., $T=\textrm{64}$.

### 3.3 Attention sink under different inputs

Different data domains. We first explore the effects of input domains on attention sinks. The pile dataset (Gao et al., ), a regular dataset for LM pretraining, has 17 available data domains. As shown in Appendix B.2, input domains have negligible effects on our attention sink metric $\textrm{Sink}_{1}^{\epsilon}$.

Beyond natural languages. We also consider two ideal scenarios: (i) randomly sample $T$ tokens from the tokenizer vocabulary $\mathbb{V}$ to construct a sequence and (ii) randomly sample 1 token from the tokenizer $\mathbb{V}$ and repeat it $T$ times. We exclude the BOS token. As present in Table 1(*Left*), compared to natural language, random tokens have insignificant effects on the existence of attention sink. However, with repeated tokens, attention sink in Mistral (Jiang et al., ) and LLaMA models disappears. In Appendix B.1, we prove that for LMs with NoPE/relative PE/ALiBI/Rotary, if the first $T$ tokens are the same, their corresponding hidden states are the same. They all have massive activations, thus dispersing the attention sink. We also provide the closed form/upper bound for attention scores in these LMs through Propositions 1-4.

**Table 1: (*Left*) Even with random sequence as input, there still exists an obvious attention sink. But with repeated tokens, the attention sink disappears for Mistral/LLaMA models. (*Right*) Chat models have comparable attention sink metrics with base models.**
| LLM | $\textrm{Sink}_{1}^{\epsilon}$(%) |  |  |
| --- | --- | --- | --- |
| natural | random | repeat |  |
| GPT2-XL | 77.00 | 70.29 | 62.28 |
| Mistral-7B | 97.49 | 75.21 | 0.00 |
| LLaMA2-7B Base | 92.47 | 90.13 | 0.00 |
| LLaMA3-8B Base | 99.02 | 91.23 | 0.00 |

Figure: Figure 4: (Left) Attention sink emerges in small LMs. (Middle) Dynamics of train/valid loss and $\textrm{Sink}_{1}^{\epsilon}$ during LM pre-training under the default setup. Attention sink emerges after certain optimization steps. (Right) Training loss (solid lines)/attention sink (dashed lines) dynamics of LMs using different learning rates. We observe that with smaller learning rates, attention sink tends to emerge after more optimization steps and be less obvious.
Refer to caption: x4.png

### 3.4 Attention sink under different LMs

Base vs. chat model. Compared with base models, chat models are typically continually trained through instruction tuning (Ouyang et al., ). From Table 1(*Right*), instruction tuning has an insignificant impact on attention sink, which motivates us to focus on the LM pre-training.

Model scale. We evaluate the metric $\textrm{Sink}_{1}^{\epsilon}$ of LLaMA2 Base (Touvron et al., ), LLaMA3 Base (Dubey et al., ), Pythia (Biderman et al., ), GPT2 (Radford et al., ), OPT (Zhang et al., ) families. As visualized in Figure 4(*Left*), attention sink emerges in small LMs, even in Pythia-14M. Only in Pythia family, larger-sized LMs tend to have more obvious attention sink.

Block-wise and head-wise property. We visualize distributions of attention sink across different blocks and heads in LLaMA2/LLaMA3/GPT2/Mistral/Pythia/OPT family in Appendix B.2. We find that (i) though different LMs may have different distributions, they tend to have less attention sink heads in the earlier blocks; (ii) instruction tuning does not significantly modify such distribution.

## 4 Effects of optimization on attention Sink.

We pre-train a series of LLaMA models to conduct our experiments. Due to the intractability of replicating LLaMA pre-training, we design small-sized models. Following Liu et al. (), we set hidden dimension $d=\textrm{768}$, block number $L=\textrm{10}$, head number $H=\textrm{8}$, intermediate size of FFN as 1536, resulting in approximately 60M parameters except for word embeddings and unembeddings. We keep the other design the same as LLaMA2 models, including Rotary (Su et al., ), pre-norm structure, RMSNorm (Zhang & Sennrich, ) as LN, SwiGLU activation (Shazeer, ) in FFN, etc.

For data distribution, we sample 5B tokens from the Pile dataset (Gao et al., ). We set the context length to 2048 tokens, the batch size to 1M tokens, and the training step to 20k (including 100 steps for warm-up). We adopt a learning rate of 4e-4 with cosine scheduling. The optimizer is AdamW (Loshchilov & Hutter, ) with a weight decay ratio of 0.1. We use the Pile-CC validation loss (Gao et al., ; Liu et al., ) to measure the model performance and sample 100 sequences with $T=64$ (no BOS token) out of training data to measure the metric $\textrm{Sink}_{k}^{\epsilon}$ with $\epsilon=\textrm{0.3}$.

**Table 2: Larger weight decay ratios tend to induce more attention sink heads in LMs. But much larger values hurt the model performance and attention sink disappears.**
| $\gamma$ | 0.0 | 0.001 | 0.01 | 0.1 | 0.5 | 1.0 | 2.0 | 5.0 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| $\textrm{Sink}_{1}^{\epsilon}$(%) | 15.20 | 15.39 | 15.23 | 18.18 | 41.08 | 37.71 | 6.13 | 0.01 |
| valid loss | 3.72 | 3.72 | 3.72 | 3.73 | 3.80 | 3.90 | 4.23 | 5.24 |

Optimization steps. As visualized in Figure 4(*Middle*), under our default setup, attention sink emerges after certain optimization steps, e.g., between 1k and 2k steps. With the progression of pre-training, attention sink becomes more obvious.

Learning rate. With a smaller learning rate, it takes longer training steps to lower training loss, as present in Figure 4(*Right*). Meanwhile, the emergence of attention sink is also delayed. Besides, we also find that a smaller learning rate (1e-4) results in LMs with less obvious attention sink. But further decreasing learning rate significantly affects the optimization and model performance, thus affecting the emergence of attention sink.

Batch size. In Table 8(*Left*), we find that only modifying batch size has no effects on attention sink.

## 5 Effects of data distribution p data subscript 𝑝 data p_{\textrm{data}} italic_p start_POSTSUBSCRIPT data end_POSTSUBSCRIPT on attention sink

Figure: Figure 5: (*Left*) Attention pattern for prefix language modeling. (*Middle*) Attention sink does not only appear on the first token but among the prefix tokens for LMs with $p=\textrm{5}$. (Right) With less training data, attention sink disappears. Meanwhile, trained LMs demonstrate overfitting behaviors.
Refer to caption: x5.png

Training data amount. In the default setup, we consider 5B tokens. We wonder whether the attention sink emerges if we further constrain the data within a fixed compute budget. Therefore, we constrain the training data to 5B, 2.5B, 500M, 200M, 100M, and 50M. Meanwhile, we fix the batch size and optimization steps. As visualized in Figure 5(*Right*), with less training data, the trained LLMs tend to overfit. Meanwhile, attention sink also disappears.

Randomness in data distribution. After packing documents into chunks, we re-sample the first token within the chunk $\bm{x}_{1}\sim\textrm{Uniform}(\mathbb{V})$. The trained LM has the metric $\textrm{Sink}_{1}^{\epsilon}=\textrm{27.03\%}$, even larger than the default setup. This further validates the low semantic information of the sink token. We also consider $\bm{x}_{1}\textrm{,}\,\bm{x}_{2}\sim\textrm{Uniform}(\mathbb{V})$, and we find attention sink shifts to the second token with $\textrm{Sink}_{2}^{\epsilon}=\textrm{14.08\%}$ while the attention sink on the first token is much less obvious $\textrm{Sink}_{1}^{\epsilon}=\textrm{1.98\%}$. But when only sample $\bm{x}_{2}\sim\textrm{Uniform}(\mathbb{V})$, the attention sink still always appears on the first token ($\textrm{Sink}_{1}^{\epsilon}=\textrm{20.99\%}$). Additionally, we find with more random tokens during pre-training, attention sink tends to disappear.

Fixing token in a specific position. Xiao et al. () considered a learnable token in the first token position within each chunk, which can be considered as $\bm{x}_{1}\sim\mathbb{I}(\bm{x}=\bm{x}_{\textrm{fix}})$. We also consider fixing the token $\bm{x}_{\textrm{fix}}$ in the second/third token position during pre-training. Consequently, the attention sink always appears in the fixed token instead of the first token, as shown in Table 8(*Right*).

## 6 Effects of loss function ℒ ℒ \mathcal{L} caligraphic_L on attention sink

Weight decay. The loss function becomes $\mathcal{L}=\sum_{t=2}^{C}\log p_{\theta}(\bm{x}_{t}|\bm{x}_{<t})+\gamma\left
\|\theta\right\|_{2}^{2}$ when introducing weight decay ratio $\gamma$. As indicated in Table 2, even $\gamma=\textrm{0}$ in the loss function, attention sink still emerges in LMs. Then a larger $\gamma$ encourages more heads to have attention sink. But further increasing weight decay hurts the optimization, leading to less obvious or even no attention sink.

Figure: Figure 6: (*Left*) Shifted window attention pattern. (*Middle*) In LMs with window attention, attention sink appears on the first token, but not on the “first token” within each window. (*Right*) Attention sink tends to emerge when the window size is large enough.
Refer to caption: x6.png

Prefix language modeling. Since the first token is not predicted in the auto-regressive loss function, it could be considered as the prefix token. Then the original auto-regressive loss can be generalized into the formula $\mathcal{L}=\sum_{t=p+1}^{C}\log p_{\theta}(\bm{x}_{t}|\bm{x}_{p+1:t-1}\textrm
{,}\,\bm{x}_{1:p})$, with the prefix length $p=1$. Motivated by Wang et al. (), we consider $p>1$ and the casual mask visualized in Figure 5(*Left*). Although this design does not affect the emergence of attention sink, it shifts the sink position. In Figure 5(*Middle*), the attention sink only appears on one token. But it appears among these prefix tokens instead of on the first token only. Massive activations also appear on the corresponding sink token.

Shifted window attention. Motivated by the shifted window attention adopted in Mistral-7B, we further explore the effects of window size on attention sink. With shifted window attention, the loss function becomes $\mathcal{L}=\sum_{t=2}^{C}\log p_{\theta}(\bm{x}_{t}|\bm{x}_{t-w:t-1})$, where $w$ refers to the window size. As shown in Figure 6(*Left*) and (*Middle*), with shifted window attention, we find that if $t\leq w$, the $t$-th token can still “look at” the first token, and LMs still have attention sink on the first token. When $t>w$, the $t$-th token can only attend up to the $t-w+1$-th token. Although this token is the “first token” for the $t$-th token, typically it has no attention sink. We have similar observations in Mistral-7B. Additionally, from Figure 6(*Right*), smaller window size prevents the emergence of attention sink.

## 7 Effects of model architecture p θ subscript 𝑝 𝜃 p_{\theta} italic_p start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT on attention sink

In this section, we mainly explore the effects of positional embedding, pre-norm or post-norm structure, and attention design on the emergence of attention sink. In Appendix C, we also show that varying activation functions in the FFN, multi-head design (including concatenation operation and number of heads) do not affect the emergence of attention sink.

### 7.1 Positional embedding

Attention sink always appears on the first token, which motivates us to explore where such a position property is brought by positional embedding (PE). Therefore, we attempt to replace the original Rotary with other PEs, as shown in Table 3. We differentiate these PEs through the calculations of the hidden states $\bm{H}^{0}$ before the first transformer block and the dot product between queries and keys $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle$. The detailed formulations are delayed to Appendix A. From the same Table, we observe that only the model with relative PE is difficult to train while other models have comparable performance under our setup. Then we note that all these LMs, even the one without explicit PE (NoPE), have attention sink.

### 7.2 Pre-norm and post-norm structure

Layer normalization (LN) (Ba et al., ; Zhang & Sennrich, ) regularizes the hidden states in LMs by re-centering and re-scaling, which may affect the massive activations. This motivates us to explore the effects of LN location on attention sink. In the pre-norm structure, as stated in Equation 2, hidden states from the earlier blocks could be retained by the later blocks through residual connections (He et al., ). Therefore, if massive activations appear in a specific block, they will likely be retained in the subsequent blocks. Within a post-norm structure, the hidden states will be normalized before being fed into the following blocks, as present in Figure 1(*Left*).

When replacing the pre-norm structure with the post-norm structure, $\textrm{Sink}_{1}^{\epsilon}$ becomes 13.54%. This indicates that the attention sink still exists in post-norm LMs. After further investigations, as visualized in Figure 7(*Left*), massive activations exist in the hidden states before the post LN instead of $\bm{h}_{1}^{l}$.

**Table 3: Positional embedding does not affect the emergence of attention sink.**
| PE | $\bm{H}^{0}$ | $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle$ | $\textrm{Sink}_{1}^{\epsilon}$(%) | valid loss |
| --- | --- | --- | --- | --- |
| NoPE | $\bm{X}\bm{W}_{E}$ | $\bm{q}_{i}\bm{k}_{j}^{T}$ | 20.35 | 3.81 |
| Absolute PE | $\bm{X}\bm{W}_{E}+\bm{P}_{\textrm{abs}}$ | $\bm{q}_{i}\bm{k}_{j}^{T}$ | 32.73 | 3.74 |
| Learnable PE | $\bm{X}\bm{W}_{E}+\bm{P}_{\textrm{learnable}}$ | $\bm{q}_{i}\bm{k}_{j}^{T}$ | 33.13 | 3.79 |
| Relative PE | $\bm{X}\bm{W}_{E}$ | $\bm{q}_{i}\bm{k}_{j}^{T}+g_{\textrm{relative}}(i-j)$ | 35.53 | 5.45 |
| ALiBi | $\bm{X}\bm{W}_{E}$ | $\bm{q}_{i}\bm{k}_{j}^{T}+g_{\textrm{alibi}}(i-j)$ | 20.78 | 3.71 |
| Rotary | $\bm{X}\bm{W}_{E}$ | $\bm{q}_{i}\bm{R}_{\Theta\textrm{,}\,j-i}\bm{k}_{j}^{T}$ | 18.18 | 3.73 |

Figure: Figure 7: $\ell_{2}$-norm ratio of $\bm{h}_{1}^{l}$ and mean of $\bm{h}_{t\neq 0}^{l}$. (*Left*) Massive activations exist not in hidden states in post-norm LMs, but in the features before LN. (*Middle*) LMs with KV biases or K biases have no massive activations, while LMs with a learnable sink token or V biases have massive activations. (*Right*) Massive activations emerge when increasing the $\ell_{2}$-norm of fixed $\bm{v}^{*l\textrm{,}\,h}$ for the setup of K biases.
Refer to caption: x7.png

**Table 4: With comparable performance, LMs with sink token, KV biases, and K biases could shift attention sink from the first token to key biases’ position. Value biases cannot affect attention sink.**
| Attention in each head | $\textrm{Sink}_{*}^{\epsilon}$(%) | $\textrm{Sink}_{1}^{\epsilon}$(%) | valid loss |
| --- | --- | --- | --- |
| $\textrm{Softmax}\left(\frac{1}{\sqrt{d_{h}}}\bm{Q}^{l\textrm{,}h}{\bm{K}^{l<br>\textrm{,}h}}^{T}{\sqrt{d_{h}}}+\bm{M}\right)\bm{V}^{l\textrm{,}h}$ | - | 18.18 | 3.73 |
| $\textrm{Softmax}\left(\frac{1}{\sqrt{d_{h}}}\begin{bmatrix}\bm{q}^{*l,h}\\<br>\bm{Q}^{l,h}\end{bmatrix}\begin{bmatrix}{\bm{k}^{*l\textrm{,}h}}^{T}&{\bm{K}^{<br>l\textrm{,}h}}^{T}\end{bmatrix}+\bm{M}\right)\begin{bmatrix}\bm{v}^{*l\textrm{<br>,}h}\\<br>\bm{V}^{l\textrm{,}h}\end{bmatrix}$ | 74.12 | 0.00 | 3.72 |
| $\textrm{Softmax}\left(\frac{1}{\sqrt{d_{h}}}\bm{Q}^{l\textrm{,}h}\begin{<br>bmatrix}{\bm{k}^{*l\textrm{,}h}}^{T}&{\bm{K}^{l\textrm{,}h}}^{T}\end{bmatrix}+<br>\bm{M}\right)\begin{bmatrix}\bm{v}^{*l\textrm{,}h}\\<br>\bm{V}^{l\textrm{,}h}\end{bmatrix}$ | 72.76 | 0.04 | 3.72 |
| $\textrm{Softmax}\left(\frac{1}{\sqrt{d_{h}}}\bm{Q}^{l\textrm{,}h}\begin{<br>bmatrix}{\bm{k}^{*l\textrm{,}h}}^{T}&{\bm{K}^{l\textrm{,}h}}^{T}\end{bmatrix}{<br>\sqrt{d_{h}}}+\bm{M}\right)\begin{bmatrix}\bm{0}\\<br>\bm{V}^{l\textrm{,}h}\end{bmatrix}$ | 73.34 | 0.00 | 3.72 |
| $\textrm{Softmax}\left(\frac{1}{\sqrt{d_{h}}}\bm{Q}^{l\textrm{,}h}{\bm{K}^{l<br>\textrm{,}h}}^{T}+\bm{M}\right)\bm{V}^{l\textrm{,}h}+\bm{v}^{*l\textrm{,}h}$ | - | 17.53 | 3.73 |

### 7.3 Attention biases

Implicit biases in attention. In Section 3.1, we have shown that the first token acts as a bias: its key $\bm{k}_{1}^{l\textrm{,}\,h}$ is distributed in a different manifold and its value $\bm{v}_{1}^{l\textrm{,}\,h}$ has small $\ell_{2}$ norm. Xiao et al. () considered a learnable sink token in each chunk before the input tokens during LM pre-training. As this token is fixed in the first token, this could be considered as implicitly introducing biases $\bm{k}^{*l,h}$, $\bm{v}^{*l,h}$, $\bm{q}^{*l,h}$ in attention, as shown in the second row in Table 4. These biases are the MLP output of $\bm{x}^{*}\bm{W}_{E}$. As a result, attention sink appears on this learnable token $\bm{x}^{*}$ instead of the actual first token $\bm{x}_{1}$.

Explicit biases in attention. Sun et al. () directly introducing $\bm{k}^{*l,h}$ and $\bm{v}^{*l,h}$ as learnable parameters in attention (*KV biases*). They found that this design could alleviate the massive activations. Considering the important role of $\bm{k}^{*l,h}$ and small $\ell_{2}$-norm of $\bm{v}^{*l,h}$ , we propose introducing only the key biases $\bm{k}^{*l,h}$ and fix value biases $\bm{v}^{*l,h}=\bm{0}$ (*K biases*). As a control, we also consider only adding value biases (*V biases*). The formulations of all these attention designs are shown in Table 4.

LMs need key biases. After evaluating the LMs with setups in Table 4, we first observe that these LMs have comparable model performance. Moreover, as long as there are key biases $\bm{k}^{*l\textrm{,}\,h}$, attention sink disappears on the first token but on the biases. From the setup of K biases, we reaffirm that the sink token acts as key biases, storing extra attention scores, which could be completely non-informative and not contribute to the value computation. This is different from the registers (Darcet et al., ), which aggregates global information, in Vision Transformers (ViTs) (Dosovitskiy, ). It is worth mentioning that the introduced learnable sink token, KV biases, and V biases become part of model parameters in LMs. Removing them will lead to no attention sink in the first position, but a significant drop in model performance. In Figure 7(*Middle*), we also find that the LM with a learnable sink token has massive activations in $\bm{x}^{*}$. While LMs with KV biases and K biases have no massive activations.

**Table 5: (*Top*) Larger $\ell_{2}$-norm of fixed $\bm{v}^{*l\textrm{,}h}$ results in LMs allocating more attention on $\bm{x}_{1}$ instead of $\bm{k}^{*l\textrm{,}h}$. (*Bottom*) Even with very few learnable dimensions for $\bm{k}^{*l\textrm{,}h}$, large attention appears in $\bm{k}^{*l\textrm{,}h}$.**
| $\bm{v}^{*l,h}$ | $\bm{0}$ | $\bm{v}^{\prime}$ | 5$\bm{v}^{\prime}$ | 20$\bm{v}^{\prime}$ | $\bm{v}^{\prime\prime}$ | 5$\bm{v}^{\prime\prime}$ | 20$\bm{v}^{\prime\prime}$ |
| --- | --- | --- | --- | --- | --- | --- | --- |
| $\textrm{Sink}_{*}^{\epsilon}$(%) | 73.34 | 70.03 | 44.43 | 1.51 | 69.74 | 27.99 | 0.00 |
| $\textrm{Sink}_{1}^{\epsilon}$(%) | 0.00 | 0.06 | 3.71 | 25.88 | 2.15 | 5.93 | 11.21 |
| valid loss | 3.72 | 3.72 | 3.72 | 3.71 | 3.72 | 3.72 | 3.73 |
| $d_{a}$ | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
| $\textrm{Sink}_{*}^{\epsilon}$(%) | 32.18 | 30.88 | 30.94 | 31.39 | 23.30 | 51.23 | 69.19 |
| $\textrm{Sink}_{1}^{\epsilon}$(%) | 4.74 | 4.96 | 4.39 | 4.54 | 2.19 | 1.94 | 0.04 |
| valid loss | 3.73 | 3.72 | 3.72 | 3.73 | 3.73 | 3.73 | 3.72 |

Beyond all zeros in V biases. In the setup of K biases, we fix $\bm{v}^{*l,h}=\bm{0}$. We wonder whether the fixed values of $\bm{v}^{*l,h}$ could affect the attention sink. We consider, $\bm{v}^{*l,h}=m\bm{v}^{\prime}$ or $\bm{v}^{*l,h}=m\bm{v}^{\prime\prime}$, where $m$ is the controllable $\ell_{2}$ norm and $\bm{v}^{\prime}=[1,0,0,..,0]$ and $\bm{v}^{\prime\prime}=[1,1,1,..,1]/\sqrt{d_{h}}$. As shown in Table 5(*Top*), with larger $\ell_{2}$-norm of $\bm{v}^{*l,h}$, attention sink shifts from $\bm{k}^{*l,h}$ to the first token. Intuitively, it is difficult for LMs to remove the effects of $\bm{v}^{*l,h}$ with larger $\ell_{2}$-norm in model predictions. Then they opt to optimize the keys and values of the first token to save extra attention.

Learnable dimensions of K biases. In the setup of K biases, we set all dimensions of $\bm{k}^{*l\textrm{,}\,h}$ as learnable weights. In Section 3.1, we have shown that K biases are distributed in a different manifold, with low rank. Therefore, we consider only $d_{a}$ dimensions of $\bm{k}^{*l\textrm{,}\,h}$ are adjustable/learnable while the other $d_{h}-d_{a}$ dimensions are zeros. As present in Table 5(*Bottom*), with very few learnable dimensions, even for $d_{a}=\textrm{1}$, $\bm{k}^{*l\textrm{,}\,h}$ are still allocated significant attention. With more learnable dimensions, the attention sink appears more obvious.

Head-sharing biases.. In Appendix C, we explore whether different heads in each block can share the same parameters for KV biases. Results in Table 10(*Right*) show that the LM with KV biases tends to shift the attention sink from $\bm{k}^{*l,h}$ back to the first token. While the LM with K biases is less affected.

### 7.4 Attention operation

General formulation of attention. In the last section, we realize that LMs with softmax attention need key biases to save extra attention. This motivates us to explore whether such a property is related to the dependence among attention scores due to the softmax operation. First, the attention output for the $i$-th token can be generalized into the following formulation: $\bm{v}_{i}^{\dagger}=\left(\sum_{j^{\prime}=1}^{i}\textrm{sim}(\varphi(\bm{q}_
{i})\textrm{,}\,\varphi(\bm{k}_{j^{\prime}}))\right)^{-1}\sum_{j=1}^{i}\textrm
{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j}))\bm{v}_{j}=\bm{Z}_{i}
^{-1}\sum_{j=1}^{i}\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_
{j}))\bm{v}_{j}$,
where we omit the positional embedding, and block/head indexes for simplicity. $\bm{Z}_{i}$ is a normalization term and $\varphi(\cdot)$ is a kernel function. Normally, $\bm{Z}_{i}=\sum_{j^{\prime}=1}^{i}\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,
\varphi(\bm{k}_{j}))$. For softmax attention, the kernel $\varphi(\cdot)$ is an identity kernel and the similarity function is $\textrm{exp}(\bm{q}_{i}^{T}\bm{k}_{j}/\sqrt{d_{h}})$.

Normalization. In Appendix C, we first show that only scaling the normalization term $\bm{Z}_{i}\rightarrow\bm{Z}_{i}/\alpha$ with $\alpha<\textrm{1}$ results in less obvious attention sink but does not stop its emergence. So we consider removing the normalization. Since the exponential function in softmax tends to explode without normalization, we replace it with sigmoid or elu plus one. When evaluating the attention sink, we compute the proxy attention scores by using the term $\bm{Z}_{i}=\sum_{j^{\prime}=1}^{i}\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,
\varphi(\bm{k}_{j^{\prime}}))$ for attention sink metric $\textrm{Sink}_{1}^{\epsilon}$. As shown in Table 6, without normalization, LMs still have comparable validation loss but no attention sink. With normalization, attention sink also emerges in LMs with sigmoid attention.

**Table 6: Normalization and selections of kernels in attention significantly affect the emergence of the attention sink. We use “*” to mark that the metric $\textrm{Sink}_{1}^{\epsilon}$ is computed by proxy attention scores.**
| $\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j}))$ | $\bm{Z}_{i}$ | $\textrm{Sink}_{1}^{\epsilon}$(%) | valid loss |
| --- | --- | --- | --- |
| $\textrm{exp}(\frac{\bm{q}_{i}^{T}\bm{k}_{j}}{\sqrt{d_{h}}})$ | $\sum_{j^{\prime}=1}^{i}\textrm{exp}(\frac{\bm{q}_{i}\bm{k}_{j^{\prime}}^{T}}{<br>\sqrt{d_{h}}})$ | 18.18 | 3.73 |
| $\textrm{sigmoid}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})$ | $1$ | 0.44^∗ | 3.70 |
| $\textrm{sigmoid}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})$ | $\sum_{j^{\prime}=1}^{i}\textrm{sigmoid}(\frac{\bm{q}_{i}\bm{k}_{j^{\prime}}^{T<br>}}{\sqrt{d_{h}}})$ | 30.24 | 3.74 |
| $\textrm{elu}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})+1$ | $1$ | 0.80^∗ | 3.69 |
| $\frac{(\textrm{elu}(\bm{q}_{i})+1)(\textrm{elu}(\bm{k}_{j})+1)^{T}}{\sqrt{d_{h<br>}}}$ | $\sum_{j^{\prime}=1}^{i}\frac{(\textrm{elu}(\bm{q}_{i})+1)(\textrm{elu}(\bm{k}_<br>{j^{\prime}})+1)^{T}}{\sqrt{d_{h}}}$ | 53.65^∗ | 4.19 |
| $\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}}$ | $1$ | 0.00^∗ | 3.99 |
| $\frac{\textrm{mlp}(\bm{q}_{i})\textrm{mlp}(\bm{k}_{j})^{T}}{\sqrt{d_{h}}}$ | $\textrm{max}\left(\left|\sum_{j^{\prime}=1}^{i}\frac{\textrm{mlp}(\bm{q}_{i})<br>\textrm{mlp}(\bm{k}_{j^{\prime}})^{T}}{\sqrt{d_{h}}}\right|\textrm{,}\,1\right)$ | 0.19^∗ | 3.85 |
| $\frac{\textrm{mlp}(\bm{q}_{i})\textrm{mlp}(\bm{k}_{j})^{T}}{\sqrt{d_{h}}}$ | $1$ | 0.74^∗ | 3.91 |

Figure: Figure 8: We visualize the $\ell_{2}$-norm ratio of $\bm{h}_{1}^{l}$ and mean of $\bm{h}_{t\neq 0}^{l}$. (*Left*) Massive activations exist in LMs with attention scores that are non-negative and added up to one. (*Middle*) Massive activations do not exist in LMs with independent attention scores. (*Right*) When scaling the model size to 1B, LLMs with sigmoid attention (no normalization) still have no massive activations.
Refer to caption: x8.png

Kernel functions. Motivated by linear attention (Katharopoulos et al., ), we consider different kernel functions $\varphi(\cdot)$, including elu plus one, identity, and MLP. It is noted that $\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j^{\prime}}))$ could be minus for identity and MLP kernels. This brings intrinsic difficulty for normalization during the training and calculation of $\textrm{Sink}_{1}^{\epsilon}$. For normalization in the training, we consider $\bm{Z}_{i}=\textrm{max}\big{(}\big{|}\sum_{j^{\prime}=1}^{i}\textrm{sim}(
\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j^{\prime}}))\big{|}\textrm{,}
\,1\big{)}$. When computing $\textrm{Sink}_{1}^{\epsilon}$, we consider the proxy attention scores $\left|\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j}))\right|/
\sum_{j^{\prime}=1}^{i}\left|\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,
\varphi(\bm{k}_{j^{\prime}}))\right|$. From Table 6 (a full version in Table 12), we find that the LM with MLP kernel have no attention sink with or without normalization.

Inner dependence on attention scores. We note that the LMs with no attention sink typically relax tokens’ inner dependence on attention scores. Their attention scores during pre-training could be negative or not add up to one. This indicated that attention sink (at least partially) stems from such inner dependence. Besides the attention metric computed by proxy attention scores, we also observe that the above LMs also have no massive activations, as shown in Figure 8(*Middle*).

Scale up to 1B parameters. We compare model behaviors of 1B LMs with softmax attention and sigmoid attention (without normalization). Specifically, the latter achieves a validation loss of 3.10, slightly larger than the 3.07 achieved by the former. However, the attention sink metric significantly drops from 45.11% to near zero: $\textrm{Sink}_{1}^{\epsilon}=\textrm{2.46\%}$ using the proxy attention scores. Meanwhile, as visualized in Figure 8(*Right*), LLMs with sigmoid attention have no massive activations.

## 8 Future work

This work focuses on the sink token in the first position. Sun et al. (); Yu et al. () showed that attention sink can also appear on certain word tokens, e.g., period and newline tokens. However, these sink words may vary in different LMs and typically have no fixed positions. In the future, we will extend the research scope to explore how these sink tokens are related to the pre-training. Additionally, we will also consider learnable KV biases in continual pre-training or instruction tuning.

## Appendix A Detailed formulations of positional embedding

In this section, we provide detailed formulations of positional embedding (PE) in LMs. PEs could be classified into two categories. NoPE, absolute positional embedding, and learnable positional embedding belong to the same category since they are added to the initial hidden states: $\bm{H}^{0}=\bm{X}\bm{W}_{E}+\bm{P}$. Here $\bm{P}=\left\{\bm{p}_{1}\textrm{,}\,\bm{p}_{2}\textrm{,}\,\cdots\textrm{,}\,
\bm{p}_{T}\right\}\in\mathbb{R}^{T\times d}$. Meanwhile, the dot product between each query and key is computed as $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\bm{q}_{i}^{T}\bm{k}_{j}$.

NoPE. NoPE (Kazemnejad et al., ) refers to no positional embedding. Therefore, $\bm{P}=\bm{0}$.

Absolute PE. Each position vector $\bm{p}_{t}$ in absolute positional embedding is a periodic function of token position $t$ following Vaswani et al. ():

$$ $\bm{p}_{t}=\begin{bmatrix}\sin(\omega_{1}t)&\cos(\omega_{1}t)&\sin(\omega_{2}t )&\cos(\omega_{2}t)&\cdots&\sin(\omega_{d/2}t)&\cos(\omega_{d/2}t)\\ \end{bmatrix}\textrm{,}$ (5) $$

where $\omega_{i}=1/\textrm{10000}^{2(i-1)/d}$.

Learnable PE. Each position vector $\bm{p}_{t}$ in learnable positional embeddings is a learnable parameter.

Relative positional embedding, ALibi, and rotary belong to another category since they consider the relative distance among tokens. Therefore, the initial hidden states are $\bm{H}^{0}=\bm{X}\bm{W}_{E}$ but how to compute the dot product between each query and key is modified.

Relative PE. The relative positional embeddings are adopted in T5 models (Raffel et al., ). A bias term is adopted for the dot product: $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\bm{q}_{i}\bm{k}_{j}^{T}+g(i-j)$, where the definition for distance function $g(\cdot)$ is:

$$ $g(i-j)=\left\{\begin{array}[]{lcl}i-j&&\textrm{if}\,\,\,\,i-j<\mathcal{B}/2\\ \frac{\mathcal{B}}{2}+\lfloor\frac{\log(\frac{i-j}{\mathcal{B}/2})}{\log(\frac {\mathcal{D}}{\mathcal{B}/2})}\rfloor\times\frac{\mathcal{B}}{2}&&\textrm{if} \,\,\,\,\mathcal{B}/2\leq i-j<\mathcal{D}\\ \mathcal{B}-1&&\textrm{if}\,\,\,\,i-j\geq\mathcal{D}\end{array}\right.$ (6) $$

Here $\mathcal{B}$ and $\mathcal{D}$ refer to the number of buckets and maximum distance, respectively. In T5 models, $\mathcal{B}=\textrm{32}$ and $\mathcal{D}=\textrm{128}$.

ALiBi. Similarly, ALiBi (Press et al., ) also adds a bias term to the dot product: $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\bm{q}_{i}^{T}\bm{k}_{j}+g(i-j)$, where $g(i-j)=-(i-j)\cdot m$. $m$ is a head-specific slope fixed:

$$ $m=2^{-h\cdot 2^{-\log_{2}H+3}}\textrm{,}$ (7) $$

where $1\leq h\leq H$ is the head index and $H$ is the number of heads in the multi-head self-attention (MHSA). This slope $m$ is a geometric sequence. For instance, when $H=8$, the sequence is $\frac{1}{2^{1}}\textrm{,}\,\frac{1}{2^{2}}\textrm{,}\,\cdots\textrm{,}\,\frac{
1}{2^{8}}$. When $H=16$, the sequence is $\frac{1}{2^{0.5}}\textrm{,}\,\frac{1}{2^{1}}\textrm{,}\,\frac{1}{2^{1.5}}
\textrm{,}\,\cdots\textrm{,}\,\frac{1}{2^{8}}$.

Rotary. Rotary (Su et al., ) is the most adopted position encoding approach in the LLM community. It projects queries and keys into another space through rotations:

$$ $\langle\bm{q}_{i}\textrm{,}\,\bm{k}_{j}\rangle=\left(\bm{q}_{i}\bm{R}_{\Theta \textrm{,}\,-i}\right)\left(\bm{k}_{j}\bm{R}_{\Theta\textrm{,}\,-j}\right)^{T} =\bm{q}_{i}\bm{R}_{\Theta\textrm{,}\,-i}\bm{R}_{\Theta\textrm{,}\,j}\bm{k}_{j} ^{T}=\bm{q}_{i}\bm{R}_{\Theta\textrm{,}\,j-i}\bm{k}_{j}^{T}\textrm{,}$ (8) $$

where $\bm{R}_{\Theta\textrm{,}\,(\cdot)}$ is a pre-defined rotation matrix:

$$ $\bm{R}_{\Theta,m}=\left(\begin{array}[]{ccccccc}\cos m\omega_{1}&-\sin m\omega _{1}&0&0&\cdots&0&0\\ \sin m\omega_{1}&\cos m\omega_{1}&0&0&\cdots&0&0\\ 0&0&\cos m\omega_{2}&-\sin m\omega_{2}&\cdots&0&0\\ 0&0&\sin m\omega_{2}&\cos m\omega_{2}&\cdots&0&0\\ \vdots&\vdots&\vdots&\vdots&\ddots&\vdots&\vdots\\ 0&0&0&0&\cdots&\cos m\omega_{d_{h}/2}&-\sin m\omega_{d_{h}/2}\\ 0&0&0&0&\cdots&\sin m\omega_{d_{h}/2}&\cos m\omega_{d_{h}/2}\\ \end{array}\right)\textrm{.}$ (9) $$

Here $\omega_{i}=1/\textrm{10000}^{2(i-1)/d_{h}}$ and $d_{h}=d/H$ is the hidden dimension in each head. From the above definition, it is noted that the rotation matrix $\bm{R}_{\Theta,m}^{d_{h}}$ satisfies $\bm{R}_{\Theta,m}^{T}=\bm{R}_{\Theta,-m}$ and $\bm{R}_{\Theta,i}\bm{R}_{\Theta,j}=\bm{R}_{\Theta,i+j}$.

## Appendix B Attention sink in open-sourced LMs

### B.1 How positional embedding relates with attention sink

In Section 3.3, we have shown that Mistral-7B, LLaMA2-7B Base, and LLaMA3-8B Base, which adopt rotary as PE, have no attention sink for repeated token sequences. While GPT2, which adopts learnable PE, has the attention sink in such a scenario. To further understand this, we explore how positional embedding plays a role through a theoretical perspective.

Activations. Suppose the repeated sequence is $\bm{X}=\{\bm{x}_{1}\textrm{,}\,\bm{x}_{2}\textrm{,}\,\ldots\textrm{,}\,\bm{x}_
{T}\}$ and each $\bm{x}_{t}=\bm{x}$. For LMs with NoPE/relative PE/ALiBi/Rotary, we have the initial hidden states $\bm{h}_{t}^{0}=\bm{x}\bm{W}_{E}$, which are the same among all the token positions since $\bm{P}=\bm{0}$. Then for the first transformer block $l=1$, we know that $\bm{k}_{t}^{1\textrm{,}h}=\textrm{LN}(\bm{h}_{t}^{0})\bm{W}_{K}^{1\textrm{,}h}
=\textrm{LN}(\bm{x}\bm{W}_{E})\bm{W}_{K}^{1\textrm{,}h}$, $\bm{q}_{t}^{1\textrm{,}h}=\textrm{LN}(\bm{h}_{t}^{0})\bm{W}_{Q}^{1\textrm{,}h}
=\textrm{LN}(\bm{x}\bm{W}_{E})\bm{W}_{Q}^{1\textrm{,}h}$, $\bm{v}_{t}^{1\textrm{,}h}=\textrm{LN}(\bm{h}_{t}^{0})\bm{W}_{V}^{1\textrm{,}h}
=\textrm{LN}(\bm{x}\bm{W}_{E})\bm{W}_{V}^{1\textrm{,}h}$. Then all tokens have the same $\bm{k}_{t}^{1\textrm{,}h}$, $\bm{q}_{t}^{1\textrm{,}h}$, and $\bm{v}_{t}^{1\textrm{,}h}$. Then the attention output is

$$ $\bm{v}_{t}^{\dagger 1\textrm{,}\,h}=\sum_{i=1}^{t}\bm{A}_{ti}^{1\textrm{,}\,h} \bm{v}_{i}^{1\textrm{,}\,h}=\bm{v}_{t}^{1\textrm{,}\,h}$ (10) $$

Then $\bm{o}_{t}^{1}=\textrm{Concat}_{h=1}^{H}(\bm{v}_{t}^{1\textrm{,}\,h})\bm{W}_{O
}^{1}$, we have the hidden states after the first block:

$$ $\displaystyle\bm{h}_{t}^{1}$ $\displaystyle=\textrm{FFN}(\textrm{LN}(\bm{o}_{t}^{1}+\bm{h}_{t}^{0}))+\bm{o}_ {t}^{1}+\bm{h}_{t}^{0}$ (11) $\displaystyle=\textrm{FFN}(\textrm{LN}(\textrm{Concat}_{h=1}^{H}(\bm{v}_{t}^{1 \textrm{,}\,h})\bm{W}_{O}^{1}+\bm{h}_{t}^{0}))+\textrm{Concat}_{h=1}^{H}(\bm{v }_{t}^{1\textrm{,}\,h})\bm{W}_{O}^{1}+\bm{h}_{t}^{0}$ (12) $\displaystyle=\textrm{FFN}(\textrm{LN}(\textrm{Concat}_{h=1}^{H}(\textrm{LN}( \bm{h}_{t}^{0})\bm{W}_{V}^{1\textrm{,}h})\bm{W}_{O}^{1}+\bm{h}_{t}^{0}))$ (13) $\displaystyle+\textrm{Concat}_{h=1}^{H}(\textrm{LN}(\bm{h}_{t}^{0})\bm{W}_{V}^ {1\textrm{,}h})\bm{W}_{O}^{1}+\bm{h}_{t}^{0}\textrm{.}$ (14) $$

Since $\bm{h}_{1}^{0}=\bm{h}_{2}^{0}=\cdots=\bm{h}_{T}^{0}$, we have $\bm{h}_{1}^{1}=\bm{h}_{2}^{1}=\cdots=\bm{h}_{T}^{1}$ based on the above equation. Using this induction, we could prove that

$$ $\displaystyle\bm{h}_{t}^{l}$ $\displaystyle=\textrm{FFN}(\textrm{LN}(\textrm{Concat}_{h=1}^{H}(\textrm{LN}( \bm{h}_{t}^{l-1})\bm{W}_{V}^{l\textrm{,}h})\bm{W}_{O}^{l}+\bm{h}_{t}^{l-1}))$ (15) $\displaystyle+\textrm{Concat}_{h=1}^{H}(\textrm{LN}(\bm{h}_{t}^{l-1})\bm{W}_{V }^{l\textrm{,}h})\bm{W}_{O}^{l}+\bm{h}_{t}^{l-1}\textrm{,}\,\,\,\,\forall\,\, \,1\leq l\leq L\textrm{.}$ (16) $$

$$ $\bm{h}_{1}^{l}=\bm{h}_{2}^{l}=\cdots=\bm{h}_{T}^{l}\textrm{,}\,\,\,\,\forall\, \,\,0\leq l\leq L\textrm{.}$ (17) $$

Typically, the hidden states of the first token $\bm{h}_{1}^{l}$ in specific blocks have massive activations. Due to the above equality, all the repeated tokens have massive activations.

For LMs with absolute PE/learnable PE, the initial hidden states $\bm{h}_{t}^{0}=\bm{x}\bm{W}_{E}+\bm{p}_{t}$. Although the word embeddings are the same for repeated tokens, $\bm{p}_{t}$ for different token positions $t$ is different. Therefore, GPT2 models have no the above equality.

###### Proposition 1 .

For LMs with NoPE, the attention scores for $t$ repeated tokens are $t^{-1}$ uniformly, i.e., there is no attention sink.

###### Proof.

We have that

$$ $\bm{A}_{ti}^{l\textrm{,}\,h}=\frac{e^{\langle\bm{q}_{t}^{l\textrm{,}h}\textrm{ ,}\,\bm{k}_{i}^{l\textrm{,}h}\rangle}}{\sum_{j=1}^{t}e^{\langle\bm{q}_{t}^{l \textrm{,}h}\textrm{,}\,\bm{k}_{j}^{l\textrm{,}h}\rangle}}=\frac{e^{\bm{q}_{t} ^{l\textrm{,}h}{\bm{k}_{i}^{l\textrm{,}h}}^{T}}}{\sum_{j=1}^{t}e^{\bm{q}_{t}^{ l\textrm{,}h}{\bm{k}_{j}^{l\textrm{,}h}}^{T}}}=\frac{e^{\bm{q}^{l\textrm{,}h}{ \bm{k}^{l\textrm{,}h}}^{T}}}{te^{\bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^ {T}}}=\frac{1}{t}\textrm{.}$ (18) $$

Therefore, the attention scores follow a uniform distribution over all previous tokens.
∎

###### Proposition 2 .

For LMs with relative PE, there is no attention sink for $t$ repeated tokens.

###### Proof.

For LMs with relative PE, the dot product between each query and key is

$$ $\langle\bm{q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{i}^{l\textrm{,}h}\rangle= \bm{q}_{t}^{l\textrm{,}h}{\bm{k}_{i}^{l\textrm{,}h}}^{T}+g_{\textrm{rel}}(t-i) =\bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^{T}+g_{\textrm{rel}}(t-i)\textrm {,}$ (19) $$

then we have the attention scores

$$ $\bm{A}_{t\textrm{,}\,i}^{l\textrm{,}\,h}=\frac{e^{\langle\bm{q}_{t}^{l\textrm{ ,}h}\textrm{,}\,\bm{k}_{i}^{l\textrm{,}h}\rangle}}{\sum_{j=1}^{t}e^{\langle\bm {q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{j}^{l\textrm{,}h}\rangle}}=\frac{e^{ \bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^{T}+g_{\textrm{rel}}(t-i)}}{\sum_ {j=1}^{t}e^{\bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^{T}+g_{\textrm{rel}}( t-j)}}=\frac{e^{g_{\textrm{rel}}(t-i)}}{\sum_{j=1}^{t}e^{g_{\textrm{rel}}(t-j) }}\textrm{.}$ (20) $$

Considering $g_{\textrm{rel}}(t-i)$ is a monotonic non-increasing function of $t-i$ and $g_{\textrm{rel}}(t-i)=\mathcal{B}-1$ when $t-i>\mathcal{D}$, then $\bm{A}_{t\textrm{,}\,1}^{l\textrm{,}\,h}=\bm{A}_{t\textrm{,}\,1}^{l\textrm{,}
\,h}=\cdots=\bm{A}_{t\textrm{,}\,t-\mathcal{D}}^{l\textrm{,}\,h}$ are the largest values. Therefore, there is no attention sink on the first token.
∎

###### Proposition 3 .

For LMs with ALiBi, there is no attention sink for $t$ repeated tokens.

###### Proof.

For LMs with ALiBi, similar to relative PE, the dot product between each query and key is

$$ $\langle\bm{q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{i}^{l\textrm{,}h}\rangle= \bm{q}_{t}^{l\textrm{,}h}{\bm{k}_{i}^{l\textrm{,}h}}^{T}+g_{\textrm{alibi}}^{h }(t-i)=\bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^{T}+g_{\textrm{alibi}}^{h} (t-i)\textrm{,}$ (21) $$

then we have the attention scores

$$ $\bm{A}_{t\textrm{,}\,i}^{l\textrm{,}\,h}=\frac{e^{\langle\bm{q}_{t}^{l\textrm{ ,}h}\textrm{,}\,\bm{k}_{i}^{l\textrm{,}h}\rangle}}{\sum_{j=1}^{t}e^{\langle\bm {q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{j}^{l\textrm{,}h}\rangle}}=\frac{e^{ \bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^{T}+g_{\textrm{alibi}}^{h}(t-i)}} {\sum_{j=1}^{t}e^{\bm{q}^{l\textrm{,}h}{\bm{k}^{l\textrm{,}h}}^{T}+g_{\textrm{ alibi}}^{h}(t-j)}}=\frac{e^{g_{\textrm{alibi}}^{h}(t-i)}}{\sum_{j=1}^{t}e^{g_{ \textrm{alibi}}^{h}(t-j)}}\textrm{.}$ (22) $$

Here $g_{\textrm{alibi}}^{h}(t-i)$ is monotonic decreasing function of $t-i$, so there is no attention sink on the first token.∎

###### Proposition 4 .

For LMs with Rotary, there is no attention sink for $t$ repeated tokens when $t$ is large if $\|\bm{q}^{l\textrm{,}h}\|\cdot\|\bm{k}^{l\textrm{,}h}\|\leq\xi$ for a constant $\xi$.

###### Proof.

For LMs with Rotary, the dot product between each query and key is

$$ $\displaystyle\langle\bm{q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{i}^{l\textrm{ ,}h}\rangle$ $\displaystyle=\bm{q}_{t}^{l\textrm{,}h}\bm{R}_{\Theta\textrm{,}\,i-t}{\bm{k}_{ i}^{l\textrm{,}h}}^{T}$ (23) $\displaystyle=\bm{q}^{l\textrm{,}h}\bm{R}_{\Theta\textrm{,}\,i-t}{\bm{k}^{l \textrm{,}h}}^{T}$ (24) $\displaystyle=\left\|\bm{q}^{l\textrm{,}h}\right\|\left\|\bm{k}^{l\textrm{,}h} \bm{R}_{\Theta\textrm{,}\,t-i}\right\|\textrm{cos}\left(\frac{\bm{q}^{l\textrm {,}h}\bm{R}_{\Theta\textrm{,}\,i-t}{\bm{k}^{l\textrm{,}h}}^{T}}{\left\|\bm{q}^ {l\textrm{,}h}\right\|\left\|\bm{k}^{l\textrm{,}h}\bm{R}_{\Theta\textrm{,}\,t- i}\right\|}\right)$ (25) $\displaystyle=\left\|\bm{q}^{l\textrm{,}h}\right\|\left\|\bm{k}^{l\textrm{,}h} \right\|\textrm{cos}(\beta_{t-i})\textrm{,}$ (26) $$

where $\beta_{j-t}$ is the angle between the rotated query and the rotated key. Then the attention scores are

$$ $\bm{A}_{t\textrm{,}\,i}^{l\textrm{,}\,h}=\frac{e^{\langle\bm{q}_{t}^{l\textrm{ ,}h}\textrm{,}\,\bm{k}_{i}^{l\textrm{,}h}\rangle}}{\sum_{j=1}^{t}e^{\langle\bm {q}_{t}^{l\textrm{,}h}\textrm{,}\,\bm{k}_{j}^{l\textrm{,}h}\rangle}}=\frac{e^{ \bm{q}^{l\textrm{,}h}\bm{R}_{\Theta\textrm{,}\,j-i}{\bm{k}^{l\textrm{,}h}}^{T} }}{\sum_{j=1}^{t}e^{\bm{q}^{l\textrm{,}h}\bm{R}_{\Theta\textrm{,}\,j-i}{\bm{k} ^{l\textrm{,}h}}^{T}}}=\frac{e^{\left\|\bm{q}^{l\textrm{,}h}\right\|\left\|\bm {k}^{l\textrm{,}h}\right\|\textrm{cos}(\beta_{t-i})}}{\sum_{j=1}^{t}e^{\left\| \bm{q}^{l\textrm{,}h}\right\|\left\|\bm{k}^{l\textrm{,}h}\right\|\textrm{cos}( \beta_{t-j})}}\textrm{.}$ (27) $$

Suppose the norm of multiplication for query and key $\left\|\bm{q}^{l\textrm{,}h}\right\|\left\|\bm{k}^{l\textrm{,}h}\right\|=\xi$. Considering $-1\leq\textrm{cos}(\beta_{t-j})\leq 1$, then we have

$$ $\displaystyle\bm{A}_{t\textrm{,}\,i}^{l\textrm{,}\,h}$ $\displaystyle=\frac{e^{\xi\textrm{cos}(\beta_{t-i})}}{\sum_{j=1}^{t}e^{\xi \textrm{cos}(\beta_{t-j})}}=\frac{1}{1+\frac{\sum_{j\neq i}e^{\xi\textrm{cos}( \beta_{t-j})}}{e^{\xi\textrm{cos}(\beta_{t-i})}}}\leq\frac{e^{2\xi}}{e^{2\xi}+ (t-1)}$ (28) $$

Then the attention scores for each token are upper-bounded and decrease to 0 0 as $t$ grows.
∎

###### Proposition 1 .

###### Proof.

###### Proposition 2 .

###### Proof.

###### Proposition 3 .

###### Proof.

###### Proposition 4 .

###### Proof.

### B.2 Attention sink under different data domains

There are 17 available data domains in the Pile dataset (Gao et al., ), including Pile-CC, PubMed Central, ArXiv, Github, FreeLaw, Stack Exchange, USPTO Backgrounds, Pubmed Abstracts, Gutenberg (PG-19), Wikipedia (en), DM Mathematics, Ubuntu IRC, EuroParl, HackerNews, PhilPapers, NIH ExPorter, and Enron Emails. We sample 100 data from each domain and then evaluate the attention sink metric for GPT2-XL/Mistral-7B/LLaMA2-7B Base/LLaMA3-8B base. As shown in Figure 9, the evaluated attention sink metrics $\textrm{Sink}_{1}^{\epsilon}$ are similar across different domains when $\epsilon=\textrm{0.2}$ and $\epsilon=\textrm{0.3}$. Small fluctuations appear when $\epsilon=\textrm{0.4}$.

Figure: Figure 9: Input domains have negligible effects on attention sink metric $\textrm{Sink}_{1}^{\epsilon}$ for (*left*) $\epsilon=\textrm{0.2}$ and (*middle*) $\epsilon=\textrm{0.3}$. There are small fluctuations for (*right*) $\epsilon=\textrm{0.4}$.
Refer to caption: x9.png

### B.3 More visualizations of internal mechanism of attention sink in LMs

$\ell_{2}$-norm. We first show that large $\ell_{2}$-norm of hidden states $\bm{h}_{1}^{l}$ and small $\ell_{2}$-norm of keys $\bm{k}_{1}^{l\textrm{,}\,h}$ and values $\bm{v}_{1}^{l\textrm{,}\,h}$ (especially for values) universally exist in open-sourced LMs, including LLaMA2-7B Base (Figure 10), GPT2-Large (Figure 11), Mistral-7B (Figure 12), and Pythia-1B (Figure 13). We also showcase our small-sized LLaMA model under the default setup in Figure 14. It is noted that for the final transformer block $l=L$, we take the hidden states before LN. We note that different LMs may have different starting blocks where massive activations appear.

Figure: Figure 10: $\ell_{2}$-norm of hidden states/keys/values of the first token/other tokens in LLaMA2-7B Base.
Refer to caption: x10.png

Figure: Figure 11: $\ell_{2}$-norm of hidden states/keys/values of the first token/other tokens in GPT2-Large.
Refer to caption: x11.png

Figure: Figure 12: $\ell_{2}$-norm of hidden states/keys/values of the first token/other tokens in Mistral-7B.
Refer to caption: x12.png

Figure: Figure 13: $\ell_{2}$-norm of hidden states/keys/values of the first token/other tokens in Pythia-1B.
Refer to caption: x13.png

Figure: Figure 14: $\ell_{2}$-norm of hidden states/keys/values of the first token/other tokens in our small LLaMA model.
Refer to caption: x14.png

QK angles. Then we further demonstrate that QK angles contribute to attention sink through more visualizations, including LLaMA3-8B Base (Figure 15), LLaMA2-7B Base (Figure 16), Mistral-7B (Figure 17), and GPT2-Large (Figure 18).

Figure: Figure 15: Cosine similarity and $\ell_{2}$-norm product between keys and queries in LLaMA3-8B Base.
Refer to caption: x15.png

Figure: Figure 16: Cosine similarity and $\ell_{2}$-norm product between keys and queries in LLaMA2-7B Base.
Refer to caption: x16.png

Figure: Figure 17: Cosine similarity and $\ell_{2}$-norm product between keys and queries in Mistral-7B.
Refer to caption: x17.png

Figure: Figure 18: Cosine similarity and $\ell_{2}$-norm product between keys and queries in GPT2-Large.
Refer to caption: x18.png

Block-wise and head-wise property. In the main paper, we mainly discuss the ratio of heads that have attention sink in the definition of attention sink metric $\textrm{Sink}_{k}^{\epsilon}$. Here we visualize the locations of these attention sink heads in open-sourced LMs, including LLaMA2 family (Figure 19), LLaMA3/LLaMA3.1 family (Figure 20), Mistral family (Figure 21), GPT2 family (Figure 22), Pythia family (Figure 23), and OPT family (Figure 24). We visualize the distributions of importance scores for the first token $\alpha_{1}^{l\textrm{,}\,h}$ across different transformer blocks $1\leq l\leq L$ and different heads $1\leq h\leq H$ before computing the attention sink metric. We find that (1) different pre-trained LMs have various attention sink distributions but they tend to have less obvious attention sink in earlier transformer blocks; (2) instruction tuning does not significantly modify such attention sink distributions when comparing base versions and chat/instruct versions.

Figure: Figure 19: Distribution of importance scores for the first token across different blocks and heads in the LLaMA2 family.
Refer to caption: x19.png

Figure: Figure 20: Distribution of importance scores for the first token across different blocks and heads in the LLaMA3/LLaMA3.1 family.
Refer to caption: x20.png

Figure: Figure 21: Distribution of importance scores for the first token across different blocks and heads in the Mistral family.
Refer to caption: x21.png

Figure: Figure 22: Distribution of importance scores for the first token across different blocks and heads in the GPT2 family.
Refer to caption: x22.png

Figure: Figure 23: Distribution of importance scores for the first token across different blocks and heads in the Pythia family.
Refer to caption: x23.png

Figure: Figure 24: Distribution of importance scores for the first token across different blocks and heads in the OPT family.
Refer to caption: x24.png

### B.4 Huggingface links for open-sourced LMs

**Table 7: Huggingface links for open-sourced LMs we used in this paper.**
| Model | Huggingface link |
| --- | --- |
| LLaMA2-7B Base | [meta-llama/Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf) |
| LLaMA2-7B Chat | [meta-llama/Llama-2-7b-chat-hf](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf) |
| LLaMA2-13B Base | [meta-llama/Llama-2-13b-hf](https://huggingface.co/meta-llama/Llama-2-13b-hf) |
| LLaMA2-13B Chat | [meta-llama/Llama-2-13b-chat-hf](https://huggingface.co/meta-llama/Llama-2-13b-chat-hf) |
| LLaMA3-8B Base | [meta-llama/Meta-Llama-3-8B](https://huggingface.co/meta-llama/Meta-Llama-3-8B) |
| LLaMA3-8B Instruct | [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) |
| LLaMA3.1-8B Base | [meta-llama/Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B) |
| LLaMA3.1-8B Instruct | [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct) |
| GPT2 | [openai-community/gpt2](https://huggingface.co/openai-community/gpt2) |
| GPT2-Medium | [openai-community/gpt2-medium](https://huggingface.co/openai-community/gpt2-medium) |
| GPT2-Large | [openai-community/gpt2-large](https://huggingface.co/openai-community/gpt2-large) |
| GPT2-XL | [openai-community/gpt2-xl](https://huggingface.co/openai-community/gpt2-xl) |
| Mistral-7B | [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) |
| Mistral-7B Instruct | [mistralai/Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1) |
| Pythia-14M | [EleutherAI/pythia-14m](https://huggingface.co/EleutherAI/pythia-14m) |
| Pythia-31M | [EleutherAI/pythia-31m](https://huggingface.co/EleutherAI/pythia-31m) |
| Pythia-70M | [EleutherAI/pythia-70m](https://huggingface.co/EleutherAI/pythia-70m) |
| Pythia-160M | [EleutherAI/pythia-160m](https://huggingface.co/EleutherAI/pythia-160m) |
| Pythia-410M | [EleutherAI/pythia-410m](https://huggingface.co/EleutherAI/pythia-410m) |
| Pythia-1B | [EleutherAI/pythia-1b](https://huggingface.co/EleutherAI/pythia-1b) |
| Pythia-1.4B | [EleutherAI/pythia-1.4b](https://huggingface.co/EleutherAI/pythia-1.4b) |
| Pythia-2.8B | [EleutherAI/pythia-2.8b](https://huggingface.co/EleutherAI/pythia-2.8b) |
| Pythia-6.9B | [EleutherAI/pythia-6.9b](https://huggingface.co/EleutherAI/pythia-6.9b) |
| Pythia-12B | [EleutherAI/pythia-12b](https://huggingface.co/EleutherAI/pythia-12b) |
| OPT-125M | [facebook/opt-125m](https://huggingface.co/facebook/opt-125m) |
| OPT-350M | [facebook/opt-350m](https://huggingface.co/facebook/opt-350m) |
| OPT-1.3B | [facebook/opt-1.3b](https://huggingface.co/facebook/opt-1.3b) |
| OPT-2.7B | [facebook/opt-2.7b](https://huggingface.co/facebook/opt-2.7b) |
| OPT-6.7B | [facebook/opt-6.7b](https://huggingface.co/facebook/opt-6.7b) |
| OPT-13B | [facebook/opt-13b](https://huggingface.co/facebook/opt-13b) |

## Appendix C More experiments in LM pre-training

### C.1 Optimization

Batch size. During the pre-training, we consider different batch sizes with other hyper-parameters fixed. As shown in Table 8(*Left*), batch size does not affect the emergence of attention sink.

### C.2 Data distribution

Fixing token in a specific position. During the pre-training, we consider fixing the token $\bm{x}_{\textrm{fix}}$ in the first/second/third position. Consequently, when evaluating the attention sink metric, in Table 8(*Right*), we find that attention sink appears in the appears in the fixed token instead of the first token.

**Table 8: (*Left*) Batch size has no effect on the emergence of attention sink. (*Right*) Attention sink appears in the appears in the fixed token instead of the first token.**
| Batch size | 0.25M | 0.5M | 1M | 2M |
| --- | --- | --- | --- | --- |
| $\textrm{Sink}_{1}^{\epsilon}$(%) | 16.45 | 17.19 | 18.18 | 16.19 |
| valid loss | 3.92 | 3.78 | 3.73 | 3.68 |

### C.3 FFN design

Activation functions. Since FFN in the earlier transformer block blasts off the $\ell_{2}$-norm of the first token, we are wondering whether the choices of activation functions in FFN will affect the attention sink. Besides the SwiGLU activations used in our default setup, we also consider other activation functions, as present in Table 9. We observe that different FFN designs do not affect the emergence of attention sink.

**Table 9: Modifying the activation functions in FFN does not affect the emergence of attention sink.**
| Activation functions | $\bm{F}$ | $\textrm{Sink}_{1}^{\epsilon}$(%) | valid loss |
| --- | --- | --- | --- |
| ReLU | $\textrm{ReLU}(\bm{h}\bm{W}_{1})\bm{W}_{2}$ | 16.90 | 3.82 |
| GeLU (Hendrycks & Gimpel, ) | $\textrm{GeLU}(\bm{h}\bm{W}_{1})\bm{W}_{2}$ | 14.76 | 3.79 |
| Swish (Ramachandran et al., ) | $\textrm{Swish}(\bm{h}\bm{W}_{1})\bm{W}_{2}$ | 17.89 | 3.80 |
| ReGLU (Shazeer, ) | $\left(\textrm{ReLU}(\bm{h}\bm{W}_{1})\odot\bm{h}\bm{W}_{2}\right)\bm{W}_{3}$ | 13.88 | 3.75 |
| GeGLU (Shazeer, ) | $\left(\textrm{GeLU}(\bm{h}\bm{W}_{1})\odot\bm{h}\bm{W}_{2}\right)\bm{W}_{3}$ | 17.86 | 3.73 |
| SwiGLU (Shazeer, ) | $\left(\textrm{Swish}(\bm{h}\bm{W}_{1})\odot\bm{h}\bm{W}_{2}\right)\bm{W}_{3}$ | 18.18 | 3.73 |

### C.4 Attention design

Multi-head design in attention. We consider two perspectives in multi-head design in attention. Firstly, we explore whether the number of heads has an impact on attention sink, especially for $H=\textrm{1}$, which refers to single-head self-attention. Second, attention output from each head is concatenated: $\bm{O}^{l}=\textrm{Concat}_{h=1}^{H}\left(\bm{A}^{l\textrm{,}h}\bm{V}^{l
\textrm{,}h}\right)\bm{W}_{O}^{l}$. We replace such concatenation operation with addition operation: $\bm{O}^{l}=\sum_{h=1}^{H}\left(\bm{A}^{l\textrm{,}h}\bm{V}^{l\textrm{,}h}
\right)\bm{W}_{O}^{l}$. As shown in Table 10(*Left*), multi-head design does not affect the emergence of attention sink.

**Table 10: (*Left*) Modifying multi-head design does not affect the emergence of attention sink. (*Right*) Sharing KV biases across heads in each block results in attention sink shifting back to the first token from K biases.**
| Multi-head | $\textrm{Sink}_{1}^{\epsilon}$ (%) | valid loss |
| --- | --- | --- |
| $H=\textrm{8}$ | 18.18 | 3.73 |
| $H=\textrm{4}$ | 10.68 | 3.74 |
| $H=\textrm{2}$ | 12.95 | 3.76 |
| $H=\textrm{1}$ | 19.50 | 3.78 |
| addition | 21.76 | 3.74 |

Head-sharing K/KV biases in attention. In the main paper, we consider both KV biases and V biases in attention. These biases are not shared by different heads in each block. We further explore whether head-sharing patterns will affect their functionality. As present in Table 10(*Right*), LMs with KV biases are more likely affected by the head-sharing pattern: attention sink shifts from the K biases to the first token. While LMs with K biases are less affected.

Scaling the normalization in softmax attention. Before our experiments about replacing softmax attention, we first explore the effects of normalization scales in softmax attention. In the main paper, the attention output for the $i$-th output is

$$ $\bm{v}_{i}^{\dagger}=\sum_{j=1}^{i}\frac{\textrm{sim}(\varphi(\bm{q}_{i}) \textrm{,}\,\varphi(\bm{k}_{j}))}{\sum_{j^{\prime}=1}^{i}\textrm{sim}(\varphi( \bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j^{\prime}}))}\bm{v}_{j}=\sum_{j=1}^{i} \frac{\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j}))}{\bm{Z} _{i}}\bm{v}_{j}\textrm{.}$ (29) $$

We consider a scale factor $\alpha$, the normalization term is $\bm{Z}_{i}=\frac{1}{\alpha}\sum_{j^{\prime}=1}^{i}\textrm{sim}(\varphi(\bm{q}_
{i})\textrm{,}\,\varphi(\bm{k}_{j}))$, and then the attention score are sum up to $\alpha$. For default setup, $\alpha=\textrm{1}$. As shown in Table 11(*Left*), with a smaller normalization scale, attention sink tends to appear in fewer heads. From another perspective,

$$ $\bm{v}_{i}^{\dagger}=\sum_{j=1}^{i}\frac{\alpha\textrm{sim}(\varphi(\bm{q}_{i} )\textrm{,}\,\varphi(\bm{k}_{j}))}{\sum_{j^{\prime}=1}^{i}\textrm{sim}(\varphi (\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j^{\prime}}))}\bm{v}_{j}=\sum_{j=1}^{i }\frac{\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j}))}{\sum_ {j^{\prime}=1}^{i}\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{ j^{\prime}}))}\bm{h}_{j}(\alpha\bm{W}_{V})\textrm{,}$ (30) $$

$$ $\bm{o}_{i}^{\prime}=\textrm{Concat}_{h=1}^{H}(\bm{v}_{i}^{{}^{\prime}h})\bm{W} _{O}\textrm{.}$ (31) $$

Therefore, this normalization scale can be regarded as the scale for $\bm{W}_{V}$ or $\bm{W}_{O}$. We show that this normalization scaling could be implemented by scaling learning rates and initialization. We use the $s$ to represent the optimization step, and $s=\textrm{0}$ refers to the initialization. When scaling the normalization, we have the following update rule (take $\bm{W}_{O}$ for example):

$$ $\displaystyle\bm{W}_{O}^{s+1}$ $\displaystyle=\bm{W}_{O}^{s}-\eta\nabla\mathcal{L}(\alpha\bm{W}_{O}^{s})$ (32) $\displaystyle=\bm{W}_{O}^{s}-\alpha\eta\nabla\mathcal{L}(\bm{W})|_{\bm{W}= \alpha\bm{W}_{O}^{s}}\textrm{,}$ (33) $$

where $\eta$ is the original learning rate. Suppose we only modify the learning rate and initialization, to ensure each optimization step $\hat{\bm{W}}_{O}^{s}=\bm{W}_{O}^{s}$, we need to first ensure $\hat{\bm{W}}_{O}^{0}=\alpha\bm{W}_{O}^{0}$. Suppose that we have $\hat{\bm{W}}_{O}^{s}=\bm{W}_{O}^{s}$, then the update rule is:

$$ $\displaystyle\hat{\bm{W}}_{O}^{s+1}$ $\displaystyle=\hat{\bm{W}}_{O}^{s}-\eta^{\prime}\nabla\mathcal{L}(\hat{\bm{W}} _{O}^{s})$ (34) $\displaystyle=\alpha\bm{W}_{O}^{s}-\eta^{\prime}\nabla\mathcal{L}(\bm{W})|_{ \bm{W}=\alpha\bm{W}_{O}^{s}}\textrm{,}$ (35) $$

To ensure $\hat{\bm{W}}_{O}^{s+1}=\bm{W}_{O}^{s+1}$, we need the new learning rate $\eta^{\prime}$ meets $\eta^{\prime}=\alpha^{2}\eta$.

**Table 11: (*Left*) Scaling the normalization in Softmax attention to less than one can mitigate attention sink but not prevent its emergence. (*Right*) LMs with sigmoid attention (without sigmoid attention) trained by different learning rates and weight decay ratios have no attention sink.**
| Scale $\alpha$ | $\textrm{Sink}_{1}^{\epsilon}$(%) | valid loss |
| --- | --- | --- |
| 2.0 | 29.10 | 3.72 |
| 1.0 | 18.18 | 3.73 |
| 0.2 | 9.41 | 3.72 |
| 0.1 | 3.59 | 3.76 |
| 0.02 | 4.53 | 3.78 |

Attention operations. Firstly, we present all attempted attention operations in Table 12. It is noted that several setups lead to training failure. For LMs with sigmoid attention without normalization, we vary the learning rates or weight decay ratios $\gamma$. Consequently, as shown in Table 11(*Right*), the trained LMs still have no attention sink, which further confirms our conclusion in the main paper.

**Table 12: Normalization and selections of kernels in attention significantly affect the emergence of the attention sink. We use “*” to mark that the metric $\textrm{Sink}_{1}^{\epsilon}$ is computed by proxy attention scores. We use “-” to represent the training failure under the setup.**
| $\textrm{sim}(\varphi(\bm{q}_{i})\textrm{,}\,\varphi(\bm{k}_{j}))$ | $\bm{Z}_{i}$ | $\textrm{Sink}_{1}^{\epsilon}$(%) | valid loss |
| --- | --- | --- | --- |
| $\textrm{exp}(\frac{\bm{q}_{i}^{T}\bm{k}_{j}}{\sqrt{d_{h}}})$ | $\sum_{j^{\prime}=1}^{i}\textrm{exp}(\frac{\bm{q}_{i}\bm{k}_{j^{\prime}}^{T}}{<br>\sqrt{d_{h}}})$ | 18.18 | 3.73 |
| $\textrm{sigmoid}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})$ | $1$ | 0.44^∗ | 3.70 |
| $\textrm{sigmoid}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})$ | $\sum_{j^{\prime}=1}^{i}\textrm{sigmoid}(\frac{\bm{q}_{i}\bm{k}_{j^{\prime}}^{T<br>}}{\sqrt{d_{h}}})$ | 30.24 | 3.74 |
| $\textrm{elu}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})+1$ | $1$ | 0.80^∗ | 3.69 |
| $\textrm{elu}(\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}})+1$ | $\sum_{j^{\prime}=1}^{i}\textrm{elu}(\frac{\bm{q}_{i}\bm{k}_{j^{\prime}}^{T}}{<br>\sqrt{d_{h}}})+1$ | - | - |
| $\frac{(\textrm{elu}(\bm{q}_{i})+1)(\textrm{elu}(\bm{k}_{j})+1)^{T}}{\sqrt{d_{h<br>}}}$ | $\sum_{j^{\prime}=1}^{i}\frac{(\textrm{elu}(\bm{q}_{i})+1)(\textrm{elu}(\bm{k}_<br>{j^{\prime}})+1)^{T}}{\sqrt{d_{h}}}$ | 53.65^∗ | 4.19 |
| $\frac{(\textrm{elu}(\bm{q}_{i})+1)(\textrm{elu}(\bm{k}_{j})+1)^{T}}{\sqrt{d_{h<br>}}}$ | $1$ | - | - |
| $\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}}$ | $\textrm{max}\left(\left|\sum_{j^{\prime}=1}^{i}\frac{\bm{q}_{i}\bm{k}_{j^{<br>\prime}}^{T}}{\sqrt{d_{h}}}\right|\textrm{,}\,1\right)$ | - | - |
| $\frac{\bm{q}_{i}\bm{k}_{j}^{T}}{\sqrt{d_{h}}}$ | $1$ | 0.00^∗ | 3.99 |
| $\frac{\textrm{mlp}(\bm{q}_{i})\textrm{mlp}(\bm{k}_{j})^{T}}{\sqrt{d_{h}}}$ | $\textrm{max}\left(\left|\sum_{j^{\prime}=1}^{i}\frac{\textrm{mlp}(\bm{q}_{i})<br>\textrm{mlp}(\bm{k}_{j^{\prime}})^{T}}{\sqrt{d_{h}}}\right|\textrm{,}\,1\right)$ | 0.19^∗ | 3.85 |
| $\frac{\textrm{mlp}(\bm{q}_{i})\textrm{mlp}(\bm{k}_{j})^{T}}{\sqrt{d_{h}}}$ | $1$ | 0.74^∗ | 3.91 |

## Peer Reviews

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: - How to identify the token where attention-sink occurs? How to determine those locations?
soundness: 4
strengths: - The paper provides a thorough investigation into the attention sink phenomenon, covering various factors that influence its emergence in LMs.
- The findings have practical applications in areas such as streaming/long context generation, KV cache optimization, and model quantization.
- The study considers various model architectures, optimizers, and data distributions, offering a broad perspective on the attention sink phenomenon.
summary: The paper investigates the phenomenon of attention sink in LMs, where significant attention is allocated to the first token regardless of its semantic importance. Key findings include the correlation of the sink position with the loss function and data distribution, and the behavior of attention sink as key biases storing extra attention without contributing to value computation. The paper also shows that attention sinks do not emerge when softmax attention is replaced with other operations like sigmoid attention without normalization, up to 1B parameters.
weaknesses: - The study notes that attention sink disappears with less training data, suggesting that the models might be overfitting to certain aspects of the training data. It seems that these two factors cannot be decoupled, and it is impossible to explain whether it is over-fit or the amount of data that affects attention-sink.
- The study claims that it focuses on the Language Models. However, this work pay more attention on auto-regressive LMs and may not capture the nuances of other types of encoder-like LMs or Jamba. Does those architecture can solve the attention-sink phenomenon?

---

confidence: 4
contribution: 3
initial_rating: 8
presentation: 4
questions: Q1: In Fig. 4 (left), could you provide a performance curve, such as the validation performance of each model against model size? It appears that as the model becomes stronger, attention sink becomes more prominent. Additionally, I am curious about how attention sink correlates with validation loss.

Q2: Fig. 4 (right) shows that a lower learning rate results in a slower increase in attention sink. Is it possible that attention sink occurs simply because the model has not been well-tuned?

Q3: In Table 1, GPT-XL behaves very differently from Llama and Mistral. Do you have any intuition as to why this might be?

Q4: Could you provide some mathematical formulation on how the attention variants (2nd to 4th rows in Table 4) are correlated? Is there an inherent connection among these attention variants that excludes attention sink?

Q5: In Table 6, it appears that the normalizer may impact attention sink. Do you have additional evidence with other types of normalizers?
soundness: 4
strengths: 1. The perspectives of studying attention sink problem is diverse and well-motivated. These perspectives are also inspiring to future studies on attention mechanisms.
2. The experiments is very comprehensive and diverse.
summary: In this paper, the authors conduct a comprehensive study of the attention sink problem and present robust empirical results. They discuss and examine the attention sink problem from various perspectives, including optimization, data distribution, loss function, and model architecture. Although the paper does not provide in-depth theoretical analysis, it may inspire further research into the understanding of the attention mechanism, which could, in turn, contribute to the development of stronger generative models. Therefore, I believe this paper would serve as a valuable empirical reference on the attention sink problem for the community and worths of acceptance.
weaknesses: The primary weakness of this paper is the lack of in-depth analysis. The empirical results come across more as observations rather than as thorough investigations. Including more theoretical analysis or deeper experimental work would strengthen the paper. For instance, in the KV bias section, it would be beneficial to explore how attention variants with and without attention sink are related in formulation.

---

confidence: 5
contribution: 4
initial_rating: 8
presentation: 3
questions: In your paper you study how to mitigate the attention sink, are you sure that we want to mitigate it?
soundness: 4
strengths: - Reproducibily.
- The paper is well written and the experiments set up is soild.
- The paper not only observes the presence of attention sinks but also delves into the mechanistic reasons behind their emergence (also providing insights on the training dynamics that foster attention sinks).
- The paper show that attention sinks persist across various input types, like random token sequences and repeated tokens.

I think that this paper is a valuable step further in understanding the phenomenon of attention sink.
summary: This paper studies the phenomenon of "attention sink" in Language Models, where significant attention is disproportionately allocated to the first token in input sequences, without taking into account its semantic importance. The attention sink has practical applications in areas such as streaming generation, KV cache optimization, inference acceleration, and model quantization. 

The authors performed a study across various LM architectures, input types, and training configurations to study the emergence and characteristics of attention sinks.
They found that attention sink happens across different LMs, including smaller models and those trained on random token sequences and that it emerges during optimization with sufficient training data, and its prominence is influenced by learning rates and weight decay.
They also found that attention sink functions similarly to key biases, storing additional attention scores that are largely non-informative and do not contribute to value computations. This behavior is partially attributed to the softmax normalization, which induces inner dependencies among attention scores.

The paper also shows that altering the attention mechanism, such as replacing softmax with sigmoid attention without normalization, can prevent the emergence of attention sinks in LMs up to 1 billion parameters.
weaknesses: - The paper doesn't really take into account the role of attention sink impact on downstream tasks.
- While the paper studies the emergence and immediate characteristics of attention sinks, it does not assess the long-term impacts of attention sinks on model behavior (like stability during fine-tuning, adaptability to new tasks, or resistance to adversarial attacks).

Not really a weakness, but i found the paper a bit difficoult to read because of the unusual aesthetic choices: i think that this style would be great for a blog post where you have more space available to write, but i personally find easier to follow simpler-looking papers.

Meta-review: This paper explores the phenomenon of attention sink in language models (LMs). Attention sink describes how, in autoregressive Transformer-based LMs, a disproportionate amount of attention often gets allocated to the first token in the sequence, regardless of its semantic importance. The authors provide extensive empirical evidence that attention sink arises across model sizes and architectures, and sufficient training data and high learning rates facilitate the emergence of attention sink. The author also showed the root of attention sink is from softmax, which can be greatly prevented by other attention variants (e.g., sigmoid attention).

**Strengths** (1) All reviewers agree on the paper's breadth of experiments across various training conditions, architectures and hyperparameters. (2) Understanding how attention sink works is also crucial for various LLM applications

**Weaknesses** (1) One recurring critique is that certain parts of the study feel more like empirical observations. A mathematical explanation for why specific attention variants eliminate attention sink would be preferred; (2) The reviewers would like to see more evidence on whether attention sink harms or helps real downstream performance. 

**Decision** The paper’s strengths, in particular its extensive empirical scope, practical insights, and potential impact, makes it a clear acceptance.

Decision: Accept (Spotlight)