Dao-AILab/flash-attention
Fast and memory-efficient exact attention
What it solves
FlashAttention 是為了讓 Transformer 中的 attention 機制變得更快速且更節省記憶體而設計的。它解決了記憶體與時間隨序列長度呈二次方增長的縮放問題,這通常會減慢 LLM 在處理長序列時的速度。
How it works
它實作了一種 IO-aware 的精確 attention 演算法,可以減少 GPU 高頻寬記憶體與其片上 SRAM 之間的記憶體讀寫次數。該專案提供了多個版本 (FlashAttention-2, 3, and 4) 進行增強優化,以適應不同的 GPU 架構,包括 NVIDIA Ampere, Ada, Hopper, and Blackwell, 以及透過 Triton 和 Composable Kernel 後端提供的 AMD ROCm 支援。
Who it’s for
它主要針對的是正在構建或訓練大型語言模型的 AI 研究員與工程師,他們需要針對現代 GPU 進行 attention 層的優化,以獲得更高的吞吐量與更低的記憶體使用量。
Highlights
- Multi-GPU Architecture Support: NVIDIA (包括 H100/B200) 與 AMD (MI200/MI300) 硬體之優化核心 (kernels)。
- Inference Optimizations: 包括
flash_attn_with_kvcache以實現高效能的增量解碼與原位 (in-place) KV cache 更新。 - Advanced Attention Variants: 支援 causal masking, sliding window local attention, 以及 ALiBi (attention with linear bias)。
- Flexible Head Configurations: 支援 Multi-Query Attention (MQA) 與 Grouped-Query Attention (GQA)。
相關
- 專案
- 專案
- 專案
- 專案
- Dispatch