以下是在CentOS下更新PyTorch的指南:
使用pip更新
- 确保pip是最新版本:
pip install --upgrade pip。 - 卸载旧版本(可选):
pip uninstall torch torchvision torchaudio。 - 访问PyTorch官网,根据系统环境选择安装命令。如使用CUDA 11.7,命令为:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117;若无需GPU支持,使用:pip install torch torchvision torchaudio。 - 验证安装:
import torch; print(torch.__version__)。
使用conda更新
- 更新conda:
conda update conda。 - 激活环境(若使用虚拟环境):
conda activate your_env_name。 - 卸载旧版本(可选):
conda remove pytorch torchvision torchaudio。 - 安装新版本,根据CUDA版本选择命令。如使用CUDA 11.7:
conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch;无需GPU则用:conda install pytorch torchvision torchaudio cpuonly -c pytorch。 - 验证安装:
import torch; print(torch.__version__)。
注意事项
- 更新前检查系统依赖,确保Python、CUDA等版本与PyTorch兼容。
- 建议在虚拟环境中操作,避免与其他项目冲突。
- 安装过程中需保持网络连接稳定。