conda虚拟环境下flash-attn包的安装部署

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

以上都是在虚拟环境进行

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值