---
title: "FlashAttention-2 — FlashAttention-2"
source: "https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2"
wiki: "systems-analysis.info/int"
article: "FlashAttention-2_—_FlashAttention-2"
language: "ja"
categories:
  - "Category:Japanese"
  - "Category:Large language models"
  - "Category:Machine learning"
revision_id: 2217
wiki_created_at: 2026-09-06T23:00:28Z
wiki_modified_at: 2026-09-06T23:00:28Z
downloaded_at: 2026-09-07T22:49:54Z
---

# FlashAttention-2 — FlashAttention-2

**FlashAttention-2**は、大規模言語モデル (LLM)におけるアテンション機構 (attention) の計算を目的とした改良アルゴリズムです。このアルゴリズムは、スタンフォード大学の研究者である**Tri Dao**によって開発され、2023年7月に発表されました<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_main-1)</sup>。その主な目的は、GPUのハードウェアリソースをより効率的に利用することで、トランスフォーマーモデルの学習と推論を大幅に高速化し、同時に標準的なアテンション機構との計算の完全な同一性、つまり**精度を損なうことなく**維持することです。

FlashAttention-2は、同じチームが2022年に発表したアルゴリズム**FlashAttention**の論理的な後継です。新バージョンは、前身で見られたGPUの不完全な利用という問題を解決し、第1版と比較してほぼ2倍の速度向上を達成しています。

## 背景：トランスフォーマーにおけるアテンションの問題

標準的な自己アテンション (self-attention) 機構は、トランスフォーマーで長いテキストシーケンスを扱う際のボトルネックとなっています。その計算複雑性とメモリ消費量は、シーケンス長 (N) に対して**二次関数的** (O(N²)) に増大するため、LLMの最大コンテキスト長とスケーラビリティに深刻な制約を課しています<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_main-1)</sup>。

この問題を解決するため、2022年に**FlashAttention**アルゴリズムが発表されました<sup>[\[2\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-huggingface_optim-2)</sup>。その主なアイデアは以下の通りです。

- **GPUメモリ階層の考慮 (IO-awareness)**: アルゴリズムは、低速なGPUメモリ (HBM) と高速なオンチップのスタティックメモリ (SRAM) との間で行われる高コストな読み書き操作を最小限に抑えます。
- **ブロック処理 (タイリング)**: 計算を小さなブロック（タイル）に分割し、高速なSRAMで処理することで、完全なアテンション行列をメモリ上に実体化させることを回避します。

これにより、メモリ消費量の**線形**増加 (O(N)) と、標準的な実装と比較して2～4倍の高速化が達成されました<sup>[\[2\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-huggingface_optim-2)</sup>。FlashAttentionは広く普及し、コンテキスト長を大幅に拡大したモデルの登場に貢献しました。例えば、2～4千トークン (GPT-3) から128千トークン (GPT-4) 以上への拡大です<sup>[\[3\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-tridao_blog_fa3-3)</sup>。**Falcon-40B**モデルでは、FlashAttentionを使用することで、推論が3倍、全体的な生成スループットがGPT-3と比較して5倍高速化されました<sup>[\[4\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-e2e_analysis-4)</sup>。

## FlashAttention-2の開発と目標

成功を収めたにもかかわらず、FlashAttentionの第1版はGPUの計算リソースを完全には活用していませんでした。**NVIDIA A100**ビデオカードでは、パフォーマンスは理論上の最大値 (FLOPs/s) の**25–40%**にしか達していませんでした<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_main-1)</sup>。主な原因は、ストリーミングマルチプロセッサ (Streaming Multiprocessors) の最適ではない利用と、共有メモリへの冗長な操作でした<sup>[\[5\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-openreview_fa2-5)</sup>。

**FlashAttention-2**の目標は、作業の並列化をより効率的にし、補助的な操作を最小限に抑えることで、計算をさらに高速化することでした。アルゴリズムは、最高のパフォーマンスを達成するために、低レベルのライブラリ**NVIDIA CUTLASS 3.x**のプリミティブを使用して完全に書き直されました<sup>[\[6\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-hazyresearch_blog-6)</sup>。

## 技術アーキテクチャと動作原理

FlashAttention-2は、並列性と効率を向上させるために、3つの主要な改善点を導入しています<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_main-1)</sup>。

### 1. 非行列演算の最小化

このアルゴリズムは、行列積ではない浮動小数点演算 (non-matmul FLOPs) の数を削減します。GPUのテンソルコアは行列演算 (GEMM) に最適化されており、それを最大16倍高速に実行するため、この変更により、ほとんどの時間を最も高性能なGPUブロックの使用に充てることができます。

### 2. 並列処理の改善

オリジナルのFlashAttentionでは、1つのアテンションヘッドに対する作業は並列化されておらず、長いシーケンス長かつ小さなバッチサイズの場合にアイドル時間が発生していました。FlashAttention-2は**ブロック間並列化**を導入し、1つのアテンションヘッドの計算をGPUの異なるストリーミングマルチプロセッサに分散させることで、それらの使用率を大幅に向上させます。

### 3. ブロック内の作業分割の最適化

1つの計算ブロックレベルで、共有メモリ (shared memory) を介したデータ交換を減らすために、スレッドグループ (warp) 間で作業が再配分されました。これにより、Softmaxの正規化に必要な冗長な読み書き操作の数が減少します。

## パフォーマンスと効率

アーキテクチャの改善により、FlashAttention-2はパフォーマンスを大幅に向上させました。

- **2倍の高速化**: このアルゴリズムは、FlashAttentionの第1版と比較して約**2倍**高速に動作します<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_main-1)</sup>。
- **高いGPU使用率**: **NVIDIA A100** GPUでは、理論上の最大スループット (TFLOPs) の**50–73%**を達成しており、これは最適化された行列積演算 (GEMM) の効率に匹敵します<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_main-1)</sup>。
- **記録的な計算速度**:
  - **A100** GPUでは、GPTタイプのモデルのend-to-end学習サイクルで最大**225 TFLOP/s**の速度を達成し、これは計算ユニット使用率の72%に相当します。比較として、同じ条件下での標準的なアテンションはGPUを100 TFLOP/s未満しか使用していませんでした<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_pdf-7)</sup>。
  - **H100** GPUでは、パフォーマンスは**335 TFLOP/s**に達します<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_pdf-7)</sup>。

このようなパフォーマンス向上により、例えば、以前は**8k**トークンのウィンドウに必要だった時間で、**16k**トークンのコンテキストウィンドウを持つモデルを学習させることが可能になります<sup>[\[5\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-openreview_fa2-5)</sup>。重要なのは、アルゴリズムが**正確**かつ決定論的であり続けるため、その適用がモデルの予測品質に影響を与えないことです<sup>[\[8\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-raschka_blog-8)</sup>。

## 適用とエコシステムへの統合

FlashAttention-2は、LLMエコシステムにおいて急速に標準的なツールとなりました。多くの人気のあるフレームワークやライブラリに統合されています。

- **PyTorch**: ネイティブサポート。
- **Hugging Face Transformers**: モデルをロードする際に \`attn_implementation="flash_attention_2"\` パラメータでサポートが有効になります<sup>[\[9\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-linkedin_younes-9)</sup>。数十のアーキテクチャ (GPT, Llama, Falcon, BERTなど) と互換性があります<sup>[\[10\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-huggingface_gpu_infer-10)</sup>。
- **TensorRT-LLM**, **xFormers**, **Triton**: これらのプラットフォーム向けにアルゴリズムが実装されており、広範な応用が保証されています<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_pdf-7)</sup>。

この統合により、FlashAttention-2を量子化 (GPTQ, QLoRA) や効率的なファインチューニング (PEFT) といった他の最適化手法と容易に組み合わせることができます<sup>[\[9\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-linkedin_younes-9)</sup>。

## 後継バージョンとの比較

### FlashAttention-3

アテンションの最適化に関する研究は続いています。2024年7月、Tri Daoは**FlashAttention-3**を発表しました。これは**NVIDIA Hopper** (H100/H200) GPUアーキテクチャの能力を活用することを目的としています。主な新機能は以下の通りです<sup>[\[3\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-tridao_blog_fa3-3)</sup>。

- **FP8のサポート**: 8ビット浮動小数点演算を使用してさらなる高速化を図ります。
- **非同期操作**: GPUの非同期機能をより効率的に利用します。

FlashAttention-3は、H100 GPU上でFlashAttention-2と比較して**1.5～2倍**の高速化を実現し、最大**740 TFLOP/s** (理論上の最大値の75%) のパフォーマンスを達成します<sup>[\[11\]](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_note-arxiv_fa3-11)</sup>。

## 参考文献

- Dao, T. (2023). *FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning*. <a href="https://arxiv.org/abs/2307.08691" class="external text" rel="nofollow">arXiv:2307.08691</a>.
- Dao, T. et al. (2022). *FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness*. <a href="https://arxiv.org/abs/2205.14135" class="external text" rel="nofollow">arXiv:2205.14135</a>.
- Shah, J. et al. (2024). *FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision*. <a href="https://arxiv.org/abs/2407.08608" class="external text" rel="nofollow">arXiv:2407.08608</a>.
- Kwon, W. et al. (2023). *Efficient Memory Management for Large Language Model Serving with PagedAttention*. <a href="https://arxiv.org/abs/2309.06180" class="external text" rel="nofollow">arXiv:2309.06180</a>.
- Ye, Z. et al. (2025). *FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving*. <a href="https://arxiv.org/abs/2501.01005" class="external text" rel="nofollow">arXiv:2501.01005</a>.
- Chen, Y. et al. (2023). *FlashDecoding++: Faster Large Language Model Inference on GPUs*. <a href="https://arxiv.org/abs/2311.01282" class="external text" rel="nofollow">arXiv:2311.01282</a>.
- Liu, Y. et al. (2024). *FastAttention: Extending FlashAttention-2 to NPUs and Low-Resource GPUs*. <a href="https://openreview.net/forum?id=76NYyOrnfk" class="external text" rel="nofollow">OpenReview: 76NYyOrnfk</a>.
- Dege, P. et al. (2025). *FlashMLA-ETAP: Efficient Transpose Attention Pipeline for Accelerating MLA Inference on NVIDIA H20 GPUs*. <a href="https://arxiv.org/abs/2506.01969" class="external text" rel="nofollow">arXiv:2506.01969</a>.
- Wang, G. et al. (2024). *FlashMask: Efficient and Rich Mask Extension of FlashAttention*. <a href="https://openreview.net/forum?id=rog0J435OO" class="external text" rel="nofollow">OpenReview: rog0J435OO</a>.
- Abbott, V.; Zardini, G. (2025). *FlashAttention on a Napkin: A Diagrammatic Approach to Deep Learning IO-Awareness*. <a href="https://arxiv.org/abs/2412.03317" class="external text" rel="nofollow">arXiv:2412.03317</a>.

## 脚注

1.  <span id="cite_note-arxiv_main-1">↑ <sup>[1.0](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_main_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_main_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_main_1-2)</sup> <sup>[1.3](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_main_1-3)</sup> <sup>[1.4](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_main_1-4)</sup> <sup>[1.5](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_main_1-5)</sup> Dao, Tri. "FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning". *arXiv:2307.08691* \[cs.LG\], July 17, 2023. <a href="https://arxiv.org/abs/2307.08691" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-huggingface_optim-2">↑ <sup>[2.0](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-huggingface_optim_2-0)</sup> <sup>[2.1](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-huggingface_optim_2-1)</sup> “Optimizing LLMs for Speed and Memory”. *Hugging Face Documentation*. <a href="https://huggingface.co/docs/transformers/v4.42.0/en/llm_tutorial_optimization" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-tridao_blog_fa3-3">↑ <sup>[3.0](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-tridao_blog_fa3_3-0)</sup> <sup>[3.1](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-tridao_blog_fa3_3-1)</sup> Dao, Tri. "FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision". *Tri Dao's Blog*. <a href="https://tridao.me/blog/2024/flash3/" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-e2e_analysis-4">[↑](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-e2e_analysis_4-0) “FlashAttention vs FlashAttention-2 - an Analysis”. *E2E Networks Blog*. <a href="https://www.e2enetworks.com/blog/shades-of-attention-flashattention-vs-flashattention-2-a-comprehensive-study" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-openreview_fa2-5">↑ <sup>[5.0](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-openreview_fa2_5-0)</sup> <sup>[5.1](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-openreview_fa2_5-1)</sup> “FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning”. *OpenReview*. <a href="https://openreview.net/forum?id=mZn2Xyh9Ec" class="external autonumber" rel="nofollow">[5]</a></span>
6.  <span id="cite_note-hazyresearch_blog-6">[↑](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-hazyresearch_blog_6-0) “FlashAttention-2”. *Hazy Research, Stanford University*. <a href="https://hazyresearch.stanford.edu/blog/2023-07-17-flash2" class="external autonumber" rel="nofollow">[6]</a></span>
7.  <span id="cite_note-arxiv_pdf-7">↑ <sup>[7.0](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_pdf_7-0)</sup> <sup>[7.1](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_pdf_7-1)</sup> <sup>[7.2](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_pdf_7-2)</sup> Dao, Tri. "FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning" (PDF). *arXiv:2307.08691*. <a href="https://arxiv.org/pdf/2307.08691.pdf" class="external autonumber" rel="nofollow">[7]</a></span>
8.  <span id="cite_note-raschka_blog-8">[↑](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-raschka_blog_8-0) Raschka, Sebastian. “Llama 2 and FlashAttention 2”. *Ahead of AI Magazine*. <a href="https://magazine.sebastianraschka.com/p/research-highlights-in-three-sentences" class="external autonumber" rel="nofollow">[8]</a></span>
9.  <span id="cite_note-linkedin_younes-9">↑ <sup>[9.0](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-linkedin_younes_9-0)</sup> <sup>[9.1](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-linkedin_younes_9-1)</sup> Belkada, Younes. “Faster and more memory efficient models with Flash Attention 2!”. *LinkedIn*. <a href="https://www.linkedin.com/posts/younes-belkada-b1a903145_flashattention-llms-activity-7112061650106474496-1dzz" class="external autonumber" rel="nofollow">[9]</a></span>
10. <span id="cite_note-huggingface_gpu_infer-10">[↑](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-huggingface_gpu_infer_10-0) “GPU inference”. *Hugging Face Documentation*. <a href="https://huggingface.co/docs/transformers/v4.39.0/perf_infer_gpu_one" class="external autonumber" rel="nofollow">[10]</a></span>
11. <span id="cite_note-arxiv_fa3-11">[↑](https://systems-analysis.info/int/FlashAttention-2_%E2%80%94_FlashAttention-2#cite_ref-arxiv_fa3_11-0) Dao, Tri, et al. “FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision”. *arXiv:2407.08608* \[cs.LG\], July 11, 2024. <a href="https://arxiv.org/abs/2407.08608" class="external autonumber" rel="nofollow">[11]</a></span>
