提出新算法TFLA,让线性RNN在长文本处理上更快更省内存。
Tiled Flash Linear Attention: More Efficient Linear RNN and xLSTM Kernels
- 通过分块内再分片并行,突破传统分块大小限制
- 在长序列上实现比Flash Attention更快的推理速度
- 适合需要高效处理长文本的模型开发者
最近,带门控的线性RNN在语言建模任务中表现媲美Transformer。尽管其计算复杂度随序列长度呈线性增长,理论上优于Transformer,但实际性能依赖于高效自定义核函数,而Transformer已依赖高度优化的Flash Attention核。此前,闪速线性注意力(FLA)通过分块并行实现了线性RNN快于Flash Attention,但受限于分块大小,需在GPU内存中存储大量中间状态,导致算术强度低、内存占用高且输入输出开销大,尤其在长上下文预训练中问题突出。本文提出分块闪速线性注意力(TFLA),引入块内进一步分片的序列并行机制,实现任意大分块和高算术强度。首先,将TFLA应用于带矩阵记忆的xLSTM(mLSTM),其次提出一种带sigmoid输入门且计算量更低的mLSTM变体,在保持同等语言建模性能下进一步加速内核运行。在速度基准测试中,基于TFLA的新mLSTM内核超越高度优化的Flash Attention、线性注意力及Mamba内核,成为长序列高效建模的新标杆。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。