温馨提示×

如何更新Ubuntu上的PyTorch版本

小樊
51
2025-09-03 01:12:13
栏目: 智能运维

在Ubuntu上更新PyTorch版本,常用方法如下:

  • 使用pip安装
    1. 卸载旧版本:pip uninstall torch torchvision torchaudio
    2. 安装最新版:pip install --upgrade torch torchvision torchaudio。若需特定版本,可指定版本号,如pip install torch==<version> torchvision==<version> torchaudio==<version>。若用GPU,需指定CUDA版本,如pip install torch torchvision torchaudio --extra -index -url https://download.pytorch.org/whl/cu117(以CUDA 11.7为例)。
  • 使用conda安装
    1. 激活conda环境(若有):conda activate your_environment_name
    2. 卸载旧版本:conda remove pytorch torchvision torchaudio
    3. 安装最新版:conda update pytorch torchvision torchaudio cudatoolkit=<对应版本> -c pytorch。不使用GPU可省略cudatoolkit参数。

安装完成后,可通过import torch; print(torch.__version__)验证版本。操作前建议备份代码数据,确保CUDA等版本兼容,且在虚拟环境中操作。

0