AssertionError: nn criterions don't compute the gradient w.r.t. targets - please mark these tensors as not requiring gradients

When I use the nn.MSELoss(), just as follows:
nn.MSELoss(feature1, feature2)

where both the feature1 and the feature are need to be differentiated here. That means feature1 is the output of model1 and feature2 is the output of model2.

But the error is like this:
AssertionError: nn criterions don’t compute the gradient w.r.t. targets - please mark these tensors as not requiring gradients

How should I solve it?

Hi,

Which version of pytorch are you using?

Thanks for replying.

pytorch0.4

Ok, I think this has been fixed in the latest versions.
Can you try upgrading to see if it fixes the issue?