ubuntu

Ubuntu与PyTorch的集成方式是什么

小樊
45
2025-09-17 01:30:33
栏目: 智能运维

Ubuntu与PyTorch的集成方式主要有以下两种,均需先安装Python环境:

  1. 使用pip安装
    • CPU版本:更新系统后,直接通过pip安装PyTorch,无需额外配置CUDA。
      pip3 install torch torchvision torchaudio
    • GPU版本:需先安装对应CUDA和cuDNN,再通过pip指定CUDA版本安装PyTorch。
      pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117(以CUDA 11.7为例)
  2. 使用conda安装
    • CPU版本:创建conda环境后,安装CPU版PyTorch。
      conda install pytorch torchvision torchaudio cpuonly -c pytorch
    • GPU版本:安装时指定CUDA工具包版本,需提前安装对应CUDA和cuDNN。
      conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch

安装后可通过import torchprint(torch.cuda.is_available())验证,若返回True则表示GPU加速可用。

0
看了该问题的人还看了