xxxxxxxxxx
evice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
xxxxxxxxxx
# conda
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
# pip
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
Check if Cuda is enabled on PyTorch
xxxxxxxxxx
import torch
torch.cuda.is_available()