torch get device code example
Example 1: torch device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
Example 2: pytorch get gpu number
torch.cuda.device_count()
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
torch.cuda.device_count()