Common response
We thank the reviewers for insightful comments and constructive feedback. We are happy that reviews were positive, and that reviewers thought that our work addresses an important problem and results in useful software artifacts benefiting researchers and practitioners, and that our paper was clear and well-written.
We first report some updates, address a few common questions, and then respond to specific questions from the reviewers.
We are happy to report several updates to FlashAttention-2 (FA2) since submission. We are happy to see that FA2 has already begun making an impact in a short time:
* **Getting FlashAttention-2 into people’s hands**: we have been working with the Pytorch and Huggingface developers to integrate FA2 into these widely-used libraries. FA2 is available through torch.nn.Transformer and torch.nn.functional.scaled_dot_product_attention (available now on torch-nightly, slated for PyTorch 2.2 release), as well as Huggingface’s implementation of many popular models (e.g. Llama) in the `transformers` library. FA2 is also integrated into many inference libraries (Nvidia’s TensorRT-LLM, Huggingface’s Text Generation Inference), as well as many finetuning libraries (fastchat, axolotl). This has benefitted a large audience of researchers and practitioners, as well as AI enthusiasts and developers building applications on top of large language models and diffusion models.
* **Implementations on other hardwares**: Though our work presented in this paper focuses on Nvidia GPUs, the general ideas can apply to other hardware accelerators. FA2 has been independently implemented in Jax (through Pallas, a high-level language embedded in Python) that can run on both Nvidia GPUs and TPUs. Thanks to the effort of the OpenAI Triton team and developers from AMD and Intel, FA2 is also independently implemented in the Triton language with backends that run on AMD GPUs (e.g. MI250 and MI300) and Intel CPUs and GPUs.
* **Latest MLPerf training benchmark**: MLPerf is an industry-wide benchmark on the latest hardware and best software implementations of ML models. In MLPerf training 3.1 (Oct-Nov 2023), FA2 was a component of the fastest GPT3 (175B) implementation on H100 GPUs and on TPU v5e, as well as a component to achieve the fastest training of the Stable Diffusion v2 model on H100 GPUs. We are happy to see that our conceptually simple approach is making progress on a well-studied problem, benefiting several important applications.
* **Collaborations on open source models**: We have collaborated with several organizations to add new features to FA2 and use it to train open source models. As an example, FA2 with local (i.e. sliding-window) attention was used to train the Mistral-7B model, arguably one of the strongest open source LLMs currently. Mistral-7B enabled AI researchers and developers to study and deploy much smaller open models with comparable capabilities to larger-scale or proprietary models.
We now address some common questions about our contributions.
**Ablation: contribution of different techniques**
We ablate the effectiveness of our three techniques: (1) fewer non-matmul FLOPs (2) threadblock parallelism (3) warp partitioning to reduce communication. Threadblock parallelism is most important in the case of small batch size and number of heads (common in training large models distributed across many accelerators), since FlashAttention suffers from low occupancy there (not using all the streaming multiprocessors on the GPUs due to not enough parallel work). In other cases, better warp partitioning plays a major role in speeding up the computation, since one of the bottlenecks of FlashAttention is communication between different warps through shared memory. Fewer non-matmul FLOPs are always helpful.
We measure speed for the attention forward pass, with causal mask, head dimension 128, sequence length 2048, on an A100 80GB SXM4 GPU. We consider two setting:
(A) large batch size x number of heads: we set batch size = 8 and number of heads = 16
| Method | Speed (TFLOPs/s) |
|-------------------------------------------- | ------------------|
| FlashAttention | 65 |
| + (1) Fewer non-matmul FLOPs | 91 (1.4x) |
| + (1) + (2) Threadlbock paralelism | 110 (1.2x) |
| + (1) + (2) + (3) Better warp partitioning | 187 (1.7x) |
(B) small batch size x number of heads: we set batch size = 1 and number of heads = 16
| Method | Speed (TFLOPs/s) |
|-------------------------------------------- | ------------------|
| FlashAttention | 23 |
| + (1) Fewer non-matmul FLOPs | 32 (1.4x) |
| + (1) + (2) Threadlbock paralelism | 103 (3.2x) |
| + (1) + (2) + (3) Better warp partitioning | 143 (1.4x) |