flash-attn
Flash Attention: Fast and Memory-Efficient Exact Attention
What it is and what it does
FlashAttention is a GPU-accelerated library that implements fast, memory-efficient exact attention mechanisms for transformer models. It provides optimized kernels for scaled dot-product attention that reduce memory I/O and improve computational efficiency on modern GPUs. The package includes FlashAttention-2 (optimized for Ampere, Ada, and Hopper architectures) and a beta FlashAttention-3 for Hopper GPUs, with support for both NVIDIA CUDA and AMD ROCm backends.
The library integrates with PyTorch and einops, exposing functions like flash_attn_func and flash_attn_qkvpacked_func that drop in as replacements for standard attention. It supports various attention patterns including causal masking, sliding window attention, multi-query and grouped query attention, dropout, rotary embeddings, and ALiBi. Installation requires compilation against your GPU toolkit, which adds setup complexity but is necessary to generate hardware-specific optimized code.
Use it for:
- Accelerate training and inference of large language models and transformers on NVIDIA A100, RTX 4090, H100, or AMD MI200/MI300 GPUs
- Reduce memory consumption during attention computation, enabling longer sequences or larger batch sizes on the same hardware
- Implement causal attention for autoregressive language model generation with improved efficiency
- Deploy transformer models with lower latency by replacing standard PyTorch attention with optimized FlashAttention kernels
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides optimized GPU implementations of scaled dot-product attention (FlashAttention and FlashAttention-2) that reduce memory usage and improve speed compared to standard attention, with support for NVIDIA CUDA and AMD ROCm.
Yes, if you have a supported GPU (Ampere, Ada, Hopper for CUDA; MI200/MI300 for ROCm) and are training or deploying transformer models where attention is a bottleneck. The high install friction (compilation, GPU toolkit requirements) is justified by significant speed and memory gains. Not worth installing for CPU-only workflows or unsupported GPU architectures (e.g., older Turing GPUs without FlashAttention 1.x).
Install
flash-attn on PyPI
pip
pip install flash-attnuv
uv add flash-attnpoetry
poetry add flash-attnInstalling flash-attn
Before you install
High install friction: requires CUDA 12.0+ or ROCm 6.0+, PyTorch 2.2+, ninja build tool, and compilation from source. Compilation takes 3–5 minutes on well-equipped machines but can exhaust RAM on systems with many CPU cores and <96GB memory; MAX_JOBS environment variable can mitigate this. Package is actively maintained with recent releases.
License in practice
BSD License (permissive): you may use, modify, and distribute the package freely, including in commercial projects, provided you retain the license notice and credit the authors as requested in the repository.
Quickstart
pip install flash-attn --no-build-isolation
from flash_attn import flash_attn_func
# flash_attn_func(q, k, v, dropout_p=0.0, softmax_scale=None, causal=False)
Requires CUDA 12.0+ or ROCm 6.0+, PyTorch 2.2+, ninja build tool, and Linux (Windows support experimental as of v2.3.2). Compilation requires a GPU and appropriate toolkit installed.
Verify before relying
- Exact performance gains over standard attention on specific hardware and sequence lengths
- Compatibility with all transformer architectures and attention variants beyond those documented
- Windows support stability and completeness as of current version
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | high — source build required |
| Runtime dependencies | 2 — torch, einops |
| Maintenance | actively maintained — 64 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 484,138/month — #6,407 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flash_attn-2.8.3.post1.tar.gz
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
flash-attn-4GPU-accelerated attention mechanism…
permissive · top 5,000 on PyPI
ring-flash-attnImplements ring attention with flash attention…
permissive · top 15,000 on PyPI
fa3-fwdProvides a lightweight Flash-Attention-3…
permissive · top 15,000 on PyPI
tokenspeed-mlaProvides optimized MLA (Multi-head Latent…
permissive · top 5,000 on PyPI
sageattentionSageAttention provides quantized attention…
permissive · top 15,000 on PyPI
local-attentionImplements local windowed attention for…
permissive · top 15,000 on PyPI
flashinfer-cubinProvides pre-compiled GPU kernel binaries…
permissive · top 5,000 on PyPI
flashinfer-pythonFlashInfer provides optimized GPU kernels for…
permissive · top 5,000 on PyPI
mamba-ssmMamba-ssm implements state-space model…
permissive · top 15,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI