DL0075 Attention Sink

What is an attention sink, and why do models attend to the first token so heavily?

Answer

An attention sink is a token that a head dumps its attention mass onto when it has nothing relevant to retrieve, and in decoder-only LLMs that token is almost always the first one in the sequence (often the BOS token). Measured on a trained model, a middle-layer head can place well over half of its probability on that single position even though its value vector carries almost no task-relevant content. The cause is structural rather than semantic: softmax normalizes every attention row to sum to exactly 1, so a head has no way to say “attend to nothing” and must put the leftover mass somewhere. Causal masking makes the first token the only key visible from every query position, and it is the one token whose representation is not yet mixed with context, so training converges on it as the default no-op target. The model then reinforces the arrangement by growing massive activations and unusually large key norms at that position, which is why the sink shows up as an outlier in both attention maps and activation histograms.

(1) Softmax Has No No-Op: the row constraint \sum_j \alpha_{ij} = 1 means an idle head still emits a full distribution, so the mass must land on some low-cost token.
(2) Why The First Token Wins: under causal masking it is the only key every query can see, and it precedes all content, so it is both universally available and information-free, the ideal dumping ground.
(3) The Sink Is Load-Bearing: it is not decorative; drop the first token from a sliding-window KV cache and perplexity jumps by one to two orders of magnitude, because every head loses its default target and redistributes mass onto real tokens.
(4) Fingerprints Beyond Attention: the same position carries hidden-state outliers that widen activation ranges, which is a known headache for per-tensor quantization; vision transformers show the analogous effect by repurposing background patches as sinks.

Log-scale bar chart of attention mass by key position for one head at query position 512: token 0 receives 0.42, tokens 1 to 3 receive 0.06, 0.03 and 0.02, three middle bins receive 0.07, 0.06 and 0.09, and the most recent 64 positions receive 0.25

Figure 1: Illustrative single head at query position 512: the first token absorbs 0.42 of the mass, the most recent 64 positions share 0.25, and the roughly 444 middle positions split only 0.22, about 5\times 10^{-4} each.

The cleanest way to read the sink is as a learned bias term smuggled into the softmax. Because the denominator sums over all visible keys, the only way for a head to shrink the weight it gives to real tokens is to inflate the score of some other key; the first token, whose value vector contributes near-zero to the output, is that escape valve. This also explains the standard fixes. Giving the softmax an explicit extra term in the denominator (the off-by-one softmax, or a learned per-head sink logit as used in some recent open-weight models such as OpenAI’s gpt-oss) lets attention rows sum to less than 1, so no real token needs to be sacrificed. Prepending dedicated register tokens achieves the same thing with ordinary softmax by supplying a scratch position, which is what cleaned up the noisy attention maps in vision transformers. Both changes must be present during pretraining: retrofitting them onto a model that already routes mass through token 0 changes the normalization the weights were trained under.

Mathematical Formulation:
s_{ij} = \frac{q_i^{\top} k_j}{\sqrt{d_k}}
\alpha_{ij} = \frac{\exp(s_{ij})}{\sum_{m=1}^{i} \exp(s_{im})}
\sum_{j=1}^{i} \alpha_{ij} = 1
\tilde{\alpha}_{ij} = \frac{\exp(s_{ij})}{\exp(b_h) + \sum_{m=1}^{i} \exp(s_{im})}

Where:

  • s_{ij} is the scaled dot-product score between query q_i and key k_j, with head dimension d_k.
  • \alpha_{ij} is the attention weight; i indexes query positions and j, m index key positions, restricted to m \leq i by causal masking, which is why j = 1 is the only key shared by every query.
  • The third line is the normalization constraint that creates the sink: no configuration of scores lets a head emit less than one unit of total mass.
  • b_h is a learned per-head sink logit added to the denominator, so \sum_j \tilde{\alpha}_{ij} can fall below 1; the off-by-one softmax is the special case b_h = 0, since \exp(0) = 1.
Log-scale perplexity versus tokens streamed for three attention policies: dense attention rises past the 4096-token pretraining length, sliding-window attention jumps from about 10 to nearly 400 once the first token is evicted at 1024 tokens, and a window that retains 4 sink tokens stays flat near 10.5

Figure 2: Illustrative streaming behavior: a plain sliding window collapses the moment the first token leaves the KV cache, while retaining a handful of sink tokens alongside the window keeps perplexity flat far beyond the pretraining length.

ApproachWhat It ChangesTraining CostWhen to Reach for It
Dense AttentionNothing; the sink stays at token 0 and is never evictedNoneShort contexts where the full KV cache fits
Keep First k Tokens (StreamingLLM)Cache policy only: pin the first 4 tokens plus a sliding windowNone, works on an already-trained modelStreaming or long-running serving with a fixed cache budget
Register or Sink TokensPrepends learnable scratch tokens that heads can dump ontoPretraining or substantial fine-tuningNew models, and ViTs whose attention maps must stay interpretable
Learned Sink Logit / Softmax Off-by-OneExtra denominator term so a row can sum to less than 1Must be present from pretrainingNew architectures, especially where activation outliers hurt quantization

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *