This is an automated email from the ASF dual-hosted git repository.
tlopex 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 3765df7b39 [Relax][ONNX] Add edge padding mode (#18575)
3765df7b39 is described below
commit 3765df7b39dd316adbd735ef28d8bf40b04fa933
Author: Guan-Ming (Wesley) Chiu <[email protected]>
AuthorDate: Sun Dec 28 21:10:48 2025 +0800
[Relax][ONNX] Add edge padding mode (#18575)
## How
- resolving todo by add edge padding mode in onnx
- add tests for this change
---
python/tvm/relax/frontend/onnx/onnx_frontend.py | 8 ++++----
tests/python/relax/test_frontend_onnx.py | 4 ++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/python/tvm/relax/frontend/onnx/onnx_frontend.py
b/python/tvm/relax/frontend/onnx/onnx_frontend.py
index 24a4014f84..b41f56bfd4 100644
--- a/python/tvm/relax/frontend/onnx/onnx_frontend.py
+++ b/python/tvm/relax/frontend/onnx/onnx_frontend.py
@@ -1881,8 +1881,8 @@ class Pad(OnnxOpConverter):
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):
@@ -1911,8 +1911,8 @@ class Pad(OnnxOpConverter):
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):
diff --git a/tests/python/relax/test_frontend_onnx.py
b/tests/python/relax/test_frontend_onnx.py
index 23348cf847..447e1ac99d 100644
--- a/tests/python/relax/test_frontend_onnx.py
+++ b/tests/python/relax/test_frontend_onnx.py
@@ -2440,6 +2440,8 @@ def test_pad(dynamic):
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("dynamic", [True, False])
@@ -2496,6 +2498,8 @@ def test_pad_v2(dynamic):
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])