赞
踩
安装大语言模型的时候,有时候需要安装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安装的艰辛过程。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。