Skip to content

fix(relax/onnx): apply dtype limits when Clip bounds are omitted - #20844

Open
173787247 wants to merge 1 commit into
apache:mainfrom
173787247:fix/onnx-clip-default-bounds
Open

173787247 wants to merge 1 commit into
apache:mainfrom
173787247:fix/onnx-clip-default-bounds

Conversation

@173787247

Copy link
Copy Markdown

Fixes #20841

Problem

For Clip-13, when the optional min/max inputs are omitted, ONNX defines the bounds as the finite limits of the input dtype. The frontend returned the input unchanged in that case, so infinities survived instead of being clamped to the dtype limits.

Example: float32 input [+inf, -inf, 0] through Clip with no min/max:

  • ONNX Runtime: [FLT_MAX, -FLT_MAX, 0]
  • TVM (before): [+inf, -inf, 0]

Change

  • Clip._impl_v13 now emits the clamp with the dtype limits when min/max is absent (numpy.finfo/iinfo for float and integer dtypes; dtypes unknown to numpy keep the previous unbounded default).
  • Provided bounds keep the existing NaN sanitization, and the emission order is unchanged.
  • Updated the Clip structural expectations for the min-only, max-only and no-bound cases.
  • Added test_clip_v13_omitted_bounds, checked against ONNX Runtime.

Validation

pytest tests/python/relax/test_frontend_onnx.py -k clip passes (8 tests), and the reported input now produces [FLT_MAX, -FLT_MAX, 0].

@173787247
173787247 force-pushed the fix/onnx-clip-default-bounds branch 2 times, most recently from 10f560d to 21bebe0 Compare October 29, 2026 01:10
ONNX Clip-13 defines omitted min/max inputs as the finite limits of the
input dtype.  The frontend skipped the clamp entirely in that case, so an
input containing infinities came out unchanged instead of clamped to the
dtype limits.

Emit the maximum/minimum with dtype limits when the corresponding input
is absent, keeping the NaN-bound handling for provided bounds.  Use a
constant of the input dtype so the result dtype is preserved, and skip
the clamp for integer inputs where the limit is identity.  Update the
Clip expectations for the min-only, max-only and no-bound cases, and add
an ONNX Runtime checked regression test for the omitted bounds.
@173787247
173787247 force-pushed the fix/onnx-clip-default-bounds branch from 21bebe0 to 6113bb3 Compare October 29, 2026 01:10

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.

[Bug][Relax][ONNX] Clip without optional bounds preserves infinities instead of finite schema defaults

1 participant