---
name: flashattention-resources
---

# FlashAttention 学习资源

## 必读论文（Primary Sources）

1. **FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness**  
   Tri Dao et al., NeurIPS 2022. arXiv:2205.14135  
   <https://arxiv.org/abs/2205.14135>  
   *首次提出 tiling + online softmax + recomputation，奠定 IO-aware attention 基础。*

2. **FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning**  
   Tri Dao, 2023. arXiv:2307.08691  
   <https://arxiv.org/abs/2307.08691>  
   *调整 loop order、减少非 matmul 开销、提升 warps 并行度。*

3. **FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision**  
   Jay Shah et al., 2024. arXiv:2407.08608  
   <https://arxiv.org/abs/2407.08608>  
   *面向 Hopper H100：TMA/WGMMA、warp specialization、GEMM-softmax 交错、FP8。*

4. **FlashAttention-4: Algorithm and Kernel Pipelining Co-Design for Asymmetric Hardware Scaling**  
   2026. arXiv:2603.05451  
   <https://arxiv.org/abs/2603.05451>  
   *面向 Blackwell B200：TMEM、2-CTA MMA、LPT 调度、CuTe-DSL。*

## 官方实现

- **Dao-AILab/flash-attention** (GitHub)  
  <https://github.com/Dao-AILab/flash-attention>  
  *官方仓库，包含 FA-1/2/3/4 的 CUDA 实现。*

## 高质量解读与博客

- **Seth Weidman: FlashAttention: Algorithm and Pseudocode**  
  <https://www.sethweidman.com/blog/flash_attention_1.html>  
  *带伪代码和数值示例的算法讲解，适合第一次理解 online softmax。*

- **Damek Davis: Basic idea behind flash attention (V1)**  
  <https://damek.github.io/random/basic-idea-behind-flash-attention/>  
  *简短、直觉化的核心原理解释。*

- **NVIDIA Developer Blog: Tuning Flash Attention for Peak Performance**  
  <https://developer.nvidia.com/blog/tuning-flash-attention-for-peak-performance-in-nvidia-cuda-tile/>  
  *从 kernel tuning 角度讲解 tile size、occupancy、warp partition。*

- **PyTorch Blog: FlashAttention-3**  
  <https://pytorch.org/blog/flashattention-3/>  
  *官方发布博客，解释异步执行、FP8、性能数字。*

- **Together AI Blog: FlashAttention-4**  
  <https://www.together.ai/blog/flashattention-4>  
  *面向 Blackwell 的工程解读。*

## 辅助实现

- **Mog9/FlashAttention-CuPy**  
  <https://github.com/Mog9/FlashAttention-CuPy>  
  *带 CUDA 的 from-scratch 实现，展示 tiling、online softmax 和 backward recomputation。*

- **eunsolch/FlashAttention-pytorch**  
  <https://github.com/PeTeRr0/FlashAttention-pytorch>  
  *PyTorch 版实现，适合先跑通数值正确性。*

- **gitctrlx/flash-attention-tutorial**  
  <https://github.com/gitctrlx/flash-attention-tutorial>  
  *教程型代码仓库。*

## 内部实测（真实 workload kernel-trace）

- **飞书文档：IAW 模型 FA2 vs FA3 性能对比分析**  
  <https://nio.feishu.cn/docx/WoSBd0f6AoowMCxCRvYczrQVnxh>  
  *sequence packing 训练场景下 FA2/FA3 的 kernel-trace 级实测（unpad→varlen→pad 全路径 + Asight Systems 报告）。平台为阿里自研 PPU810E（CUDA 兼容非 NVIDIA），CUTLASS 走 Sm80 路径。关键结论：FA3 eager 快 1.2–2×（CUTLASS kernel 质量），但 torch.compile 反而变慢（triton dispatch + FillFunctor 无法 fuse）；Vision dense 场景 SDPA 比 FA3 更快。Use for: 把"理论性能"拉回现实，做 attention kernel 选型。*

## 前置知识

- **Online normalizer calculation for softmax** (Milakov & Gimelshein, 2018)  
  *online softmax 的数学基础。*

- NVIDIA CUDA 文档：
  - Tensor Memory Accelerator (TMA)
  - Warp Group Matrix Multiply-Accumulate (WGMMA)
  - Hopper / Blackwell architecture guides

## 社区

- **r/MachineLearning**、**r/LocalLLaMA**：讨论 attention 优化和 kernel 实现。
- **GitHub Dao-AILab/flash-attention Issues/PRs**：真实工程问题和性能讨论。
- **CUDA / CUTLASS Discord / NVIDIA Developer Forums**：底层实现问题。

## Gaps

- **PPU810E 公开资料缺失**：阿里自研 PPU810E 的微架构、CUTLASS 适配细节、为何选中 Sm80 路径，目前无公开高信噪比资料。内部 kernel-trace 是唯一信源。后续若涉及该平台 kernel 调优，需补充内部文档或实测。

## 使用建议

- 第一次学：先读 Seth Weidman 的博客，再读 FA-1 论文的 Section 3。
- 想写 kernel：配合 Mog9/FlashAttention-CuPy 或官方仓库的 `flash_attn/flash_attn_cuda.cpython` 实现。
- 想理解版本演进：先掌握 FA-1/2 的算法，再读 FA-3/4 的硬件相关章节。
