Table of Contents
Fetching ...

Why do LLMs attend to the first token?

Federico Barbero, Álvaro Arroyo, Xiangming Gu, Christos Perivolaropoulos, Michael Bronstein, Petar Veličković, Razvan Pascanu

TL;DR

This paper investigates why LLMs develop attention sinks at the first token, arguing that sinks help prevent over-mixing and information collapse in deep, long-context Transformers. It blends theory—linking rank collapse, representational collapse, and over-squashing with Jacobian-based bounds—with extensive empirical validation on Gemma 7B and the LLaMa 3.1 family, including data-packing and pretraining context-length manipulations. Key findings show sinks slow perturbation spread, grow stronger with model size and context length, and depend on pretraining packing strategies; removing BOS-induced sinks at inference degrades long-context performance. The work offers a practical lens on attention patterns, guiding pretraining choices and prompting further exploration of robust, long-context transformer architectures.

Abstract

Large Language Models (LLMs) tend to attend heavily to the first token in the sequence -- creating a so-called attention sink. Many works have studied this phenomenon in detail, proposing various ways to either leverage or alleviate it. Attention sinks have been connected to quantisation difficulties, security issues, and streaming attention. Yet, while many works have provided conditions in which they occur or not, a critical question remains shallowly answered: Why do LLMs learn such patterns and how are they being used? In this work, we argue theoretically and empirically that this mechanism provides a method for LLMs to avoid over-mixing, connecting this to existing lines of work that study mathematically how information propagates in Transformers. We conduct experiments to validate our theoretical intuitions and show how choices such as context length, depth, and data packing influence the sink behaviour. We hope that this study provides a new practical perspective on why attention sinks are useful in LLMs, leading to a better understanding of the attention patterns that form during training.

Why do LLMs attend to the first token?

TL;DR

This paper investigates why LLMs develop attention sinks at the first token, arguing that sinks help prevent over-mixing and information collapse in deep, long-context Transformers. It blends theory—linking rank collapse, representational collapse, and over-squashing with Jacobian-based bounds—with extensive empirical validation on Gemma 7B and the LLaMa 3.1 family, including data-packing and pretraining context-length manipulations. Key findings show sinks slow perturbation spread, grow stronger with model size and context length, and depend on pretraining packing strategies; removing BOS-induced sinks at inference degrades long-context performance. The work offers a practical lens on attention patterns, guiding pretraining choices and prompting further exploration of robust, long-context transformer architectures.

Abstract

Large Language Models (LLMs) tend to attend heavily to the first token in the sequence -- creating a so-called attention sink. Many works have studied this phenomenon in detail, proposing various ways to either leverage or alleviate it. Attention sinks have been connected to quantisation difficulties, security issues, and streaming attention. Yet, while many works have provided conditions in which they occur or not, a critical question remains shallowly answered: Why do LLMs learn such patterns and how are they being used? In this work, we argue theoretically and empirically that this mechanism provides a method for LLMs to avoid over-mixing, connecting this to existing lines of work that study mathematically how information propagates in Transformers. We conduct experiments to validate our theoretical intuitions and show how choices such as context length, depth, and data packing influence the sink behaviour. We hope that this study provides a new practical perspective on why attention sinks are useful in LLMs, leading to a better understanding of the attention patterns that form during training.

Paper Structure

This paper contains 28 sections, 2 theorems, 15 equations, 10 figures, 3 tables.

Key Result

Proposition 3.1

If $\|\mathbf{V}^{(L)} - \frac{1}{n}\mathbf{1}\mathbf{1}^\top\mathbf{V}^{(L)}\|_F < \Delta / 2,$ then $\|\mathbf{v}_n^{(L)} - \mathbf{v}_{n-1}^{(L)}\|_2 < \Delta.$

Figures (10)

  • Figure 1: Our key result is to illustrate how attention sinks are usefully leveraged by decoder-only Transformers. The presence of attention sinks slows down the mixing of information between tokens and hence makes Transformers more robust to perturbations of prompts. To illustrate this, we demonstrate how sharply a perturbation in the second token's input representation (in red) affects the embeddings of other tokens throughout the model, both without ( left) and with ( right) a sink token (e.g. $\langle\text{bos}\rangle$). The presence of a sink draws attention away from the rest of the tokens, limiting the spread of perturbed information and resulting in more stable embeddings. See Figure \ref{['fig:perturbation']} for a direct measurement in Gemma 7B.
  • Figure 2: Effect of token perturbations on Gemma 7B. Left/Right: With/without $\langle\text{bos}\rangle$.
  • Figure 3: Attention patterns of four heads in Gemma 7B. Top/Bottom: With/without $\langle\text{bos}\rangle$.
  • Figure 4: Apostrophe head attention pattern (a) and value norms (b). This attention head is a real-world example of the theoretically studied Bigram-Backcopy task from guo2024active.
  • Figure 5: Pre-trained model Sink Metric (%) after training (a) and during training (b) trained at different context lengths.
  • ...and 5 more figures

Theorems & Definitions (4)

  • Proposition 3.1: Rank collapse implies representational collapse.
  • Theorem 3.2: More detailed over-squashing bounds.
  • proof
  • proof