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

Lean Attention:面向Transformer解码阶段的硬件感知可扩展注意力机制

Lean Attention: Hardware-Aware Scalable Attention Mechanism for the Decode-Phase of Transformers

Microsoft(微软公司)

Rya Sanovar, Srikant Bharadwaj, Renee St. Amant, Victor Rühle, Saravan Rajmohan

AI总结:

针对Transformer推理中注意力操作随上下文长度平方增长的延迟问题,提出LeanAttention技术,利用在线softmax结合律和stream-K归约实现解码阶段注意力并行计算,显著提升长上下文下的推理速度。

摘要:

基于Transformer的模型已成为自然语言处理、自然语言生成和图像生成领域应用最广泛的架构之一。当前最先进模型的规模稳步增长,参数量已达数十亿级别。这类巨型模型内存需求极高,即便在GPU等前沿AI加速器上运行,也会产生显著的推理延迟。具体而言,注意力操作的时间和内存复杂度与总上下文长度(即提示词与输出词元的总长度)呈平方关系。因此,业界已提出键值张量缓存、FlashAttention计算等多种优化方案,以满足依赖这类大模型的应用对低延迟的需求,但这些技术并未适配推理过程中不同阶段的计算特性差异。\n为此,我们提出LeanAttention,这是一种面向仅解码器Transformer模型词元生成阶段(解码阶段)的可扩展自注意力计算技术。LeanAttention通过重新设计解码阶段的执行流程,实现了注意力机制在长上下文这一挑战性场景下的可扩展实现。我们发现,在线softmax的结合律可被视为一种归约操作,从而使我们能够在长上下文场景下对注意力计算进行并行化。我们将分块计算的“stream-K”风格归约扩展到自注意力计算中,实现并行运算,最终注意力执行速度相比FlashAttention-2平均提升2.6倍,在512k上下文长度下最高可提升8.33倍。

英文摘要:

Transformer-based models have emerged as one of the most widely used architectures for natural language processing, natural language generation, and image generation. The size of the state-of-the-art models has increased steadily reaching billions of parameters. These huge models are memory hungry and incur significant inference latency even on cutting edge AI-accelerators, such as GPUs. Specifically, the time and memory complexity of the attention operation is quadratic in terms of the total context length, i.e., prompt and output tokens. Thus, several optimizations such as key-value tensor caching and FlashAttention computation have been proposed to deliver the low latency demands of applications relying on such large models. However, these techniques do not cater to the computationally distinct nature of different phases during inference. To that end, we propose LeanAttention, a scalable technique of computing self-attention for the token-generation phase (decode-phase) of decoder-only transformer models. LeanAttention enables scaling the attention mechanism implementation for the challenging case of long context lengths by re-designing the execution flow for the decode-phase. We identify that the associative property of online softmax can be treated as a reduction operation thus allowing us to parallelize the attention computation over these large context lengths. We extend the "stream-K" style reduction of tiled calculation to self-attention to enable parallel computation resulting in an average of 2.6x attention execution speedup over FlashAttention-2 and up to 8.33x speedup for 512k context lengths.

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

↑