Skip to content

[Fix][Relax]: ONNX Clip NaN bounds and preserve input NaN (ORT parity)#19535

Merged
tlopex merged 4 commits into
apache:mainfrom
ConvolutedDog:fix-19533
May 12, 2026
Merged

[Fix][Relax]: ONNX Clip NaN bounds and preserve input NaN (ORT parity)#19535
tlopex merged 4 commits into
apache:mainfrom
ConvolutedDog:fix-19533

Conversation

@ConvolutedDog
Copy link
Copy Markdown
Contributor

This PR fixes #19533:

  • Sanitize floating tensor min/max: replace NaN with +inf/-inf before topi max/min so bounds match ONNX "unbounded" semantics where NaN bounds default to no constraint.
  • After clamping, preserve NaNs from the input tensor on floating dtypes.
  • Extend check_correctness with equal_nan for float outputs containing NaN.
  • Add parametrized Clip opset-13 tests for NaN min/max tensor bounds.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the ONNX Clip operator implementation in Relax to correctly handle NaN values in both the input tensor and the clip bounds (min/max). It introduces a helper function to identify floating-point types and a sanitization method for NaN bounds. Feedback includes correcting the casing of DataTypeCode constants to avoid runtime errors, refactoring duplicated comparison logic in tests, removing redundant test parameters, and expanding test coverage to explicitly verify that input NaNs are preserved.

Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py
Comment thread tests/python/relax/test_frontend_onnx.py Outdated
Comment thread tests/python/relax/test_frontend_onnx.py
Comment thread tests/python/relax/test_frontend_onnx.py Outdated
…k_correctness

- Extend tvm.testing.assert_allclose with equal_nan (forwarded to NumPy) and document parameters.
- Refactor check_correctness _check_output to normalize ndarray once and call a single assert helper.
- Parametrize test_clip_v13 over input vectors (finite vs NaN); adjust Clip v13 min/max fixture where needed.
@ConvolutedDog ConvolutedDog marked this pull request as draft May 12, 2026 02:10
@ConvolutedDog ConvolutedDog marked this pull request as ready for review May 12, 2026 08:35
@tlopex tlopex merged commit b1918c7 into apache:main May 12, 2026
10 checks passed
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.

[Bug] Relax ONNX Clip with NaN max bound returns all NaNs

2 participants