arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2312.08874cs.CV
收藏

Agent Attention:关于Softmax与线性注意力的融合

Agent Attention: On the Integration of Softmax and Linear Attention

Tsinghua University(清华大学);Kuaishou Technology(快手科技)

Dongchen Han, Tianzhu Ye, Yizeng Han, Zhuofan Xia, Siyuan Pan, Pengfei Wan, Shiji Song, Gao Huang

AI总结:

针对Transformer全局注意力计算成本高的问题,提出融合Softmax与线性注意力的Agent Attention范式,通过引入少量智能体令牌实现高效全局建模,在多视觉任务及高分辨率场景下表现优异。

摘要:

注意力模块是Transformer中的核心组件。尽管全局注意力机制具备强大的表达能力,但其过高的计算成本限制了它在多种场景下的适用性。本文提出一种新型注意力范式——Agent Attention(智能体注意力),在计算效率与表征能力之间实现良好平衡。具体而言,记为四元组$(Q, A, K, V)$的Agent Attention在传统注意力模块中引入了一组额外的智能体令牌$A$。智能体令牌首先作为查询令牌$Q$的代理,从$K$和$V$中聚合信息,随后将信息回传给$Q$。由于智能体令牌的数量可设计为远少于查询令牌的数量,Agent Attention比广泛使用的Softmax注意力效率显著更高,同时保留了全局上下文建模能力。有趣的是,我们证明所提出的智能体注意力等价于线性注意力的一种广义形式。因此,Agent Attention无缝融合了功能强大的Softmax注意力与高效的线性注意力。大量实验验证了Agent Attention在多种视觉Transformer以及各类视觉任务中的有效性,涵盖图像分类、目标检测、语义分割和图像生成。值得注意的是,得益于其线性注意力的特性,Agent Attention在高分辨率场景下表现出色。例如,当应用于Stable Diffusion时,我们的智能体注意力可加速生成过程,并在无需额外训练的情况下大幅提升图像生成质量。代码可在https://github.com/LeapLabTHU/Agent-Attention获取。

英文摘要:

The attention module is the key component in Transformers. While the global attention mechanism offers high expressiveness, its excessive computational cost restricts its applicability in various scenarios. In this paper, we propose a novel attention paradigm, Agent Attention, to strike a favorable balance between computational efficiency and representation power. Specifically, the Agent Attention, denoted as a quadruple $(Q, A, K, V)$, introduces an additional set of agent tokens $A$ into the conventional attention module. The agent tokens first act as the agent for the query tokens $Q$ to aggregate information from $K$ and $V$, and then broadcast the information back to $Q$. Given the number of agent tokens can be designed to be much smaller than the number of query tokens, the agent attention is significantly more efficient than the widely adopted Softmax attention, while preserving global context modelling capability. Interestingly, we show that the proposed agent attention is equivalent to a generalized form of linear attention. Therefore, agent attention seamlessly integrates the powerful Softmax attention and the highly efficient linear attention. Extensive experiments demonstrate the effectiveness of agent attention with various vision Transformers and across diverse vision tasks, including image classification, object detection, semantic segmentation and image generation. Notably, agent attention has shown remarkable performance in high-resolution scenarios, owning to its linear attention nature. For instance, when applied to Stable Diffusion, our agent attention accelerates generation and substantially enhances image generation quality without any additional training. Code is available at https://github.com/LeapLabTHU/Agent-Attention.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑