Repository navigation
Conversation
… 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>
Author
|
@mshr-h gentle ping; this lowers onnx ThresholdedRelu with |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An active optional nit recommends reusing run_in_tvm in the ONNX test to avoid duplicating the compilation/VM pipeline and prevent the opset-version warning.
1 open issue
What changed in this PR
Fixes Relax’s ONNX ThresholdedRelu conversion to handle nonfinite values correctly and support float16 and float64 inputs, addressing #20851.
Changes:
- Replaces mask multiplication with
where, using constants in the input dtype. - Updates expected IR and adds exact-output and dtype regression checks for float32, float16, and float64.
| File | Description |
|---|---|
| tests/python/relax/test_frontend_onnx.py | Updates expected IR and covers nonfinite values across three floating-point dtypes. |
| python/tvm/relax/frontend/onnx/onnx_frontend.py | Lowers ThresholdedRelu through typed conditional selection. |
Review effort: Max
… test Signed-off-by: Dundy Pasupuleti <dundysm@gmail.com>
mshr-h
approved these changes
Nov 13, 2026
Contributor
|
@dundysm please check ci errors. |
Signed-off-by: Dundy Pasupuleti <dundysm@gmail.com>
Author
Author
|
@guan404ming this is approved and ci is green on the latest head; could you merge it when you get a chance? thanks |
guan404ming
approved these changes
Dec 1, 2026
Member
|
LGTM, waiting for the ci and I will merge this. Thanks! |
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.

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:
test_thresholded_relu_nonfinite_and_dtypesruns[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.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.