Skip to content

[Relax][Frontend][ONNX] Lower ThresholdedRelu with where in the input dtype - #20861

Open
dundysm wants to merge 1 commit into
apache:mainfrom
dundysm:fix-onnx-thresholdedrelu
Open

dundysm wants to merge 1 commit into
apache:mainfrom
dundysm:fix-onnx-thresholdedrelu

Conversation

@dundysm

@dundysm dundysm commented Oct 31, 2026

Copy link
Copy Markdown

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:

  • new test_thresholded_relu_nonfinite_and_dtypes runs [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.
  • updated the expected IR in 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.

… 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

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] ThresholdedRelu multiply-mask lowering changes nonfinite values and hardcodes FLOAT

1 participant