在 Ubuntu 上升级 PyTorch 版本,通常取决于你是用 pip 还是 conda 安装的。下面分别说明。
python -c "import torch; print(torch.__version__)"
pip install --upgrade torch torchvision torchaudio
例如 CUDA 11.8:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
其他常见版本:
cu121pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
conda list torch
conda update pytorch torchvision torchaudio -c pytorch
例如 CUDA 11.8:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
如果你还没用虚拟环境,建议新建一个:
python -m venv venv
source venv/bin/activate
pip install torch torchvision torchaudio
或用 conda:
conda create -n torch_env python=3.10
conda activate torch_env
python -c "import torch; print(torch.__version__); print(torch.cuda.is_available())"
pip uninstall torch torchvision torchaudio
apt 安装 PyTorch(版本很旧)如果你告诉我:
我可以给你精确的一条命令。