HLA: Hadamard Linear Attention
作者: Hanno Ackermann, Hong Cai, Mohsen Ghafoorian, Amirhossein Habibian
分类: cs.AI
发布日期: 2026-02-12
💡 一句话要点
提出Hadamard线性注意力(HLA),用于高效近似Transformer中的softmax注意力机制。
🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture)
关键词: 线性注意力 Transformer Hadamard变换 视频生成 注意力机制
📋 核心要点
- 标准注意力机制计算复杂度高,线性注意力通过核函数近似,但精度受限。
- HLA在计算相似度后引入非线性,使用更高阶有理函数近似softmax,提升精度。
- HLA计算效率高,无需张量重塑,在视频生成Transformer模型上验证了有效性。
📝 摘要(中文)
注意力机制是Transformer成功的关键因素。它依赖于计算tokens之间的成对关系。为了降低标准二次注意力的高计算成本,线性注意力被提出作为一种有效的近似方法。线性注意力采用核函数,在计算成对相似性之前独立地应用于输入。这使得计算过程高效,但同时也导致了使用低阶有理函数来近似softmax。本文提出了Hadamard线性注意力(HLA)。与以往的线性注意力工作不同,HLA中的非线性不是分别应用于queries和keys,而是类似于标准softmax注意力,在计算成对相似性之后应用。结果表明,所提出的非线性相当于使用更高阶的有理函数来近似softmax。推导出了一种与标准线性注意力相似的有效计算方案。与其他方法相比,应用该算法不需要耗时的张量重塑。通过将其应用于用于视频生成的大型扩散Transformer模型(涉及大量tokens的应用)来证明该方法的有效性。
🔬 方法详解
问题定义:Transformer中的标准注意力机制计算复杂度为O(N^2),其中N是token的数量。对于长序列,计算成本非常高。线性注意力通过将query和key分别进行核函数变换,然后计算点积,将复杂度降低到O(N)。然而,这种方法使用低阶有理函数近似softmax,精度可能受到影响。
核心思路:HLA的核心思路是在计算query和key的点积之后,再应用非线性变换,类似于标准softmax注意力。通过这种方式,HLA可以使用更高阶的有理函数来近似softmax,从而提高精度。同时,HLA保持了线性注意力的计算效率。
技术框架:HLA的整体框架与线性注意力类似。首先,将query和key分别进行线性变换。然后,计算变换后的query和key的点积,得到相似度矩阵。接下来,对相似度矩阵应用Hadamard变换,引入非线性。最后,将变换后的相似度矩阵用于计算注意力权重。整个过程不需要耗时的张量重塑操作。
关键创新:HLA的关键创新在于在计算相似度之后引入非线性变换。这种非线性变换是通过Hadamard变换实现的,它能够有效地提高softmax近似的精度。与以往的线性注意力方法相比,HLA能够使用更高阶的有理函数来近似softmax,从而更好地捕捉token之间的关系。
关键设计:HLA的关键设计包括Hadamard变换的具体形式和参数设置。论文中具体使用了哪种Hadamard变换以及如何设置其参数,摘要中未提及,属于未知信息。损失函数和网络结构方面,HLA可以与现有的Transformer模型相结合,无需进行额外的修改。
🖼️ 关键图片
📊 实验亮点
论文将HLA应用于一个大型扩散Transformer模型,用于视频生成任务。实验结果表明,HLA在保持计算效率的同时,能够有效地提高视频生成的质量。具体的性能数据和提升幅度在摘要中未提及,属于未知信息。
🎯 应用场景
HLA可以应用于各种需要处理长序列的任务,例如视频生成、机器翻译、语音识别等。尤其是在资源受限的场景下,HLA可以在保证一定精度的前提下,显著降低计算成本,提高模型的效率。未来,HLA有望成为Transformer模型中一种重要的注意力机制替代方案。
📄 摘要(原文)
The attention mechanism is an important reason for the success of transformers. It relies on computing pairwise relations between tokens. To reduce the high computational cost of standard quadratic attention, linear attention has been proposed as an efficient approximation. It employs kernel functions that are applied independently to the inputs before the pairwise similarities are calculated. That allows for an efficient computational procedure which, however, amounts to a low-degree rational function approximating softmax. We propose Hadamard Linear Attention (HLA). Unlike previous works on linear attention, the nonlinearity in HLA is not applied separately to queries and keys, but, analogously to standard softmax attention, after the pairwise similarities have been computed. It will be shown that the proposed nonlinearity amounts to a higher-degree rational function to approximate softmax. An efficient computational scheme for the proposed method is derived that is similar to that of standard linear attention. In contrast to other approaches, no time-consuming tensor reshaping is necessary to apply the proposed algorithm. The effectiveness of the approach is demonstrated by applying it to a large diffusion transformer model for video generation, an application that involves very large amounts of tokens.