Repository navigation
fix(nx): propagate NaN through clip on BinaryBackend - #1855
Merged
Merged
Conversation
Nx.clip on BinaryBackend picked its result with two comparisons, and every comparison against NaN is false, so each argument position fell through to a different arm: clip(NaN, 0, 2) returned 0.0, clip(1, NaN, 2) returned 2.0, and only clip(1, 0, NaN) returned NaN. EXLA computes clip as min(max(x, lo), hi) and returns NaN for all three. Use the backend's own element_max and element_min, which already propagate NaN and handle infinities, so clip is the same composition on both backends. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
blasphemetheus
marked this pull request as ready for review
October 7, 2026 07:12
polvalente
approved these changes
Oct 7, 2026
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.
Nx.cliponBinaryBackendreturns a different thing for NaN depending on which argument carries it:The first case is the harmful one: a NaN input comes out as an in-range value, so a
clipused as a guard hides the NaN instead of surfacing it. EXLA returns NaN for all three, which matchesmin(max(x, lo), hi)with Nx's own NaN-propagatingminandmax.The cause is the two-comparison chain in
BinaryBackend.clip: every comparison against NaN is false, so each position falls through to a different arm. This replaces the chain with the backend's existingelement_maxandelement_min, which already handle NaN and infinities, so both backends compute the same composition.The new test covers NaN in each argument position and fails on
mainwith the values above. The existingcliptests, including the infinities case, still pass, and so does the fullnxsuite. (claude) also checked BinaryBackend against the EXLA CUDA client on the three NaN cases plus ordinary float and integer inputs, and they agree on all of them.🤖 Generated with Claude Code