Repository navigation
fix(clipping): keep zero-update reverse gradients finite - #1815
Merged
selamw1 merged 2 commits intoOct 19, 2026
Merged
Conversation
selamw1
self-requested a review
October 13, 2026 00:16
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
…ngents PiperOrigin-RevId: 1004955717
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I fix NaN reverse-mode derivatives of
clip_by_global_normat zero updates with a positive threshold. The forward mapping is locally the identity, but the unused clipping branch differentiates a square root and division at zero.Mask the squared norm before the unused branch's square root and division. Keep the existing strict threshold comparison, nonzero clipped derivatives, public API and dependencies unchanged.
Closes #1814. This is separate from #1752's zero-threshold forward-value fix; it does not change that boundary contract or introduce the optional performance path discussed in #1452. No performance claim is made.
Testing plan — executed
Windows CPU, Python 3.12.10, JAX/jaxlib 0.11.2:
git diff --checkpass.The deterministic three-step inner loop now gives the analytic outer gradient
-1.458instead of NaN; centered float32 finite differences give approximately-1.45793.These local runs are selected affected-test validation, not the entire
bash test.shor accelerator validation.On head
5a39453983cc19f3c16f5ad9490868bce35e3c55, the upstream tests workflow also passes all 12 jobs: all five declared Ubuntu CPU test-matrix jobs (including JAX 0.5.3 and nightly), doctests, build/Pyrefly and lint checks.