arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2404.02882cs.LGcs.CL
收藏

线性注意力序列并行

Linear Attention Sequence Parallelism

Shanghai AI Laboratory(上海人工智能实验室);TapTap

Weigao Sun, Zhen Qin, Dong Li, Xuyang Shen, Yu Qiao, Yiran Zhong

AI总结:

针对现有序列并行方法未利用线性注意力先右乘特性导致效率不足的问题,提出LASP方法,通过环形通信、核融合等优化,在128GPU上将序列长度扩展至现有方法的8倍,且兼容批量数据并行。

摘要:

序列并行(SP)是处理超出单设备内存限制的长序列的常用策略。然而,对于线性注意力这类线性序列建模方法,现有序列并行方案并未利用其“先右乘”的特性,导致通信效率和可用性未达最优。本文提出线性注意力序列并行(LASP),这是一种专为基于线性注意力的Transformer模型设计的高效序列并行方法。具体而言,我们设计了一种高效的点对点环形通信机制,以利用线性注意力的右乘核技巧,与现有序列并行方法相比,大幅降低了通信开销。我们通过核融合和中间状态缓存提升了LASP的计算效率,使其在GPU上的实现更适配硬件。此外,我们精心确保了序列级LASP与所有类型的批量级数据并行方法兼容,这对于在超长长序列的大规模集群上进行分布式训练至关重要。我们还讨论了LASP在其他线性序列建模方法上的泛化性。我们在基于线性注意力的模型上开展了大量实验,序列长度从2K到4096K不等。LASP在128块GPU上可将序列长度扩展至4096K,是现有序列并行方法的8倍。代码可在https://github.com/OpenNLPLab/LASP获取。

英文摘要:

Sequence parallelism (SP) serves as a prevalent strategy to handle long sequences that exceed the memory limit of a single device. However, for linear sequence modeling methods like linear attention, existing SP approaches do not take advantage of their right-product-first feature, resulting in sub-optimal communication efficiency and usability. In this paper, we introduce Linear Attention Sequence Parallelism (LASP), an efficient SP approach designed for linear attention-based transformer models. Specifically, we design an efficient point-to-point ring-style communication mechanism to leverage the right-product kernel trick of linear attention, which sharply decreases the communication overhead, comparing with existing SP methods. We enhance the computation efficiency of LASP by performing kernel fusion and intermediate state caching, making the implementation of LASP hardware-friendly on GPUs. Furthermore, we meticulously ensure the compatibility of sequence-level LASP with all types of batch-level data parallel methods, which is vital for distributed training on large clusters with very-long sequences. We also discuss the generalization of LASP on other linear sequence modeling methods. Extensive experiments on linear attention-based models are conducted with varying sequence lengths from 2K to 4096K. LASP scales sequence length up to 4096K on 128 GPUs, which is 8$\times$ longer than existing SP methods. Code is available at: https://github.com/OpenNLPLab/LASP.

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

↑