SEA: Sparse Linear Attention with Estimated Attention Mask

📄 arXiv: 2310.01777v2 📥 PDF

作者: Heejun Lee, Jina Kim, Jeffrey Willette, Sung Ju Hwang

分类: cs.CL, cs.LG

发布日期: 2023-10-03 (更新: 2024-03-25)

备注: 9 main pages


💡 一句话要点

提出SEA以解决长序列注意力计算复杂度问题

🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture)

关键词: 变换器 稀疏注意力 线性注意力 自然语言处理 模型压缩 可解释性 资源优化

📋 核心要点

  1. 现有的稀疏和线性注意力方法在处理长序列时面临计算复杂度高和知识提取困难的问题。
  2. SEA通过核基线性注意力估计注意力矩阵,并利用top-k选择生成稀疏注意力矩阵,从而降低计算复杂度。
  3. 在Wikitext2语言建模任务中,SEA的困惑度优于OPT-1.3B,并且内存使用量减少了约50%。

📝 摘要(中文)

变换器架构在需要建模序列元素之间成对关系的任务中取得了突破性进展,然而长序列导致注意力操作的二次复杂性问题。以往研究通过稀疏化或线性近似注意力矩阵来降低复杂度,但这些方法无法直接从教师的注意力矩阵中提取知识,且通常需要从头开始完全重训练。此外,之前的稀疏和线性方法在无法生成完整注意力矩阵时失去了可解释性。为了解决这些挑战,我们提出了SEA:基于估计注意力掩码的稀疏线性注意力。SEA通过基于核的线性注意力以线性复杂度估计注意力矩阵,然后通过top-k选择创建稀疏注意力矩阵以执行稀疏注意力操作。在语言建模任务(Wikitext2)中,SEA的困惑度优于OPT-1.3B,并使用了大约一半的内存,提供了可解释的注意力矩阵。我们相信这项工作将在资源有限的设备上运行大型变换器方面产生重大实际影响。

🔬 方法详解

问题定义:论文要解决的问题是长序列注意力计算的二次复杂性,现有方法在稀疏化和线性近似时无法有效提取知识,且通常需要完全重训练。

核心思路:论文的核心思路是通过核基线性注意力以线性复杂度估计注意力矩阵,然后通过top-k选择生成稀疏注意力矩阵,从而实现高效的注意力计算。

技术框架:整体架构包括两个主要模块:首先是基于核的线性注意力模块,用于估计注意力矩阵;其次是稀疏化模块,通过top-k选择生成稀疏注意力矩阵并执行注意力操作。

关键创新:最重要的技术创新点在于SEA能够在保持可解释性的同时,显著降低注意力计算的复杂度,与现有方法相比,避免了完全重训练的需求。

关键设计:关键设计包括选择合适的核函数以实现线性复杂度的注意力估计,以及在稀疏化过程中如何有效选择top-k元素,以确保注意力矩阵的有效性和可解释性。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,SEA在Wikitext2语言建模任务中的困惑度优于OPT-1.3B,且内存使用量减少了约50%。这一结果表明,SEA不仅在性能上超越了现有的线性和稀疏注意力方法,还提供了更好的可解释性。

🎯 应用场景

该研究的潜在应用领域包括自然语言处理、机器翻译和对话系统等。SEA的设计使得在资源有限的设备上运行大型变换器成为可能,具有重要的实际价值和广泛的应用前景,尤其是在移动设备和边缘计算环境中。

📄 摘要(原文)

The transformer architecture has driven breakthroughs in recent years on tasks which require modeling pairwise relationships between sequential elements, as is the case in natural language understanding. However, long seqeuences pose a problem due to the quadratic complexity of the attention operation. Previous research has aimed to lower the complexity by sparsifying or linearly approximating the attention matrix. Yet, these approaches cannot straightforwardly distill knowledge from a teacher's attention matrix and often require complete retraining from scratch. Furthermore, previous sparse and linear approaches lose interpretability if they cannot produce full attention matrices. To address these challenges, we propose SEA: Sparse linear attention with an Estimated Attention mask. SEA estimates the attention matrix with linear complexity via kernel-based linear attention, then subsequently creates a sparse attention matrix with a top-k selection to perform a sparse attention operation. For language modeling tasks (Wikitext2), previous linear and sparse attention methods show roughly two-fold worse perplexity scores over the quadratic OPT-1.3B baseline, while SEA achieves better perplexity than OPT-1.3B, using roughly half the memory of OPT-1.3B, providing interpretable attention matrix. We believe that our work will have a large practical impact, as it opens the possibility of running large transformers on resource-limited devices with less memory.