Which line of code is raising this error?
This should be unrelated to the current error message, but note that you override the loss criterion with the loss tensor, which might yield other issues, if you are trying to call the same criterion again.