Skip to main content
QUICK REVIEW

[論文レビュー] FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision

Jay P. Shah, Ganesh Bikshandi|arXiv (Cornell University)|Jul 11, 2024
Computational Physics and Python ApplicationsComputer Science被引用数 14
ひとこと要約

FlashAttention-3 は Hopper GPUs 上でアシンクロニーと FP8 の低精度を活用して attention を高速化し、FlashAttention-2 より 1.5–2.0x FP16 スピードアップを達成、ほぼ 1.2 PFLOPs/s FP8 性能と精度向上を実現。

ABSTRACT

Attention, as a core layer of the ubiquitous Transformer architecture, is the bottleneck for large language models and long-context applications. FlashAttention elaborated an approach to speed up attention on GPUs through minimizing memory reads/writes. However, it has yet to take advantage of new capabilities present in recent hardware, with FlashAttention-2 achieving only 35% utilization on the H100 GPU. We develop three main techniques to speed up attention on Hopper GPUs: exploiting asynchrony of the Tensor Cores and TMA to (1) overlap overall computation and data movement via warp-specialization and (2) interleave block-wise matmul and softmax operations, and (3) block quantization and incoherent processing that leverages hardware support for FP8 low-precision. We demonstrate that our method, FlashAttention-3, achieves speedup on H100 GPUs by 1.5-2.0$ imes$ with FP16 reaching up to 740 TFLOPs/s (75% utilization), and with FP8 reaching close to 1.2 PFLOPs/s. We validate that FP8 FlashAttention-3 achieves 2.6$ imes$ lower numerical error than a baseline FP8 attention.

研究の動機と目的

  • 長-context なトランスフォーマーと新しいモダリティのための高速な attention を動機づける。
  • Hopper GPU の特徴(アシンクロニーと FP8)を活用して attention を再設計する。
  • 低精度での数値誤差を制御しつつスループットを向上させる。

提案手法

  • memory latency と compute latency を隠すために warp-specialization を備えた producer-consumer asynchronous を導入する。
  • WGMMA ベースの GEMM の 2-stage(および 3-stage)パイプライン化により GEMM と softmax を重ね合わせる。
  • ブロック量子化と非整合処理でハードウェア加速の FP8 GEMM を利用し、量子化誤差を低減する。
  • FP8 WGMMA の制約を満たすために、カーネル内 V タイル転置とレイアウト適応を適用する。
  • H100 上で FP16/FP8 の比較を FlashAttention-2 および cuDNN と行い、TFLOPs/s とスピードアップを報告する。
  • PyTorch および Hugging Face への統合計画を含むオープンソース実装。
Figure 1 : Pingpong scheduling for 2 warpgroups to overlap softmax and GEMMs: the softmax of one warpgroup should be scheduled when the GEMMs of another warpgroup are running. The same color denotes the same iteration.
Figure 1 : Pingpong scheduling for 2 warpgroups to overlap softmax and GEMMs: the softmax of one warpgroup should be scheduled when the GEMMs of another warpgroup are running. The same color denotes the same iteration.

実験結果

リサーチクエスチョン

  • RQ1アシンクロニーと低精度ハードウェア機能をどのように活用して現代 GPU 上で attention を加速できるか。
  • RQ2前方/後方スループットに対するワープ・特化と GEMM-softmax の重なりが与える影響は。
  • RQ3FP8 ベースの attention が高いスループットを提供しつつ競争力のある精度を達成できるか。
  • RQ4FP8 WGMMA の attention 使用時の実用的なレイアウト/精度制約は何か。
  • RQ5Hopper GPU 上で FlashAttention-3 は既存の GPU 最適化 attention 実装とどのように比較されるか。

主な発見

  • FP16 の FlashAttention-3 は Forward パスで FlashAttention-2 を 1.5–2.0x、Backward パスで 1.5–1.75x のスピードアップを達成。
  • FlashAttention-3 は H100 で FP16 の場合最大 740 TFLOPs/s(75% の実利用率)、FP8 の場合は約 1.2 PFLOPs/s に近い。
  • ブロック量子化と非整合処理を用いた FP8 FlashAttention-3 は、外れ値特徴を含むケースで per-tensor 量子化の標準注意より 2.6x 高精度。
  • 2-stage GEMM-softmax パイプラインと warp-specialization により顕著な速度向上が見られる(例:ablation で 570→661 TFLOPs)。
  • FP16 は中間結果が FP32 のままなので数値的には FlashAttention-2 と同等の精度を維持する一方、FP8 はブロック技術を用いることで基準 FP8 に対する誤差を低減。
  • FlashAttention-3 はオープンソース化されており、PyTorch および Hugging Face への統合を目指す。
Figure 2 : 2-stage WGMMA-softmax pipelining
Figure 2 : 2-stage WGMMA-softmax pipelining

この論文を読む

Nubintのビューアで原文を開き、読みながら気になる箇所をすぐに質問できます。

Nubintでこの論文を読む

このレビューはAIが論文の原文をもとに作成しました。引用する前に原文をご確認ください。