Repository navigation
fix: RMS transforms produce NaN on float16 zero-gradient steps - #1808
Aditya-B-007 wants to merge 3 commits into
Conversation
|
Fixed issue #1784 . Please do take a look |
…ent steps eps=1e-8 underflows to 0.0 when evaluated in float16, making the denominator zero and producing inf * 0 = NaN on the first step with zero gradients. This affected scale_by_rms, scale_by_stddev, and therefore optax.rmsprop. Fix: - Compute the scaling denominator in float32 so eps remains 1e-8. - Floor variance at jnp.finfo(float32).tiny before taking the square root, so a zero EMA can never produce an infinite scale factor. - Cast the update product back to the gradient dtype, preserving float16. Both eps_in_sqrt=True (rsqrt path) and eps_in_sqrt=False (1/sqrt+eps path) are fixed. bias_correction on/off is also covered. Add 16 parameterised JIT-compiled regression tests in ScaleByRmsFloat16Test covering: scale_by_rms, scale_by_stddev x eps_in_sqrt True/False x bias_correction True/False x scalar eps / ArrayLike eps (pre-underflowed float16 value) Each case asserts: no NaNs, zero output, float16 dtype preserved.
b185a10 to
ce09690
Compare
…g by 0 when the denominator approaches 0 for float 16 use cases.
|
Bug is fixed can be merged |
|
Thanks for working on this and contributing a fix for #1784, @Aditya-B-007! We've addressed the Closing this PR as superseded by #1835. Thanks again for your effort! |
|
Thank you. |
Prevent NaN updates in scale_by_rms/stddev on float16 zero-gradi…ent steps
eps=1e-8 underflows to 0.0 when evaluated in float16, making the denominator zero and producing inf * 0 = NaN on the first step with zero gradients. This affected scale_by_rms, scale_by_stddev, and therefore optax.rmsprop.
Fix:
Both eps_in_sqrt=True (rsqrt path) and eps_in_sqrt=False (1/sqrt+eps path) are fixed. bias_correction on/off is also covered.