arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2501.06480cs.CV
收藏

Flash Window Attention:加速Swin Transformer的注意力计算

Flash Window Attention: speedup the attention computation for Swin Transformer

Zhendong Zhang

AI总结:

针对Swin Transformer窗口注意力无法直接适配flash attention的问题,提出定制化的Flash Window Attention方案,大幅提升注意力计算效率与端到端运行效率。

摘要:

为应对图像像素的高分辨率问题,Swin Transformer引入了窗口注意力机制。该机制将图像划分为互不重叠的窗口,并将注意力计算限制在每个窗口内部,显著提升了计算效率。为进一步优化这一过程,可考虑用已在语言模型中被证明更高效的flash attention(闪存注意力)替换标准注意力,但直接替换并无效果。flash attention是为长序列设计的,而窗口注意力处理的是更短的序列,且必须并行处理大量此类短序列。本报告提出了一种专为窗口注意力定制的优化方案Flash Window Attention。该方案将注意力计算效率提升最高达300%,端到端运行时效率提升最高达30%。我们的代码已在线公开。

英文摘要:

To address the high resolution of image pixels, the Swin Transformer introduces window attention. This mechanism divides an image into non-overlapping windows and restricts attention computation to within each window, significantly enhancing computational efficiency. To further optimize this process, one might consider replacing standard attention with flash attention, which has proven to be more efficient in language models. However, a direct substitution is ineffective. Flash attention is designed for long sequences, whereas window attention deals with shorter sequences but must handle numerous of them in parallel. In this report, we present an optimized solution called Flash Window Attention, tailored specifically for window attention. Flash Window Attention improves attention computation efficiency by up to 300% and enhances end-to-end runtime efficiency by up to 30%. Our code is available online.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑