SwiftFormer:用于基于Transformer的实时移动视觉应用的高效加性注意力
SwiftFormer: Efficient Additive Attention for Transformer-based Real-time Mobile Vision Applications
AI总结:
本文提出高效加性注意力机制,替代自注意力中的二次矩阵乘法,构建SwiftFormer模型,在移动设备上实现高精度和低延迟,小模型在iPhone 14上达78.5%准确率,延迟0.8ms,比MobileViT-v2快2倍。
摘要:
自注意力已成为各种视觉应用中捕获全局上下文的事实选择。然而,其相对于图像分辨率的二次计算复杂度限制了其在实时应用中的使用,尤其是在资源受限的移动设备上部署时。尽管已经提出了混合方法来结合卷积和自注意力的优势以实现更好的速度-精度权衡,但自注意力中昂贵的矩阵乘法操作仍然是瓶颈。在这项工作中,我们引入了一种新颖的高效加性注意力机制,该机制有效地将二次矩阵乘法操作替换为线性逐元素乘法。我们的设计表明,键值交互可以用线性层替换,而不会牺牲任何精度。与之前最先进的方法不同,我们高效的自注意力公式使其能够在网络的所有阶段使用。利用我们提出的高效加性注意力,我们构建了一系列名为“SwiftFormer”的模型,在准确性和移动推理速度方面均达到了最先进的性能。我们的小型变体在iPhone 14上仅用0.8毫秒延迟就达到了78.5%的ImageNet-1K top-1准确率,与MobileViT-v2相比,准确率更高且速度快2倍。代码:https://github.com/Amshaker/SwiftFormer
英文摘要:
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
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。