问题描述
pip install flash-attn --no-build-isolation --use-pep517
安装失败(报错特别长)
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for flash-attn
Failed to build flash-attn
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (flash-attn
原因分析
这个问题主要是由于编译flash-attn模块时遇到了环境和依赖问题。具体来说,有两个问题:
GCC版本过旧:flash-attn
编译需要GCC 9或更高版本,但当前环境的GCC版本过低。
网络连接超时:flash-attn
在下载和构建依赖项时发生超时。
解决方案
请按照以下步骤进行调整:
- 更新GCC版本
由于当前环境需要GCC 9或更高版本,请确保安装和使用正确的GCC版本。您可以通过以下命令更新GCC:
sudo apt-get update
sudo apt-get install gcc-9 g++-9
然后,将GCC 9设置为默认编译器:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9
sudo update-alternatives --config gcc
- 使用ninja加速编译
flash-attn依赖ninja编译工具,可以加速安装过程。如果没有安装ninja,可以使用以下命令:
sudo apt-get install ninja-build
- 手动安装flash-attn
直接从GitHub源代码编译flash-attn。可以尝试以下步骤:
git clone https://github.com/Dao-AILab/flash-attention.git
cd flash-attention
pip install .
但是这一步我失败了
- 再装一次,就成功了
pip install flash-attn --no-build-isolation --use-pep517
- 虽然没整明白,但好歹环境装起来了