Transformers are slow and memory-hungry on long sequences, since the time and memory complexity of self-attention are quadratic in sequence length. Approximate attention methods have attempted to address this problem by trading off model quality to reduce the compute complexity, but often do not achieve wall-clock speedup. We argue that a missing principle is making attention algorithms IO-aware -- accounting for reads and writes between levels of GPU memory. We propose FlashAttention, an IO-aware exact attention algorithm that uses tiling to reduce the number of memory reads/writes between GPU high bandwidth memory (HBM) and GPU on-chip SRAM. We analyze the IO complexity of FlashAttention, showing that it requires fewer HBM accesses than standard attention, and is optimal for a range of SRAM sizes. We also extend FlashAttention to block-sparse attention, yielding an approximate attention algorithm that is faster than any existing approximate attention method. FlashAttention trains Transformers faster than existing baselines: 15% end-to-end wall-clock speedup on BERT-large (seq. length 512) compared to the MLPerf 1.1 training speed record, 3$\times$ speedup on GPT-2 (seq. length 1K), and 2.4$\times$ speedup on long-range arena (seq. length 1K-4K). FlashAttention and block-sparse FlashAttention enable longer context in Transformers, yielding higher quality models (0.7 better perplexity on GPT-2 and 6.4 points of lift on long-document classification) and entirely new capabilities: the first Transformers to achieve better-than-chance performance on the Path-X challenge (seq. length 16K, 61.4% accuracy) and Path-256 (seq. length 64K, 63.1% accuracy).
翻译:64 变异器在长序列上是缓慢的,而记忆-饥饿是长序列上是缓慢的,因为自我注意的时间和记忆复杂性在序列长度上是四倍的。 近距离关注方法试图通过交换模型质量来解决这一问题,以减少计算复杂性,但往往没有实现倒时钟加速。 我们争论说, 缺少的原则是关注算法 IO- 觉 -- 计算读数和写数在 GPU 记忆级别之间的值。 我们提议了 FlashAtention, 一种IO- 觉觉察精确的注意算法, 用来降低GPU高带内存(HBMB) 和 GPUT Streal Right SRA 之间的记忆读数( HBM) 。 我们分析了 IMO 复杂性, 显示它需要比标准关注范围少的 HBBMBM- 2- TL) 递增速度( K- Trightal- moreal- deal- deal- deal- deal- deal- dreal- dreal lax) 16 K- dreal- dreal- dreal- dreal- dreal- dreal- dreax 和在1 K- dreal- drealdalx 和1 K- dreal- dreald- drealx 和1 Kxx 上, 在1 K- devalx 上, 和1 K- slock- devalxxxx 上, 16- devit- devalx 和1 Kx 和1 Kx 和1x 上, 和1 K- deval-l-l-l-l-l-l-l-l-l-l-l-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 上, 上, 上, 16-l-l-lxxxxxxxxxxxxxxxxxx, 16-lx, 16-l-l-l-l-l-l