Skip to main content
QUICK REVIEW

[论文解读] Agent Attention: On the Integration of Softmax and Linear Attention

Dongchen Han, Tianzhu Ye|arXiv (Cornell University)|Dec 14, 2023
Advanced Neural Network ApplicationsComputer Science被引用 20
一句话总结

引入 Agent Attention,一种新的注意力范式,使用代理令牌聚合并广播全局信息,有效结合 Softmax 与线性注意力,在线性复杂度下实现高表达能力。

ABSTRACT

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.

研究动机与目标

  • 推动高效且具表现力的视觉变换器注意力,超越传统的 Softmax 注意力。
  • 开发一种机制,在不牺牲全局上下文建模的前提下整合 Softmax 与线性注意力。
  • 展示在图像分类、目标检测、语义分割和图像生成等领域的广泛适用性。
  • 为现有架构提供插件式设计,并分析效率与性能之间的权衡。

提出的方法

  • 将代理注意力定义为一个四元组 (Q, A, K, V),引入代理令牌 A 以从 K, V 聚合并广播到 Q。
  • 通过两个 Softmax 注意力展示其对广义线性注意力形式的理论等价性:O^A = Attn^S(Q, A, Attn^S(A, K, V)).
  • 通过聚合或可学习参数获得代理令牌 A;在具有 n 个代理令牌的情况下,使用线性复杂度 O(Nnd)。
  • 通过 Agent Bias 注入位置信息,并使用多样性恢复模块(深度卷积)来保持特征多样性。
  • 提出一个 Agent Attention 模块,结合纯代理注意力、代理偏置和 DWC:O = σ(QA^T + B2) σ(AK^T + B1) V + DWC(V)。
  • 展示对 DeiT、PVT、Swin、CSwin 与 Stable Diffusion 的即插即用集成,包含消融实验和高分辨率实验。

实验结果

研究问题

  • RQ1代理令牌是否能够以线性计算复杂度实现全局上下文建模?
  • RQ2通过代理令牌整合 Softmax 与线性注意力对视觉任务(分类、检测、分割、生成)的性能有何影响?
  • RQ3哪些设计选择(代理偏置、代理令牌的数量/类型、在何处应用代理注意力)能优化准确性与效率?
  • RQ4在高分辨率和高感受野设置中,代理注意力是否有益,包括像 Stable Diffusion 这样的扩散模型?
  • RQ5代理注意力在不同架构中与现有线性注意力方法相比如何?

主要发现

  • 代理注意力在多种架构(如 Agent-PVT、Swin)上相对于 Softmax 注意力基线实现了显著的准确性提升,同时具有较低或可比的 FLOPs。
  • Agent-PVT 变体在参数和 FLOPs 更少的情况下超越相应的 PVT 模型(如 Agent-PVT-S 对 PVT-S,+2. ?见来源),且 Agent-Swin-T/S 在相近 FLOPs 下超越 Swin-T/S。
  • 在目标检测和分割任务中,代理变体持续提升 AP 和 mIoU,相对于基线(如 Agent-PVT 和 Agent-Swin 在 COCO 和 ADE20K 上显示显著提升)。
  • 代理注意力在高分辨率下显著提升性能;通过代理注意力增加感受野在不增加计算量的情况下获得更高准确性。
  • 应用于 Stable Diffusion 时,Agent Attention 将生成速度提高约 1.7x–2.1x 且不增加额外训练即可提升图像质量;在扩散早期步骤使用代理令牌可获得显著收益。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。