Files
myWiki/concepts/softmax-off-by-one.md

56 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "SoftMax-off-by-One"
created: 2026-05-14
updated: 2026-05-14
type: concept
tags: [attention, softmax, llm, streaming]
sources: ["https://arxiv.org/abs/2309.17453"]
---
# SoftMax-off-by-One
## 定义
SoftMax-off-by-OneSoftMax₁是 Miller (2023) 提出的 SoftMax 变体,在分母中加 1使模型不必将注意力分数分配到不相关的 Token 上:
$$\text{SoftMax}_1(x)_i = \frac{e^{x_i}}{1 + \sum_{j=1}^N e^{x_j}}$$
## 动机
标准 SoftMax 强制 $\sum_i \text{SoftMax}(x)_i = 1$,这意味着即使所有上下文 Token 都与当前 query 不相关,模型也必须分配注意力值——导致了 [[attention-sinks|注意力汇]] 现象。
SoftMax₁ 允许模型将多余的注意力"丢弃"到分母的 +1 项中,理论上消除对注意力汇的需求。
## 等价表示
SoftMax₁ 在注意力计算中等价于**前置一个全零 Key 和 Value 的虚拟 Token**
$$\text{Attention}(Q, K, V) = \text{SoftMax}_1(QK^T)V = \text{SoftMax}(\tilde{Q}\tilde{K}^T)\tilde{V}$$
其中 $\tilde{K} = [0, K]$, $\tilde{V} = [0, V]$。
这在 [[streaming-llm|StreamingLLM]] 论文中被称为 **Zero Sink**
## 实验评估
Xiao et al. (2024) 的预训练实验表明:
- Zero Sink (SoftMax₁) **部分改善**了注意力汇问题
- 但模型**仍然依赖其他初始 Token** 作为注意力汇
- 仅 Sink Token 时 PPL = 29,214远差于 Learnable Sink 的 18.01
→ SoftMax₁ 不足以完全替代专用的 [[sink-token|可学习汇 Token]]
## 与 Learnable Sink Token 的对比
| 方案 | 机制 | 有效性 |
|------|------|--------|
| SoftMax₁ (Zero Sink) | 修改 SoftMax 函数,允许丢弃注意力 | 部分改善,不够充分 |
| Learnable Sink Token | 预训练时添加专用可学习 Token | 完全有效,仅需 1 个 Token |
## 相关概念
- [[attention-sinks|注意力汇]] — 此方案试图解决的问题
- [[sink-token|汇 Token]] — 更有效的替代方案
- [[streaming-llm|StreamingLLM]] — 应用背景