温馨提示×

Ubuntu PyTorch有哪些常用命令

小樊
56
2025-08-07 18:48:52
栏目: 智能运维

以下是一些Ubuntu下PyTorch的常用命令:

安装命令

  • 使用pip安装CPU版本pip3 install torch torchvision torchaudio
  • 使用pip安装CUDA版本(以CUDA 11.3为例)pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
  • 使用conda安装CPU版本conda install pytorch torchvision torchaudio cpuonly -c pytorch
  • 使用conda安装CUDA版本(以CUDA 11.3为例)conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

验证命令

  • Python交互式查询:进入Python交互环境,输入import torch,然后print(torch.__version__)可查看版本,print(torch.cuda.is_available())可查看CUDA是否可用。
  • 终端直接查询python -c "import torch; print(f'当前版本: {torch.__version__}')" ,或pip show torch | grep Version

0