安装或更新 CUDA Toolkit - Ubuntu - RuntimeError
1、问题
执行
pip install flash-attn --no-build-isolation
时,出错:
RuntimeError: FlashAttention is only supported on CUDA 11.7 and above. Note: make sure nvcc has a torch.__version__ = 2.4.0+cu12
执行 nvcc --version
或 nvcc -V:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
2、解决:
nvcc
版本过低,需要更新安装 CUDA Toolkit。
(1)下载和安装 CUDA Toolkit
进入页面:CUDA Toolkit Archive | NVIDIA Developer。
根据下载页面的导引选择合适的版本下载并进行安装。
安装过程通常是下载并运行 .run
文件,如下:
CUDA Toolkit 安装程序 | |
安装指令: | |
| |
|
(2)配置环境变量
安装完成后,通常需要设置环境变量。可以将以下行添加到 ~/.bashrc
或 ~/.zshrc
文件中:
export PATH=/usr/local/cuda-12.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:$LD_LIBRARY_PATH
然后运行 source ~/.bashrc
或 source ~/.zshrc
来应用更改。
(3) 验证安装
再次运行 nvcc --version
或 nvcc -V
来确认 nvcc
新版本的安装和配置是否正确:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Wed_Jan_15_19:20:09_PST_2025
Cuda compilation tools, release 12.8, V12.8.61
Build cuda_12.8.r12.8/compiler.35404655_0