CUDA error: no kernel image is available for execution on the device

pip uninstall  torch torchvision torchaudio
pip cache purge
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention #进入目录
git submodule update --init --recursive 

安装最新的编译工具
pip install --upgrade wheel

卸载ninja工具,否则会编译出错!
pip uninstall ninja

如果你是其他架构的显卡,则将里面的“120”改为该架构对应的代号。
export FLASH_ATTN_CUDA_ARCHS="120"
python setup.py install # 1h

更新conda环境内的 libstdc++ 库,否则运行时会报错,方法如下:
conda install -c conda-forge libstdcxx-ng

try:
    import flash_attn
    print("flash-attention 已安装,版本:", flash_attn.__version__)
except ImportError:
    print("flash-attention 未安装")
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐