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