Gradient computation modified by an inplace operation

Hi Daniel!

The error message you posted gives two useful clues: First, the shape of
the tensor being modified inplace is [1, 128, 128], and second, it is the
output of a sqrt() operation.

Such an error could occur in parts of your code that you haven’t posted, but
it could also be happening to euclidean_distance, the result of a sqrt()
operation. Is the shape of euclidean_distance [1, 128, 128]?

I would look at what happens to euclidean_distance after it is returned
from the forward() function you posted. Do you see any inplace operations
being applied to it in the code that is subsequently called?

If this is the issue, then returning a clone() of euclidean_distance, e.g.,
return euclidean_distance.clone(), might be sufficient to fix the problem.

For further suggestions about how to debug such issues, please see this post:

Best.

K. Frank