helloworld2021:

Could you please explain it in detail? Since the error is “expected Variable[CPUType]”, while your comment is “creating new tensors on the CPU”.


The error message tries to be helpful in claiming which type is expected and which types were found.
However, this expectation could be a guess in case both types would be valid for this operation and, if I’m not mistaken, the error message uses the parameter as the expected type and the input as the wrong one (as done here), since this issue is more common.



 helloworld2021:

In addition, I don’t understand why we need to modify the code after setting model = model.to('cuda')


In this case, each forward pass creates new tensors in the forward method without using a device agnostic approach:
    def forward(self, x, adj_mat):
        weight_prod = torch.DoubleTensor(self.weight_mat(x))

Since no device attribute was used, the new weight_prod tensors will be created on the CPU by default.
Note that this approach would also detach weight_prod from the computation graph, so I would stick to my suggestion in using .double() if the dtype should be changed.