Agent Attention: On the Integration of Softmax and Linear Attention

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Han, Dongchen, Ye, Tianzhu, Han, Yizeng, Xia, Zhuofan, Pan, Siyuan, Wan, Pengfei, Song, Shiji, Huang, Gao
Format: Preprint
Published: 2023
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916323782557696
author Han, Dongchen
Ye, Tianzhu
Han, Yizeng
Xia, Zhuofan
Pan, Siyuan
Wan, Pengfei
Song, Shiji
Huang, Gao
author_facet Han, Dongchen
Ye, Tianzhu
Han, Yizeng
Xia, Zhuofan
Pan, Siyuan
Wan, Pengfei
Song, Shiji
Huang, Gao
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2312_08874
institution arXiv
publishDate 2023
record_format arxiv
spellingShingle Agent Attention: On the Integration of Softmax and Linear Attention
Han, Dongchen
Ye, Tianzhu
Han, Yizeng
Xia, Zhuofan
Pan, Siyuan
Wan, Pengfei
Song, Shiji
Huang, Gao
Computer Vision and Pattern Recognition
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.
title Agent Attention: On the Integration of Softmax and Linear Attention
topic Computer Vision and Pattern Recognition
url https://arxiv.org/abs/2312.08874