Free | No tracking | Every fact with a source|German and English

Error / Installation

Transformers: FlashAttention2 has been toggled on, but … flash_attn seems to be not installed (FlashAttention missing)

The script wants to load the model with FlashAttention 2, but the Python package flash-attn is not installed in your environment.

The message

ImportError: FlashAttention2 has been toggled on, but it cannot be used due to the following error: the package flash_attn seems to be not installed. Please refer to the documentation of https://huggingface.co/docs/transformers/perf_infer_gpu_one#flashattention-2 to install Flash Attention 2.

Affects: Python

Why is this happening?

With attn_implementation="flash_attention_2", the code requires a fast attention calculation that comes from the extra package flash-attn. This package has to be built to match CUDA and PyTorch, is mainly intended for Linux, and only runs on newer NVIDIA cards (Ampere, Ada, Hopper, so around an RTX 3090 or 4090). On Windows, the developers say compilation is still not very well tested.

How to fix it

  1. The easiest path: use the version built into PyTorch. Change attn_implementation="flash_attention_2" in the code to attn_implementation="sdpa" or choose this option in the program. The model will run normally with that.
  2. Update Transformers with the kernels add-on in your active venv: pip install -U "transformers[kernels]". Newer versions automatically fall back to a ready-made FlashAttention kernel from the Hugging Face Hub when flash_attention_2 is missing.
  3. You can also request the Hub kernel directly: attn_implementation="kernels-community/flash-attn2". That way you do not have to install flash-attn yourself at all.
  4. Check your graphics card: FlashAttention 2 supports Ampere, Ada, and Hopper (for example RTX 3090, RTX 4090). Older cards like the RTX 20 series or T4 are not supported by the package; use sdpa there.
  5. If you want the real package, install it on Linux or in WSL: requirements are CUDA 12.0 or later, PyTorch 2.2 or later, and ninja (check with ninja --version). Then pip install flash-attn --no-build-isolation. If you have little RAM, use MAX_JOBS=4 pip install flash-attn --no-build-isolation.

Better not: Do not just start building flash-attn on Windows and hope for the best: without ninja, compilation can take around two hours, and sdpa works right away.

Terms for this

Similar errors

Sources

Checked on Oct 27, 2026. Didn't help? Ask in the forum and name the graphics card, program, and the full message.