We do this as a simplification on the tensorflow graph itself. We transform SquaredDifference(a,b) into (a-b) * (a-b).