Skip to main content
QUICK REVIEW

[论文解读] SwiftFormer: Efficient Additive Attention for Transformer-based Real-time Mobile Vision Applications

Abdelrahman Shaker, Muhammad Maaz|arXiv (Cornell University)|Mar 27, 2023
Advanced Neural Network Applications被引用 5
一句话总结

SwiftFormer 提出了一种高效的加法注意力机制,用线性逐元素运算替代了自注意力中的二次矩阵乘法,使移动设备上的视觉变换器能够实现高精度、低延迟推理。该方法在 iPhone 14 上实现了仅 0.8 ms 的推理延迟,ImageNet-1K 的 top-1 准确率达到 78.5%,在速度和精度上均优于 MobileViT-v2 和 EfficientFormer。

ABSTRACT

Self-attention has become a defacto choice for capturing global context in various vision applications. However, its quadratic computational complexity with respect to image resolution limits its use in real-time applications, especially for deployment on resource-constrained mobile devices. Although hybrid approaches have been proposed to combine the advantages of convolutions and self-attention for a better speed-accuracy trade-off, the expensive matrix multiplication operations in self-attention remain a bottleneck. In this work, we introduce a novel efficient additive attention mechanism that effectively replaces the quadratic matrix multiplication operations with linear element-wise multiplications. Our design shows that the key-value interaction can be replaced with a linear layer without sacrificing any accuracy. Unlike previous state-of-the-art methods, our efficient formulation of self-attention enables its usage at all stages of the network. Using our proposed efficient additive attention, we build a series of models called "SwiftFormer" which achieves state-of-the-art performance in terms of both accuracy and mobile inference speed. Our small variant achieves 78.5% top-1 ImageNet-1K accuracy with only 0.8 ms latency on iPhone 14, which is more accurate and 2x faster compared to MobileViT-v2. Code: https://github.com/Amshaker/SwiftFormer

研究动机与目标

  • 为解决视觉变换器中自注意力机制的高计算成本,尤其是在移动设备上的问题。
  • 在保持或提升准确率的同时,消除自注意力中昂贵的矩阵乘法操作。
  • 使自注意力机制能够应用于视觉变换器主干网络的所有阶段,而不仅限于后期的低分辨率阶段。
  • 为实时移动视觉应用实现更优的速度-精度权衡。
  • 开发一种通用且高效的主干模型,适用于资源受限设备上的多样化视觉任务。

提出的方法

  • 提出一种高效的加法注意力机制,用线性逐元素运算替代查询-键-值的矩阵乘法。
  • 将自注意力分解为查询-键交互与可学习的线性投影两步,消除显式的键-值交互。
  • 仅通过查询和键特征进行逐元素乘法计算上下文向量,将计算复杂度降低至线性时间。
  • 设计轻量级的注意力模块,兼容视觉变换器的所有阶段,实现在网络中全程的全局上下文建模。
  • 通过堆叠所提出的高效注意力模块,构建一系列名为 SwiftFormer 的模型家族,专为移动推理优化。
  • 在 ImageNet-1K、COCO 和 ADE20K 基准上进行训练与评估,验证其在分类、检测和分割任务中的性能表现。
Figure 1 : Latency vs Accuracy Comparison . Compared to the recent EfficientFormer-L1 [ 20 ] , our SwiftFormer-L1 achieves an absolute gain of 1.7% in terms of top-1 accuracy with the same latency and without requiring any neural architecture search.
Figure 1 : Latency vs Accuracy Comparison . Compared to the recent EfficientFormer-L1 [ 20 ] , our SwiftFormer-L1 achieves an absolute gain of 1.7% in terms of top-1 accuracy with the same latency and without requiring any neural architecture search.

实验结果

研究问题

  • RQ1自注意力能否被优化到足够高效,实现在移动设备上的实时部署而不损失准确率?
  • RQ2自注意力的二次复杂度能否被降低至线性复杂度,同时保持全局上下文建模能力?
  • RQ3高效的注意力机制能否应用于视觉变换器的所有阶段,而不仅限于后期的低分辨率阶段?
  • RQ4在自注意力中用逐元素运算替代矩阵乘法,是否能在移动硬件上带来更优的速度-精度权衡?
  • RQ5针对移动设备优化的视觉变换器主干模型能否在准确率和延迟两方面均超越现有 SOTA 模型(如 MobileViT-v2 和 EfficientFormer)?

主要发现

  • SwiftFormer-L1 在 iPhone 14 上实现了 78.5% 的 ImageNet-1K top-1 准确率,推理延迟仅为 0.8 ms,速度和准确率均优于 MobileViT-v2。
  • SwiftFormer 的小型模型比 MobileViT-v2 快 2 倍,且准确率高出 0.5%,比 MobileViT-v2 ×2.0 快 3 倍,准确率提升 1.8%。
  • SwiftFormer-L3 在 iPhone 14 上实现了 83.0% 的 top-1 准确率,推理延迟为 1.9 ms,创下移动视觉模型的新 SOTA 记录。
  • 在 COCO 目标检测任务中,SwiftFormer-L1 实现 41.2 AP box,较 EfficientFormer-L1 提升 3.3 分,较 ResNet18 提升 7.2 分。
  • 在实例分割任务中,SwiftFormer-L1 实现 38.1 AP mask,较之前 SOTA 模型高出 2.7 分。
  • 在 ADE20K 语义分割任务中,SwiftFormer-L1 实现 41.4% mIoU,较 EfficientFormer-L1 高出 2.5 个百分点,较 ResNet18 高出 8.5 个百分点。
Figure 2 : Comparison with different self-attention modules . (a) is a typical self-attention used in ViTs [ 9 ] . (b) is the transpose self-attention used in EdgeNeXt [ 29 ] , where the self-attention operation is applied across channel feature dimensions (d $\times$ d) instead of the spatial dimen
Figure 2 : Comparison with different self-attention modules . (a) is a typical self-attention used in ViTs [ 9 ] . (b) is the transpose self-attention used in EdgeNeXt [ 29 ] , where the self-attention operation is applied across channel feature dimensions (d $\times$ d) instead of the spatial dimen

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。