gpu pytorch install code example

Example 1: pytorch check gpu

In [1]: import torch

In [2]: torch.cuda.current_device()
Out[2]: 0

In [3]: torch.cuda.device(0)
Out[3]: <torch.cuda.device at 0x7efce0b03be0>

In [4]: torch.cuda.device_count()
Out[4]: 1

In [5]: torch.cuda.get_device_name(0)
Out[5]: 'GeForce GTX 950M'

In [6]: torch.cuda.is_available()
Out[6]: True

Example 2: conda install pytorch

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

Example 3: pytorch get gpu number

torch.cuda.device_count()

Example 4: mac install pytorch 3.6

conda install pytorch torchvision -c pytorch

Example 5: pytorch

pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html

Tags:

Misc Example