[Fix][Relax][ONNX] Honor detect_negative and detect_positive in IsInf - #20481
Open
Arthur031221 wants to merge 1 commit into
Open
Arthur031221 wants to merge 1 commit into
Arthur031221 wants to merge 1 commit into
Conversation
The IsInf converter always lowered to relax.op.isinf and ignored the detect_negative and detect_positive attributes. A model that sets either one to 0 got true for infinities of that sign, where ONNX Runtime returns false. Keep relax.op.isinf when both attributes are set, AND it with a sign check when only one is set, and return all false when both are 0.
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.
The ONNX
IsInfconverter always lowered torelax.op.isinfand ignored thedetect_negativeanddetect_positiveattributes (both default to 1). A model that sets either one to 0 got true for infinities of that sign, while ONNX Runtime returns false.For the input
[[-inf, -1.5, 0.0], [2.0, inf, nan]](float32, opset 14), before this change:[1, 0, 0, 0, 1, 0][1, 0, 0, 0, 1, 0][1, 0, 0, 0, 0, 0][1, 0, 0, 0, 1, 0][0, 0, 0, 0, 1, 0][1, 0, 0, 0, 1, 0][0, 0, 0, 0, 0, 0][1, 0, 0, 0, 1, 0]The converter now keeps
relax.op.isinfwhen both attributes are set, ANDs it withx > 0orx < 0when only one is set, and returns all false when both are 0. After the change all four rows match ONNX Runtime, for float32 and float64 inputs.test_isinf_detect_signintests/python/relax/test_frontend_onnx.pycovers the four combinations with the input above throughcheck_correctness. With the converter reverted, three of the four cases fail and the default case passes. The whole oftest_frontend_onnx.pygives the same result before and after apart from the four new cases;test_range_constant_floatand onetest_range_dynamic_scalar_inputscase fail in my environment on main as well.