wrapping SGD to reduce NaN and inf