通过用 GEMM 隐藏 RNG 来降低 Flash-Attention 中 Dropout 的开销
Reducing the Cost of Dropout in Flash-Attention by Hiding RNG with GEMM
AI总结:
本文提出将 Flash-Attention 中的 RNG 与前序 GEMM 层重叠执行以隐藏 Dropout 的随机数生成延迟,并通过细粒度分析性能模型验证其在 Llama3/GH100 上相比顺序实现和融合实现分别获得 1.26 倍和 1.22 倍加速。
摘要:
Dropout 是一种网络算子,启用后很可能会显著影响 Flash-Attention 的性能,进而增加大语言模型(LLMs)的端到端训练时间。造成这种性能下降的主要因素是随机数生成(RNG)阶段。目前最先进的优化方法是将 RNG 融合到 Flash-Attention 内核中。然而,尽管 RNG 和 Attention 在计算或内存资源上并不竞争,但它们受限于相同的底层架构瓶颈。融合很难在 Attention 内核中隐藏 RNG 延迟。我们提出将 RNG 与网络中先前的 GEMM 层重叠执行,以隐藏 RNG 延迟并提高端到端性能。RNG 和 GEMM 具有不同的资源需求和硬件瓶颈,因此它们可以一起运行而不会损害彼此的性能。我们提出了一个细粒度的分析性能模型,该模型分析底层架构资源利用率,以评估 RNG-GEMM 重叠的性能收益。该模型经芯片实测结果交叉验证,显示在一个 Transformer Block(一个包含多头注意力和前馈层的 LLM 层)上,RNG 和 GEMM 层重叠执行相比顺序实现可获得 1.26 倍的加速,相比最先进的融合实现可获得 1.22 倍的加速,该结果针对 GH100 GPU 上使用 FP8 精度的 Llama3。由于内核模式具有规律性,关于共享瓶颈的发现以及可实现的性能收益可以推广到不同的模型架构、软件实现和硬件配置。
英文摘要:
Dropout, a network operator, when enabled is likely to dramatically impact the performance of Flash-Attention, which in turn increases the end-to-end training time of Large-Language-Models (LLMs). The main contributor to such performance degradation is the Random Number Generation (RNG) phase. The state-of-the-art optimization is to fuse RNG into the Flash-Attention kernel. However, while RNG and Attention do not compete on compute or memory resources, they are bounded on the same lower-level architecture bottlenecks. Fusion can hardly hide RNG latency within the Attention kernel. We propose overlapping RNG with previous GEMM layers in the network to hide RNG latency and improve end-to-end performance. RNG and GEMM have distinct resource requirements and hardware bottlenecks, so they can run together without compromising each other's performance. We propose a fine-grained analytical performance model that analyzes low-level architecture resource utilization to evaluate RNG-GEMM overlapping performance benefits. This model, cross-validated by silicon results, shows 1.26x speedup for overlapping RNG and GEMM layers over a sequential implementation on one Transformer Block (one LLM layer including multi-head attention and feed-forward layers), and 1.22x over state-of-the-art fusion implementation, for Llama3 on GH100 GPUs with FP8 precision. Because the kernel patterns are regular, the findings of the shared bottlenecks, as well as the achievable performance benefits, can be generalized to different model architectures, software implementations and hardware configurations.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。