import torch available_gpus = [torch.cuda.device(i) for i in range(torch.cuda.device_count())] available_gpus #[<torch.cuda.device object at 0x7f2585882b50>]