HyperAIHyperAI

Command Palette

Search for a command to run...

Cumulant Attention in Vision Transformers (Student Abstract)

Yuto Morimoto Zhipeng Wang Koji Yasuda

摘要

Transformer models have achieved remarkable success across diverse deep learning fields, including natural language processing (NLP) and computer vision (CV). One drawback of these models is that the computational cost of the softmax attention, the core component of the transformer, exhibits quadratic complexity in both time and memory. As data scales up various attempts have been reported to overcome this bottleneck. The objective of this study is to propose a novel attention mechanism, "Cumulant Attention", that systematically balances efficiency and accuracy. This proposal introduces a statistical-mechanics perspective and a reliable approximation based on cumulant expansion into the attention layer. The low-order variant reduces computational complexity to linear order, similar to the linear attention, while keeping nonlinearity of the softmax attention. We evaluate several variants on CV tasks, including image classification with ViT on ImageNet-100 and video classification with ViViT on UCF-101. Experimental results demonstrate that the cumulant attention outperforms the linear attention and achieves accuracy comparable to the softmax attention. These findings validate the effectiveness of our approach and highlight future directions, including scaling to larger models, extending to other modalities, and optimizing implementations for GPU hardware.

一句话总结

名古屋大学材料与系统可持续性研究所的研究者提出 Cumulant Attention,这是一种将统计力学中的累积量展开应用于近似 softmax 注意力的注意力机制,可在线性计算复杂度下保留其非线性;在基于 ViT 的图像和视频分类任务中,它优于线性注意力,并达到与 softmax 注意力相当的准确率。

核心贡献

  • 论文介绍了 Cumulant Attention,这是一种将统计力学视角和累积量展开引入 Transformer 注意力层的注意力机制,以在效率和准确率之间取得平衡。

  • Cumulant Attention 的低阶变体将注意力计算降低为线性阶,同时保留与 softmax 注意力相关的非线性行为。

  • 在 ImageNet-100 上使用 ViT 的图像分类实验,以及在 UCF-101 上使用 ViViT 的视频分类实验表明,Cumulant Attention 优于线性注意力,并达到与 softmax 注意力相当的准确率。

引言

Transformer attention 为语言、视觉、语音、图结构和多模态任务中的现代模型提供核心能力,但其标准 softmax 注意力随序列长度呈平方级扩展,为大规模数据带来严重的效率瓶颈。此前的线性注意力等高效注意力方法通过核化近似降低成本,但在计算机视觉中的空间选择性和局部特征提取方面可能表现欠佳。作者利用统计力学中的思想设计了一种高效注意力机制,通过物理概念和累积量来理解注意力,旨在保留富有表达力的相关性建模能力,同时降低计算开销。该方法在计算机视觉任务上表现强劲,优于线性注意力,并接近 softmax 注意力的准确率。

方法

作者将标准缩放点积注意力重写为统计力学自由能的梯度。将 tokens xlx^lxl 视为随机变量 XXX 的可能状态,且从由 LLL 个键组成的集合中均匀抽取。查询侧被视为外场,场方向由常规键投影和查询投影所决定的查询键交互来确定。配分函数定义为

Z(p)=⟨exp⁡(p⋅X)⟩,Z(p) = \langle \exp(p \cdot X) \rangle,Z(p)=⟨exp(p⋅X)⟩,

而对数配分函数

F(p)=log⁡Z(p)F(p) = \log Z(p)F(p)=logZ(p)

扮演负自由能势的角色。对该量相对于外场求导,可得到玻尔兹曼型分布下的归一化期望,

∂F(p)∂p=∑l=1Lxlexp⁡(p⋅xl)∑l=1Lexp⁡(p⋅xl).\frac{\partial F(p)}{\partial p} = \frac{\sum_{l=1}^L x^l \exp(p \cdot x^l)} {\sum_{l=1}^L \exp(p \cdot x^l)}.∂p∂F(p)​=∑l=1L​exp(p⋅xl)∑l=1L​xlexp(p⋅xl)​.

在应用值投影和常规查询键缩放后,该导数再现了注意力输出,

attn⁡(q)=∑j=1Lexp⁡(q⋅kj)vj∑j=1Lexp⁡(q⋅kj).\operatorname{attn}(q) = \frac{\sum_{j=1}^L \exp(q \cdot k^j) v^j} {\sum_{j=1}^L \exp(q \cdot k^j)}.attn(q)=∑j=1L​exp(q⋅kj)∑j=1L​exp(q⋅kj)vj​.

因此,注意力不仅可被解释为值向量的可学习混合,还可被解释为物理系统对外场的响应。softmax 分母对应配分函数,注意力对应自由能势的导数。

第二个核心思想是使用累积量展开来近似自由能势。累积量是 log⁡Z(p)\log Z(p)logZ(p) 幂级数展开中的系数,表示随机变量之间的相关性。第一累积量是均值,第二累积量是协方差,更高阶累积量描述真正的高阶统计依赖性。展开形式为

F(p)=F(0)+∑ipi⟨Xi⟩+∑ijpipj2(⟨XiXj⟩−⟨Xi⟩⟨Xj⟩)+∑ijkpipjpk3!⟨XiXjXk⟩c+⋯\begin{aligned} F(p) = F(0) &+ \sum_i p_i \langle X_i \rangle + \sum_{ij} \frac{p_i p_j}{2} \left( \langle X_i X_j \rangle - \langle X_i \rangle \langle X_j \rangle \right) \\ &+ \sum_{ijk} \frac{p_i p_j p_k}{3!} \langle X_i X_j X_k \rangle_c + \cdots \end{aligned}F(p)=F(0)​+i∑​pi​⟨Xi​⟩+ij∑​2pi​pj​​(⟨Xi​Xj​⟩−⟨Xi​⟩⟨Xj​⟩)+ijk∑​3!pi​pj​pk​​⟨Xi​Xj​Xk​⟩c​+⋯​

其中第三中心累积量为

⟨XiXjXk⟩c=⟨XiXjXk⟩−⟨XiXj⟩⟨Xk⟩−⟨XjXk⟩⟨Xi⟩−⟨XkXi⟩⟨Xj⟩+2⟨Xi⟩⟨Xj⟩⟨Xk⟩.\begin{aligned} \langle X_i X_j X_k \rangle_c = &\langle X_i X_j X_k \rangle - \langle X_i X_j \rangle \langle X_k \rangle - \langle X_j X_k \rangle \langle X_i \rangle \\ &- \langle X_k X_i \rangle \langle X_j \rangle + 2 \langle X_i \rangle \langle X_j \rangle \langle X_k \rangle. \end{aligned}⟨Xi​Xj​Xk​⟩c​=​⟨Xi​Xj​Xk​⟩−⟨Xi​Xj​⟩⟨Xk​⟩−⟨Xj​Xk​⟩⟨Xi​⟩−⟨Xk​Xi​⟩⟨Xj​⟩+2⟨Xi​⟩⟨Xj​⟩⟨Xk​⟩.​

该方法通过截断这一展开获得对注意力的受控近似。仅保留第一和第二累积量会得到二阶累积量注意力

attn⁡2nd=Lvˉ+∑l=1L[q⋅(kl−kˉ)](vl−vˉ),\operatorname{attn}_{\mathrm{2nd}} = L \bar{v} + \sum_{l=1}^L \left[ q \cdot (k^l - \bar{k}) \right] (v^l - \bar{v}),attn2nd​=Lvˉ+l=1∑L​[q⋅(kl−kˉ)](vl−vˉ),

其中 kˉ\bar{k}kˉ 和 vˉ\bar{v}vˉ 分别表示平均键向量和值向量。该表达式用由中心化键值统计量构建的加性修正替代了 softmax 归一化。该近似的主导修正来自第三累积量的对角部分,从而得到

attn⁡3rd=attn⁡2nd+12∑l=1L∑iqi2(kil−kˉi)2(vl−vˉ).\operatorname{attn}_{\mathrm{3rd}} = \operatorname{attn}_{\mathrm{2nd}} + \frac{1}{2} \sum_{l=1}^L \sum_i q_i^2 (k_i^l - \bar{k}_i)^2 (v^l - \bar{v}).attn3rd​=attn2nd​+21​l=1∑L​i∑​qi2​(kil​−kˉi​)2(vl−vˉ).

在该公式中,近似通过键和值嵌入的矩来运作。二阶注意力对应于保留均值和协方差信息,这相当于假设底层统计变量服从多元正态分布。三阶项引入了对更高阶嵌入相关性的额外依赖,并作为对该高斯近似的系统性修正。累积量公式的一个显著性质是连通团簇定理移除了分母,从而得到一种结构由中心化键值矩决定的加性近似。

实验

实验在 ImageNet-100 上使用 ViT 进行图像分类,并在 UCF-101 上使用 ViViT 进行视频分类,以评估 Cumulant Attention。结果表明,Cumulant Attention 始终优于线性注意力,并接近 softmax 注意力,这体现了其选择性能力和更局域化的注意力模式。视频分类也观察到类似趋势,不过由于数据集规模较小,模型倾向于过拟合。


用 AI 构建 AI

从创意到上线——通过免费 AI 协同编码、开箱即用的环境和最优惠的 GPU 价格,加速您的 AI 开发。

AI 协同编码
开箱即用的 GPU
最优定价

HyperAI Newsletters

订阅我们的最新资讯
我们会在北京时间 每周一的上午九点 向您的邮箱投递本周内的最新更新
邮件发送服务由 MailChimp 提供