[Paper Review] Agent Attention: On the Integration of Softmax and Linear Attention
Introduces Agent Attention, a new attention paradigm that uses agent tokens to aggregate and broadcast global information, effectively integrating Softmax and linear attention to achieve high expressiveness with linear complexity.
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.
Motivation & Objective
- Motivate efficient yet expressive attention for vision transformers beyond traditional Softmax attention.
- Develop a mechanism to integrate Softmax and linear attention without sacrificing global context modeling.
- Demonstrate broad applicability across image classification, object detection, semantic segmentation, and image generation.
- Provide plug-in designs for existing architectures and analyze efficiency versus performance.
Proposed method
- Define agent attention as a quadruple (Q, A, K, V) introducing agent tokens A to aggregate from K,V and broadcast to Q.
- Show theoretical equivalence to a generalized linear attention form via two Softmax attentions: O^A = Attn^S(Q, A, Attn^S(A, K, V)).
- Obtain agent tokens A by pooling or learnable parameters; use linear complexity O(Nnd) with n agent tokens.
- Enhance with Agent Bias to inject positional information and a Diversity Restoration Module (depthwise convolution) to preserve feature diversity.
- Present an Agent Attention Module combining pure agent attention, agent bias, and DWC: O = σ(QA^T + B2) σ(AK^T + B1) V + DWC(V).
- Demonstrate plug-and-play integration into DeiT, PVT, Swin, CSwin, and Stable Diffusion, with ablations and high-resolution experiments.
Experimental results
Research questions
- RQ1Can agent tokens enable global context modeling with linear computational complexity?
- RQ2How does integrating Softmax and linear attention via agent tokens affect performance on vision tasks (classification, detection, segmentation, generation)?
- RQ3What design choices (agent bias, number/type of agent tokens, where to apply agent attention) optimize accuracy and efficiency?
- RQ4Is agent attention beneficial in high-resolution and high-receptive-field settings, including diffusion models like Stable Diffusion?
- RQ5How does agent attention compare to existing linear attention methods across architectures?
Key findings
- Agent Attention achieves substantial accuracy gains over Softmax-attention baselines across multiple architectures (e.g., Agent-PVT,Swin) with reduced or comparable FLOPs.
- Agent-PVT variants surpass corresponding PVT models with fewer parameters and FLOPs (e.g., Agent-PVT-S vs PVT-S, +2. ? see source) and Agent-Swin-T/S outperform Swin-T/S with similar FLOPs.
- In object detection and segmentation, Agent variants consistently improve AP and mIoU over baselines (e.g., Agent-PVT and Agent-Swin show notable gains on COCO and ADE20K).
- Agent attention dramatically improves performance at high resolutions; increasing receptive field with agent attention yields better accuracy without increasing computation.,”
- Applied to Stable Diffusion, Agent Attention speeds generation by 1.7x–2.1x and improves image quality without extra training; using agent tokens during early diffusion steps yields notable gains.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.