Skip to content

[Fix][Relax][ONNX] Honor detect_negative and detect_positive in IsInf - #20481

Open
Arthur031221 wants to merge 1 commit into
apache:mainfrom
Arthur031221:fix-onnx-isinf-detect-sign
Open

Arthur031221 wants to merge 1 commit into
apache:mainfrom
Arthur031221:fix-onnx-isinf-detect-sign

Conversation

@Arthur031221

Copy link
Copy Markdown

The ONNX IsInf converter always lowered to relax.op.isinf and ignored the detect_negative and detect_positive attributes (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:

detect_negative detect_positive ONNX Runtime 1.30.0 TVM
1 1 [1, 0, 0, 0, 1, 0] [1, 0, 0, 0, 1, 0]
1 0 [1, 0, 0, 0, 0, 0] [1, 0, 0, 0, 1, 0]
0 1 [0, 0, 0, 0, 1, 0] [1, 0, 0, 0, 1, 0]
0 0 [0, 0, 0, 0, 0, 0] [1, 0, 0, 0, 1, 0]

The converter now keeps relax.op.isinf when both attributes are set, ANDs it with x > 0 or x < 0 when 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_sign in tests/python/relax/test_frontend_onnx.py covers the four combinations with the input above through check_correctness. With the converter reverted, three of the four cases fail and the default case passes. The whole of test_frontend_onnx.py gives the same result before and after apart from the four new cases; test_range_constant_float and one test_range_dynamic_scalar_inputs case fail in my environment on main as well.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant