看起来是 NVIDIA 驱动和 NVML 库版本不匹配的问题。让我们解决这个问题:
- 首先,检查当前安装的 NVIDIA 驱动版本:
bash
Apply to document_ser...
Run
dpkg -l | grep nvidia
- 卸载现有的 NVIDIA 驱动和 CUDA:
bash
Apply to document_ser...
Run
sudo apt-get purge nvidia* cuda*
sudo apt-get autoremove
- 清理 NVIDIA 仓库:
bash
Apply to document_ser...
Run
sudo rm /etc/apt/sources.list.d/cuda*
sudo rm /etc/apt/preferences.d/cuda*
sudo apt-key del 7fa2af80
- 添加最新的 NVIDIA 驱动仓库:
bash
Apply to document_ser...
Run
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
- 安装推荐的 NVIDIA 驱动:
bash
Apply to document_ser...
Run
ubuntu-drivers devices
sudo apt install nvidia-driver-535 # 或者使用 ubuntu-drivers 推荐的版本
- 重新安装 CUDA Toolkit:
bash
Apply to document_ser...
Run
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get install cuda-toolkit-12-3
- 设置环境变量,编辑 ~/.bashrc:
bash
Apply to document_ser...
Run
echo 'export PATH=/usr/local/cuda-12.3/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
- 重启系统:
bash
Apply to document_ser...
Run
sudo reboot
- 重启后,验证安装:
bash
Apply to document_ser...
Run
nvidia-smi
nvcc --version
- 重新安装 PyTorch:
bash
Apply to document_ser...
Run
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
- 验证 PyTorch 是否能识别 GPU:
python
Apply to document_ser...
python3 -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('CUDA device count:', torch.cuda.device_count()); print('CUDA device name:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'None')"
如果还遇到问题,可以尝试:
- 检查 NVIDIA 驱动状态:
bash
Apply to document_ser...
Run
sudo systemctl status nvidia-persistenced
- 检查 CUDA 版本兼容性:
bash
Apply to document_ser...
Run
nvidia-smi --query-gpu=driver_version --format=csv,noheader
nvcc --version
- 如果还有问题,可以查看 NVIDIA 驱动日志:
bash
Apply to document_ser...
Run
sudo dmesg | grep nvidia
完成这些步骤后,重启服务器并检查日志,应该能看到 GPU 信息。如果还有问题,请告诉我具体的错误信息!
Lines 4-64
Using terminal selections
我看到你的系统已经安装了 NVIDIA 驱动 570.133.20 版本。让我们继续安装 CUDA 和配置 PyTorch:
- 首先安装 CUDA Toolkit 12.3(与你的驱动版本兼容):
bash
Apply to document_ser...
Run
# 添加 NVIDIA 包仓库
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
# 安装 CUDA Toolkit
sudo apt-get install cuda-toolkit-12-3
- 设置 CUDA 环境变量,编辑 ~/.bashrc:
bash
Apply to document_ser...
Run
echo 'export PATH=/usr/local/cuda-12.3/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
- 验证 CUDA 安装:
bash
Apply to document_ser...
Run
nvcc --version
- 安装支持 CUDA 12.1 的 PyTorch(与 CUDA 12.3 兼容):
bash
Apply to document_ser...
Run
# 卸载现有的 PyTorch
pip uninstall torch torchvision torchaudio
# 安装支持 CUDA 的 PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
- 验证 PyTorch 是否能识别 GPU:
python
Apply to document_ser...
python3 -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('CUDA device count:', torch.cuda.device_count()); print('CUDA device name:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'None')"
- 如果一切正常,重启服务器并检查日志。你应该能看到类似这样的日志:
text
Apply to document_ser...
使用 GPU: NVIDIA GeForce RTX XXXX
如果遇到任何问题,请告诉我具体的错误信息。另外,你也可以运行以下命令来检查系统状态:
bash
Apply to document_ser...
Run
# 检查 NVIDIA 驱动状态
nvidia-smi
# 检查 CUDA 版本
nvcc --version
# 检查 PyTorch 版本和 CUDA 支持
python3 -c "import torch; print('PyTorch version:', torch.__version__); print('CUDA available:', torch.cuda.is_available())"
2万+



被折叠的 条评论
为什么被折叠?



