Skip to content

Fix flash-attn install failing with 'No module named torch'#135

Open
gt12889 wants to merge 1 commit into
meituan-longcat:mainfrom
gt12889:fix/flash-attn-build-isolation
Open

Fix flash-attn install failing with 'No module named torch'#135
gt12889 wants to merge 1 commit into
meituan-longcat:mainfrom
gt12889:fix/flash-attn-build-isolation

Conversation

@gt12889

@gt12889 gt12889 commented Jul 13, 2026

Copy link
Copy Markdown

What

Fixes the flash_attn install failure reported in #126
(ModuleNotFoundError: No module named 'torch').

Why

flash-attn's setup.py imports torch at build time. pip builds it in an
isolated environment by default, where torch isn't present, so the build fails
even when torch is already installed in the target env.

The failure happens twice with the current setup:

  1. The README's pip install flash_attn==2.7.4.post1 step.
  2. pip install -r requirements.txt, which also lists flash-attn.

Changes

  • README: build flash-attn with --no-build-isolation so it links against the
    torch installed in the previous step.
  • requirements.txt: remove flash-attn (installed via its own documented step)
    and torch (installed from the cu124 index, so the plain torch==2.6.0 here
    can pull a CPU build over it).

Fixes #126

…an-longcat#126)

pip builds flash-attn in an isolated env where torch is not installed,
so the build fails even though torch is right there in your env. Add
--no-build-isolation to the README install step, and drop torch +
flash-attn from requirements.txt since they are already handled by
their own install steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pip install flash_attn==2.7.4.post1 no modle named troch

1 participant