You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tf.squared_difference appears to produce incorrect gradients. I don't have a toy example handy, but this is demonstrable by running any training session with an error function like so:
Tensor Loss(Tensor y, Tensor expected)
{
return tf.squared_difference(y, expected)/2;
}
In my cases, the second works, while the first learns in the wrong direction. Presumably issue is in nn_grad._SquaredDifferenceGrad which is just returning the op.inputs and ignoring the grads argument, but I don't know how to fix this:
[RegisterGradient("SquaredDifference")]
public static Tensor[] _SquaredDifferenceGrad(Operation op, Tensor[] grads)
{
//"""Returns the gradient for (x-y)^2."""
Tensor x = op.inputs[0];
Tensor y = op.inputs[1];
return new Tensor[]
{
x,
y
};
}
Activity
Oceania2018 commentedon Mar 25, 2021
@LeeReidCSIRO Could you PR the handy code as UnitTest with

[IgnoreTest]annotation.You can write code in
GradientEagerTest.Fix gradient of squared_difference #787