arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.12082cs.CLcs.LG
收藏

AdaSplash:自适应稀疏 Flash Attention

AdaSplash: Adaptive Sparse Flash Attention

Universidade de Lisboa(里斯本大学);Unbabel

Nuno Gonçalves, Marcos Treviso, André F. T. Martins

AI总结:

本文提出 AdaSplash,通过混合 Halley-二分算法与自定义 Triton 内核加速 $α$-entmax 自适应稀疏注意力,显著降低长上下文训练的运行时和内存开销。

摘要:

Transformer 中基于 softmax 的注意力机制的计算成本限制了其在长上下文任务中的适用性。自适应稀疏性(其中 $α$-entmax 注意力是一个例子)提供了一种灵活的、依赖于数据的替代方案,但现有实现效率低下,且没有利用稀疏性来获得运行时和内存收益。在本工作中,我们提出了 AdaSplash,它将 GPU 优化算法的效率与 $α$-entmax 的稀疏性优势相结合。我们首先引入一种混合 Halley-二分算法,使计算 $α$-entmax 变换所需的迭代次数减少 7 倍。随后,我们实现自定义 Triton 内核,以高效处理自适应稀疏性。使用 RoBERTa 和 ModernBERT 进行文本分类和单向量检索,以及使用 GPT-2 进行语言建模的实验表明,与现有 $α$-entmax 实现相比,我们的方法在运行时和内存效率方面取得了显著提升。它接近——在某些情况下甚至超过——FlashAttention-2 等高度优化的 softmax 实现的效率,从而能够在保持强劲任务性能的同时实现长上下文训练。

英文摘要:

The computational cost of softmax-based attention in transformers limits their applicability to long-context tasks. Adaptive sparsity, of which $α$-entmax attention is an example, offers a flexible data-dependent alternative, but existing implementations are inefficient and do not leverage the sparsity to obtain runtime and memory gains. In this work, we propose AdaSplash, which combines the efficiency of GPU-optimized algorithms with the sparsity benefits of $α$-entmax. We first introduce a hybrid Halley-bisection algorithm, resulting in a 7-fold reduction in the number of iterations needed to compute the $α$-entmax transformation. Then, we implement custom Triton kernels to efficiently handle adaptive sparsity. Experiments with RoBERTa and ModernBERT for text classification and single-vector retrieval, along with GPT-2 for language modeling, show that our method achieves substantial improvements in runtime and memory efficiency compared to existing $α$-entmax implementations. It approaches -- and in some cases surpasses -- the efficiency of highly optimized softmax implementations like FlashAttention-2, enabling long-context training while maintaining strong task performance.

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

↑