maybe this helps:
device = torch.cuda.device(2)

as described here 12
can be checked using torch.cuda.current_device()
or
device = torch.device('cuda:2')

as described here 4
and here is a overview of cuda semantics 3
please keep 0-indexing in mind. meaning cuda:2 is your third cuda device, not your second