conda虚拟环境下flash-attn包的安装部署时,执行命令报错
pip install flash-attn --no-build-isolation
Collecting flash-attn
Downloading flash_attn-2.5.6.tar.gz (2.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.5/2.5 MB 11.4 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
fatal: not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-9u5e9dng/flash-attn_e362cbbd46404df8a4978593d8bb899c/setup.py", line 114, in <module>
raise RuntimeError(
RuntimeError: FlashAttention is only supported on CUDA 11.6 and above. Note: make sure nvcc has a supported version by running nvcc -V.
torch.__version__ = 2.1.2+cu121
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
主要都是因为cuda版本导致的,解决了我问题的方法:
nvcc
该解决方案要求你安装了正确版本的cuda和pytorch,可以通过
python
import torch
print(torch.version.cuda)
Previous PyTorch Versions | PyTorch(pytorch官网下载cuda对应的pythorch)
如我的cuda和pytorch是
# CUDA 11.7
conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
确保pytorch能正常用后,flash-attn还不能直接用pip安装,是因为没有在虚拟环境下安装nvcc,导致调用了系统自带的cuda。
所以执行以下命令即可:
conda install cuda-nvcc
如果报错了,换成conda install cuda-nvcc -c conda-forge
就能正确安装flash-attn了。
下载flash-attn
在github找到对应pythorch和cuda版本的flash-attn安装包,右键负责链接
Releases · Dao-AILab/flash-attention (github.com)
## 下载
wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.3.5/flash_attn-2.3.5+cu117torch2.0cxx11abiTRUE-cp310-cp310-linux_x86_64.whl
## 安装
pip install flash_attn-2.3.5+cu117torch2.0cxx11abiTRUE-cp310-cp310-linux_x86_64.whl
以上都是在虚拟环境进行