news 2026/4/16 12:00:48

Linux服务器安装flash_attn

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Linux服务器安装flash_attn

方法一:直接尝试pip:

pipinstallflash_attn

可能出现报错:

pip install flash-attn -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting flash-attn Using cached https://pypi.tuna.tsinghua.edu.cn/packages/3b/b2/8d76c41ad7974ee264754709c22963447f7f8134613fd9ce80984ed0dab7/flash_attn-2.8.3.tar.gz (8.4 MB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [20 lines of output] Traceback (most recent call last): File "/home/ysr/.conda/envs/wan/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/home/ysr/.conda/envs/wan/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ysr/.conda/envs/wan/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-7rn47hok/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-7rn47hok/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires self.run_setup() File "/tmp/pip-build-env-7rn47hok/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) File "/tmp/pip-build-env-7rn47hok/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 22, in <module> ModuleNotFoundError: No module named 'torch' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed to build 'flash-attn' when getting requirements to build wheel

这是一个非常典型的 Python 打包和构建错误,尤其是在尝试从源代码或使用 PyPI 缓存的源码包进行安装时:

ModuleNotFoundError: No module named 'torch'

错误原因分析

pip尝试安装flash-attn时,它会经历几个步骤,其中一个步骤是获取构建 Wheel 所需的依赖项 (Getting requirements to build wheel)

  1. flash-attnsetup.py(或类似的构建配置)在运行时需要导入torch来检查环境、确定 CUDA 架构等信息。
  2. 在构建环境(pip-build-env-*)内部,PyTorch 模块没有被找到,导致ModuleNotFoundError

为什么 PyTorch 已经安装了,构建环境却找不到它?

这是因为pip默认会在一个隔离的临时环境中运行构建脚本(通过pyproject.toml文件指定的要求),以确保构建的纯净性。您的主环境中的 PyTorch (虽然已安装) 并不会自动复制到这个临时的构建环境。

解决方案:禁用构建隔离

解决这个问题最简单、最直接的方法就是禁用pip的构建隔离。这将允许构建脚本直接访问您当前虚拟环境(wan)中已经安装的torch模块。

请尝试使用以下命令进行安装:

pipinstallflash-attn --no-build-isolation -i https://pypi.tuna.tsinghua.edu.cn/simple
  • --no-build-isolation: 禁用构建隔离,允许flash-attn的构建脚本访问您当前环境中的torch模块。

然后可能出现报错二:

(类似说没有找到cuda的,具体报错我的记录丢失了,解决方法是export CUDA_HOME=xxx,其中xxx类似于/一堆前缀路径/cuda-12.1


错误三:

网络问题
因为服务器可能连不上外网或者其他什么网络问题,如果出现这种情况,最好的解决方法就是自己到github仓库中找到对应版本的whl,然后手动安装。

Building wheel for flash-attn (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for flash-attn (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [22 lines of output] No CUDA runtime is found, using CUDA_HOME='/opt/Software/cuda/12.9.1' /home/ysr/.conda/envs/wan/lib/python3.11/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: BSD License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() torch.__version__ = 2.5.1+cu121 running bdist_wheel Guessing wheel URL: https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3+cu12torch2.5cxx11abiFALSE-cp311-cp311-linux_x86_64.whl error: Remote end closed connection without response [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for flash-attn Failed to build flash-attn error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> flash-attn

在报错里其实已经给出了你可能匹配的whl路径了:
Guessing wheel URL: https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3+cu12torch2.5cxx11abiFALSE-cp311-cp311-linux_x86_64.whl

直接去网站下载,然后传到服务器上,手动安装:

pipinstallflash_attn-2.8.3+cu12torch2.5cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/15 13:54:15

第三只眼睛:当 AI 重构人类视觉革命 —— 中国 EyeReal 裸眼 3D 技术如何撕开未来的裂缝?

引言 | 凌晨三点的复旦大学实验室,26 岁的博士生李默盯着显微镜下跳动的数据流,突然按下暂停键 —— 这串由 AI 算法生成的 3D 坐标,正将他的视网膜变成「立体画布」。 就在三个月前,他带领的团队刚刚让这项技术登上《Nature》封面,而此刻,他们正在改写一个更残酷的现实…

作者头像 李华
网站建设 2026/4/16 13:53:28

终极HTML压缩神器:minify-html如何让网页加载速度飙升?

终极HTML压缩神器&#xff1a;minify-html如何让网页加载速度飙升&#xff1f; 【免费下载链接】minify-html Extremely fast and smart HTML JS CSS minifier, available for Rust, Deno, Java, Node.js, Python, Ruby, and WASM 项目地址: https://gitcode.com/gh_mirror…

作者头像 李华
网站建设 2026/4/16 3:04:06

解锁chan.py:构建专业缠论分析系统的7个关键步骤

解锁chan.py&#xff1a;构建专业缠论分析系统的7个关键步骤 【免费下载链接】chan.py 开放式的缠论python实现框架&#xff0c;支持形态学/动力学买卖点分析计算&#xff0c;多级别K线联立&#xff0c;区间套策略&#xff0c;可视化绘图&#xff0c;多种数据接入&#xff0c;策…

作者头像 李华
网站建设 2026/4/12 20:00:51

以田间除草为喻:敏捷研发中流程规范与工具的动态平衡

从除草看敏捷&#xff1a;一场关于秩序与效率的永恒博弈2025 年 6 月&#xff0c;某互联网巨头宣布全面重构敏捷研发体系&#xff0c;引发行业震动。这个拥有 5000 人研发团队的科技巨头&#xff0c;曾因过度依赖自动化工具导致流程僵化&#xff0c;最终在一次关键项目中因需求…

作者头像 李华
网站建设 2026/4/14 9:59:51

双剑合璧,效率倍增:AI + 低代码如何重塑企业技术架构?

目录 一、认知重构&#xff1a;AI与低代码不是加法&#xff0c;而是乘法 1.1 从工具到中枢&#xff1a;低代码的AI原生进化 1.2 从通用到专属&#xff1a;AI的场景化落地突破 二、技术解密&#xff1a;AI低代码的核心架构与能力落地 2.1 多模型适配层&#xff1a;灵活兼容…

作者头像 李华
网站建设 2026/4/13 11:40:02

5分钟学会iziToast:优雅轻量的网页通知插件

5分钟学会iziToast&#xff1a;优雅轻量的网页通知插件 【免费下载链接】iziToast Elegant, responsive, flexible and lightweight notification plugin with no dependencies. 项目地址: https://gitcode.com/gh_mirrors/iz/iziToast iziToast是一个优雅、响应式、灵活…

作者头像 李华