Hi there,
In the training phase, then I run loss.backward()
, it raised this error:
File "/home/jingweipeng/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/tensor.py", line 107, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/home/jingweipeng/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/autograd/__init__.py", line 93, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: Function MulBackward0 returned an invalid gradient at index 1 - expected type torch.FloatTensor but got torch.cuda.FloatTensor
I have checked device attribute of all parameters, using the code snippet like this.
The Loss Function is simple nn.CrossEntropyLoss()
.
How can I trace such an error, using hooks
? Could you give me some hints or advice? Thanks in advance!