This is an automated email from the ASF dual-hosted git repository.
echuraev pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 72ce7013e4 [Relay][ONNX] Fix the attribute mode parse of operator
Upsample (#16622)
72ce7013e4 is described below
commit 72ce7013e46c432dd1f8c3e1ec862a1e72b9798e
Author: Qingchao Shen <[email protected]>
AuthorDate: Fri Feb 23 15:54:50 2024 +0800
[Relay][ONNX] Fix the attribute mode parse of operator Upsample (#16622)
* add the default value for mode attrbute of Upsample
* Update test_forward.py
* Update onnx.py
* Update test_forward.py
---
python/tvm/relay/frontend/onnx.py | 2 +-
tests/python/frontend/onnx/test_forward.py | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/python/tvm/relay/frontend/onnx.py
b/python/tvm/relay/frontend/onnx.py
index 3023cd039c..b95afae1d1 100644
--- a/python/tvm/relay/frontend/onnx.py
+++ b/python/tvm/relay/frontend/onnx.py
@@ -2392,7 +2392,7 @@ class Upsample(OnnxOpConverter):
if not isinstance(scales, _expr.Expr):
assert scales[0] == 1.0 and scales[1] == 1.0
- mode = attr.get("mode")
+ mode = attr.get("mode", b"nearest")
if mode == b"nearest":
method = "nearest_neighbor"
elif mode == b"linear":
diff --git a/tests/python/frontend/onnx/test_forward.py
b/tests/python/frontend/onnx/test_forward.py
index cfa30ad346..543aa7f518 100644
--- a/tests/python/frontend/onnx/test_forward.py
+++ b/tests/python/frontend/onnx/test_forward.py
@@ -1726,6 +1726,27 @@ def test_upsample_nearest(target, dev):
verify_with_ort_with_inputs(model, [in_array], [out_shape], opset=7,
target=target, dev=dev)
[email protected]_targets
+def test_upsample_nearest_default(target, dev):
+ """test_upsample_nearest_default"""
+ scale = 2
+ in_shape = (1, 1, 3, 3)
+ out_shape = (1, 1, 3 * scale, 3 * scale)
+ y = helper.make_node("Upsample", ["in"], ["out"], scales=[1.0, 1.0, 2.0,
2.0])
+
+ in_array = np.random.uniform(size=in_shape).astype(np.float32)
+
+ graph = helper.make_graph(
+ [y],
+ "upsample_nearest_test",
+ inputs=[helper.make_tensor_value_info("in", TensorProto.FLOAT,
list(in_shape))],
+ outputs=[helper.make_tensor_value_info("out", TensorProto.FLOAT,
list(out_shape))],
+ )
+
+ model = helper.make_model(graph, producer_name="upsample_nearest_test")
+ verify_with_ort_with_inputs(model, [in_array], [out_shape], opset=7,
target=target, dev=dev)
+
+
@tvm.testing.parametrize_targets
def test_upsample3d_nearest(target, dev):
"""test_upsample3d_nearest"""
@@ -5708,6 +5729,7 @@ unsupported_onnx_tests = [
"test_unique_sorted_with_axis_3d",
"test_unique_sorted_with_negative_axis",
"test_upsample_nearest",
+ "test_upsample_nearest_default",
]