Skip to content

Commit

Permalink
[Relay][ONNX] Fix the attribute mode parse of operator Upsample (apac…
Browse files Browse the repository at this point in the history
…he#16622)

* add the default value for mode attrbute of Upsample

* Update test_forward.py

* Update onnx.py

* Update test_forward.py
  • Loading branch information
jikechao authored Feb 23, 2024
1 parent aa55528 commit 72ce701
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ def _impl_v9(cls, inputs, attr, params):
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":
Expand Down
22 changes: 22 additions & 0 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


@tvm.testing.parametrize_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"""
Expand Down Expand Up @@ -5708,6 +5729,7 @@ def verify_eyelike(indata, dynamic=False):
"test_unique_sorted_with_axis_3d",
"test_unique_sorted_with_negative_axis",
"test_upsample_nearest",
"test_upsample_nearest_default",
]


Expand Down

0 comments on commit 72ce701

Please sign in to comment.