在Ubuntu上管理PyTorch版本,可通过以下方式操作:
pip方式
pip uninstall torch torchvision torchaudiopip install torch==2.0.1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118pip install torch torchvision torchaudioconda方式
conda remove pytorch torchvision torchaudioconda install pytorch==2.0.1 torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidiaconda install pytorch==2.0.1 torchvision torchaudio cpuonly -c pytorch查看当前版本:
import torch
print(torch.__version__) # 查看PyTorch版本
print(torch.version.cuda) # 查看CUDA版本(若安装GPU版)
切换虚拟环境:
source venv_name/bin/activate(venv)或 conda activate env_name(conda)nvidia-smi确认GPU驱动支持安装的CUDA版本。参考来源: