ImportError: cannot import name 'flash_attn_unpadded_func' (or FlashMHA, flash_attn_varlen_func, any name) from 'flash_attn...': which flash-attn releases have it
flash-attn 2.0 (2023-07-24 for 2.0.1, the first 2.x release on PyPI) renamed flash_attn_unpadded_func, flash_attn_unpadded_kvpacked_func and flash_attn_unpadded_qkvpacked_func to flash_attn_varlen_func, flash_attn_varlen_kvpacked_func and flash_attn_varlen_qkvpacked_func, and removed flash_attn.flash_attention (FlashAttention, FlashMHA); 1.0.9 is the last release with the old names. The first seven arguments are the same, so renaming the import is usually the whole fix; only deterministic is missing in 2.0 to 2.3. The opposite error, from flash_attn import flash_attn_func failing, means a 1.x install. For any other name, in any module of flash-attn, paste the error below.
Corrected on 2026-12-05: this page read only the first release of each minor version, so a name or module added or removed in a patch release was dated to the next minor. For example, the module flash_attn.models.llama is in 1.0.4 (2023-04-26) and later 1.0.x, not only from 2.0.1. Every release was then read once from PyPI: 4 top-level names (and 437 module-and-name pairs in all) differ in some patch release from the first release of the same minor. The lookup now gives those patch releases. The per-minor ranges are unchanged.
Examples:
Runs in your browser on flash_attn.json (68 KB); nothing you paste is sent anywhere. Covers 24 top-level names and 1,652 module-and-name pairs in 91 modules.
What did flash-attn 2.0 rename?
The 1.x names and their 2.x replacements; the new functions are also importable from flash_attn itself.
| 1.x (to 1.0.9) | 2.0 and later |
|---|---|
flash_attn_unpadded_func | flash_attn_varlen_func |
flash_attn_unpadded_kvpacked_func | flash_attn_varlen_kvpacked_func |
flash_attn_unpadded_qkvpacked_func | flash_attn_varlen_qkvpacked_func |
flash_attn.flash_attention.FlashAttention, FlashMHA | flash_attn.modules.mha.MHA or the functions above |
Names that need a newer 2.x (the first release of each minor version that has them):
| Import | From | Date (PyPI) |
|---|---|---|
from flash_attn import flash_attn_func | 2.0.1 | 2023-07-24 |
from flash_attn import flash_attn_varlen_func | 2.0.1 | 2023-07-24 |
from flash_attn import flash_attn_with_kvcache | 2.2.0 | 2023-09-06 |
How do I read the error?
- "cannot import name" is a version mismatch between the code and flash-attn; this page answers it.
- "undefined symbol" in
flash_attn_2_cudais a different problem: the compiled extension was built for another PyTorch or CUDA. Reinstall flash-attn against the PyTorch you have (or use a prebuilt wheel that names your PyTorch and CUDA versions). - From 2.7.3 the extension module is imported as
flash_attn_gpuinsideflash_attn_interface(it wasflash_attn_cuda); code that imported that internal name breaks there.
How was this read, and how was it checked?
From the source of each release tag of Dao-AILab/flash-attention, with Python's ast module; no release was installed, imported or compiled. A module's names are everything it binds at module level and what from .x import * brings in; code under if TYPE_CHECKING: is skipped. Dates come from PyPI.
Checks: (1) each of the 24 top-level names is found as plain text in flash_attn/__init__.py in every release of its range (239 name-and-release pairs) and not on either side (8 edges). (2) A regular expression finds 1,742 definitions in 251 file versions; all are among the names read. (3) 10 release checks by plain-text search in the tags agree:
| Name | Release | Text and data |
|---|---|---|
flash_attn.flash_attn_interface.flash_attn_unpadded_func | 1.0.0 | has it |
flash_attn.flash_attn_interface.flash_attn_unpadded_func | 2.0.1 | does not |
flash_attn.flash_attn_interface.flash_attn_varlen_func | 2.0.1 | has it |
flash_attn.flash_attn_interface.flash_attn_varlen_func | 1.0.0 | does not |
flash_attn.flash_attn_func | 2.0.1 | has it |
flash_attn.flash_attn_func | 1.0.0 | does not |
flash_attn.flash_attention.FlashMHA | 1.0.0 | has it |
flash_attn.flash_attention.FlashMHA | 2.0.1 | does not |
flash_attn.flash_attn_interface.flash_attn_with_kvcache | 2.2.0 | has it |
flash_attn.flash_attn_interface.flash_attn_with_kvcache | 2.1.0 | does not |
Limits
- Nothing was installed, compiled or run. "Has it" means the import statement resolves in the Python source; whether the CUDA extension builds for your GPU is not covered.
- The ranges use the first release of each minor version on PyPI (and the newest). Every release was also read once (55 releases, from the source archives on PyPI, with the same rules): 4 top-level names and 437 module-and-name pairs in all differ in some patch release from the first release of their minor. The lookup prints those patch releases under the range. Some of those archives hold files that the git tags do not (test and scratch modules); a difference that comes only from that is left out.
- FlashAttention-3 (the
hopper/directory of the repository) is built and installed separately and is not covered.
Questions
How do I fix "cannot import name 'flash_attn_unpadded_func' from 'flash_attn.flash_attn_interface'"?
flash-attn 2.0 renamed it to flash_attn_varlen_func (and the kvpacked and qkvpacked variants the same way); 1.0.9 is the last 1.x release with the old names. Change the import, or pin pip install "flash-attn<2.0" for code you cannot change. The first seven arguments are the same; 2.0 to 2.3 have no deterministic argument (the 2.4 series has it again).
Where did FlashMHA and flash_attn.flash_attention go?
flash-attn 2.0 removed the flash_attn.flash_attention module with FlashAttention and FlashMHA. flash_attn.modules.mha.MHA is the module that remains, or call flash_attn_func directly.
Why does "from flash_attn import flash_attn_func" fail?
The installed flash-attn is 1.x, which did not export it at the top level (the first release read that does is 2.0.1). If the error is an undefined symbol in flash_attn_2_cuda instead, the build does not match your PyTorch; that is not an import-name problem and reinstalling flash-attn against your PyTorch fixes it.
Does this page cover flash_attn.modules, flash_attn.ops and the AMD Triton backend?
Yes: every module of flash-attn from 0.2.1 to 2.8.3, 1,652 module-and-name pairs in 91 modules.
Sources
- Dao-AILab/flash-attention, release tags v0.2.1 to v2.8.3: every
.pyfile under flash_attn/, for example flash_attn_interface.py at v1.0.9 and at v2.0.1; release dates from PyPI.
The same data as JSON: flash_attn.json, licensed CC BY 4.0.
Related: "No module named 'triton.ops'" · "cannot import name ... from 'vllm'" · "... from 'transformers'".