Interesting, I get some similar errors when using the squeeze_ method. I want to compute a complex loss function, which involves some batch matrix transform. So I use squeeze_ method for matrix shape transform. Unluckily, torch seems cannot deal with this situation.
The traceback is as follows.
RuntimeError: Function MulBackward0 returned an invalid gradient at index 0 - expected type torch.FloatTensor but got torch.cuda.FloatTensor