paper-with-me

홈 › Papers

FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning

2023-07-17 · Tri Dao

Scaling Transformers to longer sequence lengths has been a major problem in the last several years, promising to improve performance in language modeling and high-resolution image understanding, as well as to unlock new applications in code, audio, and video generation. The attention layer is the main bottleneck in scaling to longer sequences, as its runtime and memory increase quadratically in the sequence length. FlashAttention exploits the asymmetric GPU memory hierarchy to bring significant memory saving (linear instead of quadratic) and runtime speedup (2-4$\times$ compared to optimized baselines), with no approximation. However, FlashAttention is still not nearly as fast as optimized matrix-multiply (GEMM) operations, reaching only 25-40\% of the theoretical maximum FLOPs/s. We observe that the inefficiency is due to suboptimal work partitioning between different thread blocks and warps on the GPU, causing either low-occupancy or unnecessary shared memory reads/writes. We propose FlashAttention-2, with better work partitioning to address these issues. In particular, we (1) tweak the algorithm to reduce the number of non-matmul FLOPs (2) parallelize the attention computation, even for a single head, across different thread blocks to increase occupancy, and (3) within each thread block, distribute the work between warps to reduce communication through shared memory. These yield around 2$\times$ speedup compared to FlashAttention, reaching 50-73\% of the theoretical maximum FLOPs/s on A100 and getting close to the efficiency of GEMM operations. We empirically validate that when used end-to-end to train GPT-style models, FlashAttention-2 reaches training speed of up to 225 TFLOPs/s per A100 GPU (72\% model FLOPs utilization).

📄 PDF Abstract BibTeX arXiv:2307.08691

Code (6)

dao-ailab/flash-attention 공식 구현 pytorch
ROCm/flash-attention pytorch
facebookresearch/xformers/blob/main/xformers/ops/fmha/flash.py pytorch
jundaf2/INT8-Flash-Attention-FMHA-Quantization
pytorch/pytorch/blob/main/torch/nn/functional.py jax
tlc-pack/libflash_attn

Tasks

GPULanguage ModelingLanguage Modelling

Methods 이 논문이 사용한 방법론

SPEED The monocular depth estimation (MDE) is the task of estimating depth from a single frame. This information is an essential knowledge in many computer vision tasks such as scene…

Similar Papers 제목 키워드 기반

FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness

2022-05-27 · Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra 외

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 …

16k4kDocument ClassificationGPU+2

INT-FlashAttention: Enabling Flash Attention for INT8 Quantization

2024-09-25 · Shimao Chen, Zirui Liu, Zhiying Wu, Ce Zheng 외

As the foundation of large language models (LLMs), self-attention module faces the challenge of quadratic time and memory complexity with respect to sequence length. FlashAttention accelerates attention computation and r…

GPUQuantization

FlashAttention for Scalable Vector Architectures

2026-08-19 · Sonia Rani Gupta, Nikela Papadopoulou, Miquel Pericàs arxiv

Inference with transformer models on CPUs is increasingly important, especially for Small Language Models (SLMs), where vector architectures are emerging as a promising execution substrate. The attention module is a majo…

FastAttention: Extend FlashAttention2 to NPUs and Low-resource GPUs

2024-10-22 · Haoran Lin, Xianzhi Yu, Kang Zhao, Lu Hou 외

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, FlashAtt…

CPUGPU

DualKV: Shared-Prompt Flash Attention for Efficient RL Training with Large Rollouts and Long Contexts

2026-05-14 · Jiading Gai, Shuai Zhang, Xiang Song, Bernie Wang 외 arxiv

Modern RL post-training methods such as GRPO and DAPO train on N response sequences of R tokens sampled from a shared prompt of P tokens, but standard FlashAttention replicates all P prompt tokens N times across both for…