FlashAttention-v1回顾
我们先快速回顾一下V1的运作流程:以K,V为外循环,Q为内循环。
FlashAttention-v2
FlashAttention V2 出自论文(《FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning》)[https://arxiv.org/pdf/2307.08691], 主要改进包括:
- 优化计算次序,减少非矩阵计算量。
- 增加 seq_len 维度的并行计算,提升 SM 利用率。
- 优化 warp 级工作模式,减少内部通信和 shared memory 访问。
FlashAttention-v3
Flash Attention V3 出自论文(《FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision》)[https://arxiv.org/pdf/2407.08608],主要改进如下:
引入生产者-消费者异步机制,提升并行度。 优化 GEMM 和 Softmax 操作的重叠计算。 支持 FP8 低精度硬件加速,提升吞吐量并减少精度损失。
参考: > 图解大模型计算加速系列:Flash Attention V2,从原理到并行计算: https://zhuanlan.zhihu.com/p/691067658