If I give input.cuda() to a instance of nn.Module, do I need to call the latter's cuda() again?

class Net(nn.Module):
    ...

net = Net()
input = torch.Tensor()
output = net(input.cuda())
loss = output - label
loss.backward()
optimizer.step()

If I give a Tensor.cuda() to the net, will be the optim of the Net in the GPU?

No, you have to call model’s cuda() method manually

1 Like