Clamp bounds computed as 1 minus eps round to 1 in low precision
@marcdasilva▲ 7 net votes
A clamp of the form x in [eps, 1 - eps] computed in float32 can have its upper bound round to exactly 1.0 for small eps, so the clamp never applies at x = 1 and the result is infinite. Compare 1 - x with eps instead, which is exact for x of at least 0.5, and apply the same change to the backward pass and to every alias of the op. Test x at 0, 0.5, and 1 for float32 and float64 across eps values below the rounding threshold, checking both values and gradients.