温馨提示×

如何在Debian上更新PyTorch

小樊
47
2025-08-02 04:23:24
栏目: 智能运维

在Debian系统上更新PyTorch可以通过以下几种方法进行:

使用pip更新PyTorch

  1. 更新pip(如果尚未是最新的):
pip install --upgrade pip 
  1. 卸载旧版本的PyTorch(可选,但推荐):
pip uninstall torch torchvision torchaudio 
  1. 安装最新版本的PyTorch
    • 无CUDA(CPU版本)
    pip install torch torchvision torchaudio 
    • CUDA 10.2
    pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu102 
    • CUDA 11.3
    pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 
    • CUDA 11.7
    pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117 
    • CUDA 12.0
    pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu120 

使用conda更新PyTorch

  1. 更新conda(如果尚未是最新的):
conda update conda 
  1. 激活你的conda环境(如果你在一个特定的环境中工作):
conda activate your_environment_name 
  1. 卸载旧版本的PyTorch(可选,但推荐):
conda remove pytorch torchvision torchaudio cudatoolkit -n your_environment_name 
  1. 安装最新版本的PyTorch
    • 无CUDA(CPU版本)
    conda install pytorch torchvision torchaudio cpuonly -c pytorch 
    • CUDA 10.2
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch 
    • CUDA 11.3
    conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch 
    • CUDA 11.7
    conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch 
    • CUDA 12.0
    conda install pytorch torchvision torchaudio cudatoolkit=12.0 -c pytorch 

验证安装

安装完成后,可以通过以下命令验证PyTorch是否安装成功:

import torch print(torch.__version__) print(torch.cuda.is_available()) # 如果安装了CUDA版本,应该返回True 

以上步骤可以帮助你在Debian系统上成功更新PyTorch。如果有任何问题,建议参考PyTorch官方文档获取更多信息。

0