How do I know whether an instance is stored on GPU with PyTorch?
I'm learning PyTorch recently, and this question comes up.
For example, if I have a net inheriting the &quot;torch.nn.Module&quot;.
class Net(torch.nn.Module):
    def __init__(self, something):
        super(net, self).__init__()
        self.p1=something

    def forward():
        pass

net1=Net(123)
net1.cuda()  ##Here I can't see what is changed.

Then how can I know whether net1 (and that something) is stored on GPU.
I've read how the *.cuda() works, seems like let all the &quot;children&quot; run the *.cuda(). I tried to see what the &quot;children&quot; are. It seems the net1 above has no children.

To check a simple tensor, you can check the is_cuda attribute. For example:
x = torch.zeros(100).cuda()
y = torch.zeros(100)

print(x.is_cuda) # True
print(y.is_cuda) # False

To check a model, a think the easiest way is using the parameters() method, which returns all trainable parameters of your model.
next(model.parameters()).is_cuda

