Ubuntu上PyTorch支持GPU。需安装NVIDIA显卡驱动、CUDA Toolkit、cuDNN库,再安装对应版本的PyTorch GPU版本,具体步骤如下:
sudo apt update
和sudo apt install nvidia-driver-版本号
安装,版本号根据显卡型号确定。pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
。安装后,可通过代码import torch; print(torch.cuda.is_available())
验证,若输出True
,则表示配置成功。