跳过主要内容
CookLLM logoCookLLM 文档

Attention Sink

会员专享

第一个 token 为什么吸走绝大部分注意力,这一现象的机制、代价,以及为何消除它要留到 Gated Attention

在权益中心获取代码

GQA 之后还剩下的问题

上一章我们看到 GQA 把 KV cache 压到 MHA 的 1/4,代价是部分任务上略有质量下降。但 GQA 改的是 KV head 的数量,没有动 attention 本身的数学结构:还是 softmax,还是 causal mask,还是 QKT/dQK^T / \sqrt{d}。

如果换一个角度,绕过 KV cache,只盯着 attention 权重看,会发现一个跟 head 数、跟 group 数都无关的现象:推理时,绝大部分注意力都流向第一个 token。

这就是 Attention Sink。本章我们在 Qwen3-0.6B 上把它从头看到尾;而从机制上看,只要 attention 还是 softmax + causal 的组合,它就会出现。

Schematic: what an attention sink looks like
key j (attended position) →query t (attending) ↓012345678012345678sinkattention weighthighlow

Each row is a query, each column a key; under the causal mask a query only sees itself and the keys to its left (dashed cells are masked out). Notice column 0: almost every query puts most of its attention weight there, forming a vertical bright stripe across all queries. That stripe is the attention sink.

本章回答三个问题:

  1. 这个现象长什么样,数据上有多极端?
  2. 它为什么必然出现?
  3. 它给系统留下什么代价?

登录以继续阅读

这是一篇付费内容,请登录您的账户以访问完整内容。