I have some code encapsulated in a:
with torch.cuda.device(self.device):
# do a bunch of stuff
And in my __init__ I have:
self.device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
But I'm a little confused about how to deal with a situation where the device is cpu. Because torch.cuda.device is already explicitly for cuda. Should I just write a decorator for the function? Seems a bit overkill