flash-attention包的安装

安装flash_attention包

https://github.com/Dao-AILab/flash-attention

第1到3步安装比较容易

pip install torch packaging ninja

ninja –version # 查看是否安装正常

由于中国下载github的文件太慢,造成了太多阻碍,如果按官方的方式安装,一定会报错, 报错如下

pip install -U flash-attn –no-build-isolation

1
2
3
4
5
6
7
8
      Guessing wheel URL:  https://github.com/Dao-AILab/flash-attention/releases/download/v2.2.5/flash_attn-2.2.5+cu117torch2.0cxx11abiFALSE-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

我们可以克隆代码仓库,修改setup.py文件,然后手动安装

手动下载whl文件,注意看你报错的whl文件是什么,就下载什么

wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.2.5/flash_attn-2.2.5+cu117torch2.0cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

修改setup.py代码如下:

1
2
3
4
5
6
print("Guessing wheel URL: ", wheel_url)
try:
if os.path.exists(wheel_filename):
print("Found wheel: ", wheel_filename)
else:
urllib.request.urlretrieve(wheel_url, wheel_filename)

然后安装

python setup.py install

安装成功

1
2
3
4
5
6
7
Using /media/wac/backup/anaconda3/envs/wenda/lib/python3.10/site-packages
Searching for mpmath==1.3.0
Best match: mpmath 1.3.0
Adding mpmath 1.3.0 to easy-install.pth file

Using /media/wac/backup/anaconda3/envs/wenda/lib/python3.10/site-packages
Finished processing dependencies for flash-attn==2.3.0

flash-attention包的安装
https://johnson7788.github.io/2023/09/28/flash-attention%E5%8C%85%E7%9A%84%E5%AE%89%E8%A3%85/
作者
Johnson
发布于
2023年9月28日
许可协议