flash_attn安装和使用指南

flash_attn安装比较麻烦。

方法1:whl安装

检查版本:

nvcc -V
ldd --version

如果 > 2.32,flash-attn 可以从https://github.com/Dao-AILab/flash-attention/下载编译好的whl包。
注意torch和cuda版本。
torch不需要完全对应,相近就行。

方法2:pip 编译

pip install packaging
pip install ninja
MAX_JOBS=32 pip install flash-attn --no-build-isolation

GCC报错:版本太低

error "You're trying to build PyTorch with a too old version of GCC. We need GCC 9 or later."

用conda安装gcc

conda install -c conda-forge gcc_linux-64=11 gxx_linux-64=11

# Conda compilers use specific environment variables
export CC=$CONDA_PREFIX/bin/x86_64-conda-linux-gnu-gcc
export CXX=$CONDA_PREFIX/bin/x86_64-conda-linux-gnu-g++
posted @ 2026-01-31 02:10  ylifs  阅读(6)  评论(0)    收藏  举报