Pytorch view GPU information

1. Check whether cuda is available: torch.cuda.is_available()

>>> import torch
>>> torch.cuda.is_available()
True

2. Check the number of GPUs: torch.cuda.device_count()

>>> torch.cuda.device_count()
1

3. Check the GPU model. The device index starts from 0 by default: torch.cuda.get_device_name(0)

>>> torch.cuda.get_device_name(0)
'NVIDIA T4 32GB'

4. View the current device index: torch.cuda.current_device()

>>> torch.cuda.current_device()
0

Guess you like

Origin blog.csdn.net/u014486518/article/details/129320525