用循环矩阵结构加速视觉Transformer注意力计算
Vision Transformers are Circulant Attention Learners

- 将注意力矩阵建模为块循环结构,实现快速计算
- 计算复杂度降至O(N log N),实测速度提升显著
- 保持原模型性能,适合高分辨率图像任务
自注意力机制推动了视觉Transformer的发展,但其二次复杂度在高分辨率场景下带来沉重计算负担,限制实际应用。以往方法通过引入手工设计的局部或稀疏模式缓解问题,却不可避免损害模型容量。本文提出一种新型注意力范式——循环注意力(Circulant Attention),利用视觉Transformer中自注意力矩阵常近似于块循环矩阵(BCCB)这一内在高效结构。我们显式将注意力图建模为最接近的BCCB矩阵,并设计高效计算算法实现快速运算。该方法仅在使用BCCB矩阵上与标准自注意力不同,却能实现O(N log N)的计算复杂度,同时基本保持原始模型容量。大量实验表明,该方法在多种视觉任务中表现优异,证明循环注意力是视觉Transformer中自注意力的有力替代方案。代码已开源。
原文摘要 · Abstract (English)
The self-attention mechanism has been a key factor in the advancement of vision Transformers. However, its quadratic complexity imposes a heavy computational burden in high-resolution scenarios, restricting the practical application. Previous methods attempt to mitigate this issue by introducing handcrafted patterns such as locality or sparsity, which inevitably compromise model capacity. In this paper, we present a novel attention paradigm termed \textbf{Circulant Attention} by exploiting the inherent efficient pattern of self-attention. Specifically, we first identify that the self-attention matrix in vision Transformers often approximates the Block Circulant matrix with Circulant Blocks (BCCB), a kind of structured matrix whose multiplication with other matrices can be performed in $\mathcal{O}(N\log N)$ time. Leveraging this interesting pattern, we explicitly model the attention map as its nearest BCCB matrix and propose an efficient computation algorithm for fast calculation. The resulting approach closely mirrors vanilla self-attention, differing only in its use of BCCB matrices. Since our design is inspired by the inherent efficient paradigm, it not only delivers $\mathcal{O}(N\log N)$ computation complexity, but also largely maintains the capacity of standard self-attention. Extensive experiments on diverse visual tasks demonstrate the effectiveness of our approach, establishing circulant attention as a promising alternative to self-attention for vision Transformer architectures. Code is available at https://github.com/LeapLabTHU/Circulant-Attention.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。