Function MulBackward0 returned an invalid gradienttorch.FloatTensor but got torch.cuda.FloatTensor

关键原因在于在forward过程中,使用的某些变量是torch.Tensor,没有放到cuda上面,使用torchsnooper检查每一个变量的类型,统一格式后就可以解决掉问题。
Some variables initialized in forward were not put deployed on cuda.
详见:https://discuss.pytorch.org/t/runtimeerror-function-addbackward0-returned-an-invalid-gradient-at-index-1-expected-type-torch-floattensor-but-got-torch-cuda-floattensor/48265

猜你喜欢

转载自blog.csdn.net/m0_46429066/article/details/104684103