高效调度 Flash Attention 以处理部分填充的注意力掩码
Efficiently Dispatching Flash Attention For Partially Filled Attention Masks
AI总结:
针对 Flash Attention 处理稀疏注意力掩码仍具二次复杂度的问题,提出掩码感知的 Binary Block Masking 方法及两种优化方案,实现最高 9 倍运行时间提升。
摘要:
Transformers 广泛应用于各种场景,其中许多会产生稀疏或部分填充的注意力矩阵。例如旨在降低注意力二次复杂度的注意力掩码、序列打包技术,以及 MEDUSA 中用于快速验证的树形掩码等近期创新。尽管这些矩阵具有内在稀疏性,但最先进的算法 Flash Attention 仍将其视为稠密矩阵,以二次复杂度进行处理。本文引入了 Binary Block Masking,这是一种高效的改进方法,通过使其具备掩码感知能力来增强 Flash Attention。我们进一步提出了两种优化方案:一种专为具有连续非零模式的掩码设计,另一种用于极稀疏掩码。在基于真实场景的注意力掩码上的实验表明,运行时间提升了 9 倍。该实现将公开发布以促进进一步研究与应用。
英文摘要:
Transformers are widely used across various applications, many of which yield sparse or partially filled attention matrices. Examples include attention masks designed to reduce the quadratic complexity of attention, sequence packing techniques, and recent innovations like tree masking for fast validation in MEDUSA. Despite the inherent sparsity in these matrices, the state-of-the-art algorithm Flash Attention still processes them with quadratic complexity as though they were dense. In this paper, we introduce Binary Block Masking, a highly efficient modification that enhances Flash Attention by making it mask-aware. We further propose two optimizations: one tailored for masks with contiguous non-zero patterns and another for extremely sparse masks. Our experiments on attention masks derived from real-world scenarios demonstrate up to a 9x runtime improvement. The implementation will be publicly released to foster further research and application.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。