All models

Agent Attention

A vision Transformer whose attention routes queries through a small set of agent tokens.

Image classification · 949 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (19 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
28.9M
Operations
949
Framework
PyTorch
Recurrent
No
Published
ECCV 2024
Cited by
247 (as of 27 October 2026)
Authors
Dongchen Han, Tianzhu Ye, Yizeng Han and others
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m14652
Graph hash
f3a5b6e5774eb8cb8fc74074ac545418918ed6d2cf06990ed0ac0e5c8618e38b
Skeleton hash
5b5f079a073b60a4a465cc689ba7fa9a2f205c619ed48576718e4e551b4a6a7c
Architecture hash
22156758c209299696a505ea9c7f0d92cb8c929c897f75f6b2b8a104f36500d8
Diagram SHA-256
d8ba9a5c96720d5bc39588df08822b43db3a9c4ef550f9a0fe931f1effe1bf3b
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

Agent Attention is an attention module for Transformers that keeps global context while being much cheaper to compute than the usual Softmax attention. The paper starts from the observation that global attention is expressive but that its computational cost restricts where it can be applied.

The module adds a set of agent tokens to the usual queries, keys and values. The agent tokens first aggregate information from the keys and values on behalf of the queries, and then broadcast it back to the queries. The number of agent tokens can be much smaller than the number of query tokens, and the paper shows that the result is equivalent to a generalized form of linear attention. In the official module the agent tokens are obtained through pooling. An agent bias and DWC are added to supply positional information and maintain feature diversity.

The paper tests the module in several vision Transformers on image classification, object detection, semantic segmentation and image generation. The official code is developed on top of PVT, Swin Transformer, CSwin Transformer and ToMeSD. Applied to Stable Diffusion, the paper reports faster generation and better image generation quality without any additional training.

Key idea. Agent Attention inserts a small set of agent tokens between the queries and the keys and values, which the paper shows is equivalent to a generalized form of linear attention.

  • Agent Attention
  • agent tokens
  • Agent-Swin
  • Agent-DeiT
  • Agent-PVT
  • Agent-CSwin
  • AgentSD
  • linear attention
  • efficient attention
  • image classification

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{han2024agentattentionintegrationsoftmax,
      title={Agent Attention: On the Integration of Softmax and Linear Attention}, 
      author={Dongchen Han and Tianzhu Ye and Yizeng Han and Zhuofan Xia and Siyuan Pan and Pengfei Wan and Shiji Song and Gao Huang},
      year={2024},
      eprint={2312.08874},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2312.08874}, 
}