Papers › Agent Attention: On the Integration of Softmax and Linear Attention

Agent Attention: On the Integration of Softmax and Linear Attention

14 Dec 2023arXiv:2312.08874archive 2025-07-28

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

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.

PaperPDFCodeCode Syntology ran

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 19 code samples: 18 from 1 repository linked to this paper, 1 identical to code harvested from another paper's repository. Across all 19: 13 ran (of which 0 constructed an object rather than computing a result; 6 with no instrument failure: 1 honoured, 2 violated, 3 with no contract checked; 7 where Syntology's instrument failed) · 6 unverified. Where Syntology's instrument failed: 4 where our contract draft was wrong; 3 where the contract check could not run; failures of Syntology's instrument, not of the code.

By repository: official repository: 18 samples from 1 repository, 12 ran (5 with no instrument failure; 7 where Syntology's instrument failed); 1 identical to code first harvested elsewhere. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

No sample is linked to this paper from 1 of its repositories that Syntology harvested for other papers:

Levels written between 2026-09-22 and 2026-09-25 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed. 4 of the 13 samples that ran have no recorded date.

leaplabthu/agent-attention officialmentioned in papermentioned on GitHubpytorchSyntology: 18 samples, 12 ran (7 instrument-failed) · 6 unverified report
lucidrains/agent-attention-pytorch mentioned on GitHubpytorchSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks (arXiv:1810.00825; that paper's own run record: 8 ran (of which 0 constructed an object rather than computing a result; 6 with no instrument failure: 0 honoured, 3 violated, 3 with no contract checked; 2 where Syntology's instrument failed) · 1 unverified); nothing checks that they implement this paper's method. report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

A paper named beside a repository with no sample linked to this paper is shown with that paper's own run record, not this paper's: “ran” means executed on a synthesized input, not that the code is correct, and “where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Papers are listed in arXiv-id order, at most three per repository.

Code Syntology ran Syntology

19 samples harvested: 13 ran (of which 0 constructed an object rather than computing a result; 6 with no instrument failure: 1 honoured, 2 violated, 3 with no contract checked; 7 where Syntology's instrument failed) · 6 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page last changed ; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

1ran · honoured contract
2ran · violated contract
4ran · our draft was wrong
3ran; the contract check could not run
3ran
6unverified

Licence: 19 of the 19 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from leaplabthu/agent-attention. 1 sample is listed last, in a group without a repository. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of six reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity. A census tag appears when Syntology's census ran implementations with that name on one shared input per bucket: it gives how many were compared, from how many papers, and how many distinct outputs they produced, and names this sample's bucket when this sample was one of them.

leaplabthu/agent-attention official repository 18 samples, 12 ran (7 instrument-failed) · 6 unverified
window_partition in 377 papers
census: 13 implementations from 17 papers, 5 distinct outputs across 3 buckets, one shared input per bucket
agent_transformer/models/agent_swin.py ran; the contract check could not run (RAISES) · metamorphic tier: invariant fingerprinted no licence file found · pointer only · 144d10b49baeb8a6 · report fixture: signature x:Tensor/4/float, window_size:int/0/int · returned Tensor · level recorded, date not recorded
build_optimizer in 83 papers agent_transformer/optimizer.py ran no licence file found · pointer only · fcf2d41dd445a70b · report fixture: signature config:Config/0/?, model:callable/0/? · returned AdamW · level recorded 2026-09-25
build_scheduler in 56 papers agent_transformer/lr_scheduler.py ran · our draft was wrong no licence file found · pointer only · 07e8b4b487c0abb6 · report fixture: signature config:SimpleNamespace/0/?, optimizer:SGD/0/?, n_iter_per_epoch:int/0/int · returned LinearLRScheduler · level recorded 2026-09-25
check_keywords_in_name in 32 papers agent_transformer/optimizer.py ran · violated contract no licence file found · pointer only · b0a5beb34716d5a6 · report fixture: signature name:str/0/str, keywords:tuple/1/str · returned bool · level recorded 2026-09-25
checkpoint_filter_fn in 80 papers agent_transformer/models/agent_deit.py ran · our draft was wrong no licence file found · pointer only · 5dac11fdc41c896b · report fixture: signature state_dict:dict/0/?, model:callable/0/? · returned dict · level recorded 2026-09-25
count_parameters in 278 papers agent_transformer/temp.py ran · honoured contract no licence file found · pointer only · f6b944f50d3f15ae · report fixture: signature model:callable/0/? · returned int · level recorded, date not recorded
create_logger in 172 papers agent_transformer/logger.py ran no licence file found · pointer only · 82e52feafbf040bb · report fixture: signature output_dir:str/0/str, dist_rank:int/0/int, name:str/0/str · returned Logger · level recorded 2026-09-25
img2windows in 15 papers agent_transformer/models/agent_cswin.py ran; the contract check could not run (RAISES) · metamorphic tier: invariant no licence file found · pointer only · 39b18f062e0cc6d9 · report fixture: signature img:Tensor/4/float, H_sp:int/0/int, W_sp:int/0/int · returned Tensor · level recorded 2026-09-22
resize_pos_embed in 102 papers agent_transformer/models/agent_deit.py ran; the contract check could not run (RAISES) no licence file found · pointer only · 1dbef2d4da4ee10f · report fixture: signature posemb:Tensor/3/float, posemb_new:Tensor/3/float, num_tokens:int/0/int, gs_new:tuple/1/int · returned Tensor · level recorded 2026-09-25
set_weight_decay_and_lr in 5 papers agent_transformer/optimizer.py ran no licence file found · pointer only · 104af48a94364f24 · report fixture: signature model:callable/0/?, skip_list:tuple/1/str, skip_keywords:tuple/1/str, lower_lr_kvs:dict/0/?, base_lr:float/0/float · returned list · level recorded 2026-09-25
window_reverse in 296 papers agent_transformer/models/agent_swin.py ran · our draft was wrong no licence file found · pointer only · 61bf152e6a42a184 · report fixture: signature windows:Tensor/4/float, window_size:int/0/int, H:int/0/int, W:int/0/int · returned Tensor · level recorded, date not recorded
windows2img in 15 papers agent_transformer/models/agent_cswin.py ran · our draft was wrong no licence file found · pointer only · ab01fbfe58c75b08 · report fixture: signature img_splits_hw:Tensor/4/float, H_sp:int/0/int, W_sp:int/0/int, H:int/0/int, W:int/0/int · returned Tensor · level recorded 2026-09-22
Agent_CSWin_64_24181_tiny_224 agent_transformer/models/agent_cswin.py unverified no licence file found · pointer only · 9ea67e130f91790b · report
agent_pvt_medium agent_transformer/models/agent_pvt.py unverified no licence file found · pointer only · cde1668e5b186869 · report
agent_pvt_small agent_transformer/models/agent_pvt.py unverified no licence file found · pointer only · 941e08e41b939a56 · report
agent_pvt_tiny agent_transformer/models/agent_pvt.py unverified no licence file found · pointer only · 18fe6a56092254c6 · report
build_model in 469 papers agent_transformer/models/build.py unverified no licence file found · pointer only · 11b1272f108e216a · report
get_config in 203 papers agent_transformer/config.py unverified no licence file found · pointer only · 20681a9065c0a731 · report
Repository not located 1 sample, 1 ran (0 instrument-failed) · 0 unverified
1 sample is identical to code Syntology harvested from another paper's repository; this paper's own copy was not located, so no repository is named and no licence is recorded.
exists in 528 papers
census: 5 implementations from 103 papers, 1 distinct output on one shared input
repository not located ran · violated contract fingerprinted licence of this copy not recorded · b7c3487f192e31b7 · report fixture: signature v:int/0/int · returned bool · level recorded, date not recorded

Tasks

Computational EfficiencyImage ClassificationImage GenerationObject DetectionSemantic Segmentationimage-classificationobject-detection

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

DiffusionSETSoftmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections