Repository navigation
Conversation
… dtype Multiplying x by a float32 mask turned nan and -inf into nan instead of 0 and failed for float16/float64 inputs. Select with where(x > alpha, x, 0) using constants in the input dtype. Fixes apache#20851 Signed-off-by: Dundy Pasupuleti <dundysm@gmail.com>
This branch has not been deployed
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.
fixes #20851
the ThresholdedRelu converter computed
(x > alpha).astype("float32") * x. that gives nan for nan and -inf inputs (nan * 0 and -inf * 0 are nan) where onnx expects 0, and the float32 mask doesn't match float16 or float64 inputs, so those failed to convert.this lowers it as
where(x > alpha, x, 0)with alpha and zero built in the input dtype, which matches the Where-based function body in the onnx spec.tests:
test_thresholded_relu_nonfinite_and_dtypesruns[nan, -inf, -2, 0, 0.5, 1, 2, inf]in float32, float16 and float64 and checks the exact output and dtype; it fails before the change and passes after.test_thresholded_relu.note: i couldn't build libtvm from source on this machine, so i ran the changed converter and these tests (plus the other relu tests, 9 passed) against the 0.27.0.post1 wheel's runtime; the converter code is identical there. ruff format and check are clean.