Files
myWiki/concepts/linear-attention-methods.md

42 lines
1.3 KiB
Markdown
Raw 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: 线性注意力方法 (Linear Attention Methods)
created: 2025-04-15
updated: 2026-05-01
type: concept
tags: []
sources: []
---
# 线性注意力方法 (Linear Attention Methods)
**O(n) 复杂度的注意力替代方案**,通过核函数分解避免显式 N×N 注意力矩阵计算。
## 核心思想
将 softmax 注意力中的核函数 κ(Q, K) 分解为特征映射乘积:
$$\kappa(Q, K) \approx \phi(Q) \cdot \phi(K)^T$$
利用矩阵乘法的结合律改变计算顺序:(QK^T)V → Q(K^TV),将复杂度从 O(n²) 降至 O(n)。
## 代表方法
- **Linear Transformer** (Katharopoulos 2020): 首次提出线性注意力
- **Performer**: 使用随机特征近似 softmax
- **RetNet**: 同时支持并行训练和循环推理的统一框架
- **RWKV**: 结合 RNN 效率与 Transformer 性能
## 与稀疏注意力的对比
| 特性 | 线性注意力 | [[sparse-attention-patterns|稀疏注意力]] |
|------|-----------|-----------|
| 复杂度 | O(n) | O(n·k) |
| 全局视野 | 隐式(全局压缩) | 显式(但受限) |
| 质量 | 一般略低于 MHA | 通常优于线性 |
## 相关概念
- [[sparse-attention-patterns]] — 稀疏注意力
- [[mamba-ssm]] — 状态空间模型(线性复杂度的新兴路径)
- [[subquadratic-transformer-alternatives]] — 次二次替代综述
- [[llm-attention-survey-2026]] — 综述参考