安装flash-attention失败的终极解决方案

安装大语言模型的时候,有时候需要安装flash-attention来加速。比如说通义千问里的安装方法:
git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .

我们经常安着安着就卡住了,比如说下面的进度:
Requirement already satisfied: mpmath>=0.19 in /root/anaconda3/envs/QWEN/lib/python3.10/site-packages (from sympy->torch->flash-attn) (1.3.0)
Building wheels for collected packages: flash-attn
  Building wheel for flash-attn (setup.py) 
等好久都没反应。

后来找到https://github.com/Dao-AILab/flash-attention,在这里找到了答案,原来要先安装ninja。然后运行ninja --version和echo $?。
如果你运行了echo $?之后返回不是0,需要卸载ninja重新安装。直到echo $?之后返回0。
pip install flash-attn --no-build-isolation再次迎来一段等待。结果报错如下:

  Building wheel for flash-attn (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      fatal: not a git repository (or any of the parent directories): .git
      
      
      torch.__version__  = 2.2.0+cu121
      
      
      running bdist_wheel
      Guessing wheel URL:  https://github.com/Dao-AILab/flash-attention/releases/download/v2.5.2/flash_attn-2.5.2+cu122torch2.2cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
      error: <urlopen error [Errno 110] Connection timed out>
      [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
  Running setup.py clean for flash-attn
Failed to build flash-attn

(补充一句,如果你的torch不是 2.2.0+cu121。那还得安装 2.2.0+cu121 这个版本)

看来是网络超时,加上代理,重新 pip install https://github.com/Dao-AILab/flash-attention/releases/download/v2.5.2/flash_attn-2.5.2+cu122torch2.2cxx11abiFALSE-cp310-cp310-linux_x86_64.whl的方式来安装。最后成功。

总结如下:
1、默认pip flash-attn 的时候,如果你之前没安装ninja,那就要等几个小时(GitHub上说是2小时)。
2、安装了ninja还要用echo $?来检测ninja是否正常。
3、正常的情况下。报了error: <urlopen error [Errno 110] Connection timed out>。说明网络超时,你还得用代理来pip这个链接。这才能安装上flash-attn。

这就是flash-attn安装的艰辛过程。

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值