FastAttention:将 FlashAttention2 扩展至 NPU 与低资源 GPU
FastAttention: Extend FlashAttention2 to NPUs and Low-resource GPUs
AI总结:
针对FlashAttention难以迁移到NPU和低资源GPU的问题,提出FastAttention,通过两级tiling、tiling-mask、tiling-AllReduce及CPU-GPU协同等策略,在昇腾NPU和Volta GPU上显著提升大模型推理效率。
摘要:
FlashAttention 系列已被广泛应用于大语言模型(LLMs)的推理中。然而,FlashAttention 系列仅支持高端 GPU 架构,例如 Ampere 和 Hopper。目前,FlashAttention 系列难以迁移到 NPU 和低资源 GPU 上。此外,FlashAttention 系列在多 NPU 或多 GPU 推理场景下效率不高。在本工作中,我们提出 FastAttention,率先将 FlashAttention 系列适配到 NPU 和低资源 GPU 上,以提升 LLM 推理效率。具体而言,我们以昇腾 NPU 和基于 Volta 架构的 GPU 为代表来设计 FastAttention。我们通过提出一种新颖的两级 tiling 策略来加速运行时、tiling-mask 策略来节省内存,以及 tiling-AllReduce 策略来减少通信开销,从而将 FlashAttention 系列迁移到昇腾 NPU 上。此外,我们通过重新设计共享内存中的操作数布局,并引入一种简单而有效的 CPU-GPU 协同策略来实现高效内存利用,从而将 FlashAttention 适配到基于 Volta 架构的 GPU 上。在昇腾 NPU 上,与标准注意力实现相比,我们的 FastAttention 可以实现 10.7$\ imes$ 的加速。使用 FastAttention 的 Llama-7B 相比使用标准注意力时吞吐量最高提升 5.16$\ imes$。在 Volta 架构 GPU 上,与 \ exttt{xformers} 中的等价实现相比,FastAttention 实现了 1.43$\ imes$ 的加速。使用 FasterTransformer 时,采用 FastAttention 的 Pangu-38B 带来了 1.46$\ imes$ 的端到端加速。结合所提出的 CPU-GPU 协同策略,FastAttention 在 8 块 V100 GPU 上支持最大 256K 的输入长度。所有代码将很快公开。
英文摘要:
FlashAttention series has been widely applied in the inference of large language models (LLMs). However, FlashAttention series only supports the high-level GPU architectures, e.g., Ampere and Hopper. At present, FlashAttention series is not easily transferrable to NPUs and low-resource GPUs. Moreover, FlashAttention series is inefficient for multi- NPUs or GPUs inference scenarios. In this work, we propose FastAttention which pioneers the adaptation of FlashAttention series for NPUs and low-resource GPUs to boost LLM inference efficiency. Specifically, we take Ascend NPUs and Volta-based GPUs as representatives for designing our FastAttention. We migrate FlashAttention series to Ascend NPUs by proposing a novel two-level tiling strategy for runtime speedup, tiling-mask strategy for memory saving and the tiling-AllReduce strategy for reducing communication overhead, respectively. Besides, we adapt FlashAttention for Volta-based GPUs by redesigning the operands layout in shared memory and introducing a simple yet effective CPU-GPU cooperative strategy for efficient memory utilization. On Ascend NPUs, our FastAttention can achieve a 10.7$\times$ speedup compared to the standard attention implementation. Llama-7B within FastAttention reaches up to 5.16$\times$ higher throughput than within the standard attention. On Volta architecture GPUs, FastAttention yields 1.43$\times$ speedup compared to its equivalents in \texttt{xformers}. Pangu-38B within FastAttention brings 1.46$\times$ end-to-end speedup using FasterTransformer. Coupled with the propose CPU-GPU cooperative strategy, FastAttention supports a maximal input length of 256K on 8 V100 GPUs. All the codes will be made available soon.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。