Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/tvm/relax/frontend/onnx/onnx_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,8 +1881,8 @@ def _impl_v2(cls, bb, inputs, attr, params):
elif pad_mode == "reflect":
return bb.emit_te(topi.nn.mirror_pad, inputs[0], pad_before, pad_after, "REFLECT")
else:
# TODO(gigiblender) Support edge mode.
raise NotImplementedError("Pad mode {} not implemented".format(pad_mode))
# edge mode - replicate border values
return bb.emit_te(topi.nn.replicate_pad, inputs[0], pad_before, pad_after)

@classmethod
def _impl_v11(cls, bb, inputs, attr, params):
Expand Down Expand Up @@ -1911,8 +1911,8 @@ def _impl_v11(cls, bb, inputs, attr, params):
elif pad_mode == "reflect":
return bb.emit_te(topi.nn.mirror_pad, inputs[0], pad_before, pad_after, "REFLECT")
else:
# TODO(gigiblender) Support edge mode.
raise NotImplementedError("Pad mode {} not implemented".format(pad_mode))
# edge mode - replicate border values
return bb.emit_te(topi.nn.replicate_pad, inputs[0], pad_before, pad_after)


class Tile(OnnxOpConverter):
Expand Down
4 changes: 4 additions & 0 deletions tests/python/relax/test_frontend_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,8 @@ def verify_pad(input_shape, pads, mode="constant", value=0.0):
verify_pad((2, 3), [1, 0, 0, 1], "constant", 0.0)
verify_pad((3, 2), [0, 0, 1, 0], "constant", 5.0)
verify_pad((1, 3, 4, 5), [0, 1, 1, 1, 0, 0, 1, 1], "reflect")
verify_pad((2, 3), [1, 1, 1, 1], "edge")
verify_pad((1, 3, 4, 5), [0, 1, 1, 1, 0, 0, 1, 1], "edge")
Comment on lines +2443 to +2444

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These test cases for 'edge' padding are also added to test_pad_v2. To avoid code duplication, consider merging test_pad and test_pad_v2 into a single parameterized test that takes the ONNX opset version as a parameter. This would make the tests more maintainable.



@pytest.mark.parametrize("dynamic", [True, False])
Expand Down Expand Up @@ -2496,6 +2498,8 @@ def verify_pad(input_shape, pads, mode="constant", value=0.0):
verify_pad((2, 3), [1, 0, 0, 1], "constant", 0.0)
verify_pad((3, 2), [0, 0, 1, 0], "constant", 5.0)
verify_pad((1, 3, 4, 5), [0, 1, 1, 1, 0, 0, 1, 1], "reflect")
verify_pad((2, 3), [1, 1, 1, 1], "edge")
verify_pad((1, 3, 4, 5), [0, 1, 1, 1, 0, 0, 1, 1], "edge")


@pytest.mark.parametrize("fp_arith", [np.float16, np.float32])
Expand Down
Loading