-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Relax][ONNX] Fix get_converter selecting wrong impl when opset < minimum supported version #18911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3980,5 +3980,35 @@ def test_nms_score_threshold(): | |
| ) | ||
|
|
||
|
|
||
| def test_reduce_mean(): | ||
| # opset 13: axes passed as attribute | ||
| node = helper.make_node("ReduceMean", inputs=["x"], outputs=["y"], axes=[2], keepdims=1) | ||
| graph = helper.make_graph( | ||
| [node], | ||
| "reduce_mean_test", | ||
| inputs=[helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 68, 4, 18])], | ||
| outputs=[helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 68, 1, 18])], | ||
| ) | ||
| model = helper.make_model(graph, producer_name="reduce_mean_test") | ||
| check_correctness(model, opset=13) | ||
|
|
||
|
|
||
| def test_reduce_mean_unsupported_opset(): | ||
| # Regression test for https://github.com/apache/tvm/issues/18698. | ||
| # When opset < minimum available impl version, get_converter previously | ||
| # wrapped to -1 and silently picked the newest impl instead of raising. | ||
| node = helper.make_node("ReduceMean", inputs=["x"], outputs=["y"], axes=[2], keepdims=1) | ||
| graph = helper.make_graph( | ||
| [node], | ||
| "reduce_mean_test", | ||
| inputs=[helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 68, 4, 18])], | ||
| outputs=[helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 68, 1, 18])], | ||
| ) | ||
| model = helper.make_model(graph, producer_name="reduce_mean_test") | ||
| model.opset_import[0].version = 9 | ||
| with pytest.raises(NotImplementedError, match="not supported for opset 9"): | ||
| from_onnx(model, opset=9, keep_params_in_input=True) | ||
|
|
||
|
|
||
|
Comment on lines
+3983
to
+4012
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new tests def _get_reduce_mean_model():
"""Helper to create a ReduceMean ONNX model for testing."""
node = helper.make_node("ReduceMean", inputs=["x"], outputs=["y"], axes=[2], keepdims=1)
graph = helper.make_graph(
[node],
"reduce_mean_test",
inputs=[helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 68, 4, 18])],
outputs=[helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 68, 1, 18])],
)
return helper.make_model(graph, producer_name="reduce_mean_test")
def test_reduce_mean():
# opset 13: axes passed as attribute
model = _get_reduce_mean_model()
check_correctness(model, opset=13)
def test_reduce_mean_unsupported_opset():
# Regression test for https://github.com/apache/tvm/issues/18698.
# When opset < minimum available impl version, get_converter previously
# wrapped to -1 and silently picked the newest impl instead of raising.
model = _get_reduce_mean_model()
model.opset_import[0].version = 9
with pytest.raises(NotImplementedError, match="not supported for opset 9"):
from_onnx(model, opset=9, keep_params_in_input=True)
|
||
| if __name__ == "__main__": | ||
| tvm.testing.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to raise an error for unsupported opsets is a great improvement. However, there's an edge case that could lead to an unhandled exception. If an operator has no
_impl_vNmethods, theversionslist will be empty. In this scenario,min(versions)will raise aValueError. It's better to handle this case explicitly to provide a more informative error message and prevent the crash.