arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2503.14376cs.LGcs.AI
收藏

分块式Flash线性注意力:更高效的线性RNN和xLSTM内核

Tiled Flash Linear Attention: More Efficient Linear RNN and xLSTM Kernels

ELLIS Unit, LIT AI Lab, Institute for Machine Learning, JKU Linz(ELLIS单位、LIT人工智能实验室、机器学习研究所、JKU林茨);NXAI GmbH(NXAI公司)

Maximilian Beck, Korbinian Pöppel, Phillip Lippe, Sepp Hochreiter

AI总结:

TFLA通过引入序列并行化提升线性RNN和xLSTM内核效率,实现更高算术强度和更优长上下文序列建模性能。

摘要:

线性RNN结合门控最近在语言建模中展示了与Transformer竞争的性能。尽管其在序列长度上的线性计算扩展提供了理论上的运行时间优势,但实际实现这些好处需要优化的定制内核,因为Transformer依赖于高效的Flash Attention内核(Dao,2024)。利用线性RNN的分块并行公式,Flash Linear Attention(FLA)(Yang & Zhang,2024)表明线性RNN内核比Flash Attention更快,通过在输入序列的分块上并行化。然而,由于FLA的分块大小受限,许多中间状态必须在GPU内存中存储。这导致了低算术强度,并引起高内存消耗和I/O成本,尤其是在长上下文预训练中。在本工作中,我们提出了Tiled Flash Linear Attention(TFLA),一种新的线性RNN内核算法,通过在每个分块内引入额外的序列并行化,实现了任意大的分块大小和高算术强度。首先,我们将TFLA应用于具有矩阵内存的xLSTM和mLSTM(Beck等人,2024)。其次,我们提出了一种具有sigmoid输入门和减少计算的mLSTM变体,以实现更快的内核运行时间,同时保持相同的语言建模性能。在我们的速度基准测试中,我们展示了基于TFLA的新型mLSTM内核优于高度优化的Flash Attention、线性注意力和Mamba内核,为高效的长上下文序列建模原语设定了新的状态。

英文摘要:

Linear RNNs with gating recently demonstrated competitive performance compared to Transformers in language modeling. Although their linear compute scaling in sequence length offers theoretical runtime advantages over Transformers, realizing these benefits in practice requires optimized custom kernels, as Transformers rely on the highly efficient Flash Attention kernels (Dao, 2024). Leveraging the chunkwise-parallel formulation of linear RNNs, Flash Linear Attention (FLA) (Yang & Zhang, 2024) shows that linear RNN kernels are faster than Flash Attention, by parallelizing over chunks of the input sequence. However, since the chunk size of FLA is limited, many intermediate states must be materialized in GPU memory. This leads to low arithmetic intensity and causes high memory consumption and IO cost, especially for long-context pre-training. In this work, we present Tiled Flash Linear Attention (TFLA), a novel kernel algorithm for linear RNNs, that enables arbitrary large chunk sizes and high arithmetic intensity by introducing an additional level of sequence parallelization within each chunk. First, we apply TFLA to the xLSTM with matrix memory, the mLSTM (Beck et al., 2024). Second, we propose an mLSTM variant with sigmoid input gate and reduced computation for even faster kernel runtimes at equal language modeling performance. In our speed benchmarks, we show that our new mLSTM kernels based on TFLA outperform highly optimized Flash Attention, Linear Attention and Mamba kernels, setting a new state of the art for efficient long-context sequence modeling primitives.

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

↑