This is an automated email from the ASF dual-hosted git repository.
syfeng 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 e754bc2325 [Relay][Bugfix] Fix conv transpose with default strides in
ONNX frontend (#15868)
e754bc2325 is described below
commit e754bc23258f4e1125027b61ca45651a1f682767
Author: Qingchao Shen <[email protected]>
AuthorDate: Wed Oct 4 20:35:48 2023 +0800
[Relay][Bugfix] Fix conv transpose with default strides in ONNX frontend
(#15868)
* fix strides in ConvTranspose converter
* Update test_forward.py
---
python/tvm/relay/frontend/onnx.py | 4 +++-
tests/python/frontend/onnx/test_forward.py | 9 +++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/python/tvm/relay/frontend/onnx.py
b/python/tvm/relay/frontend/onnx.py
index 9934d4f132..9a42fe2490 100644
--- a/python/tvm/relay/frontend/onnx.py
+++ b/python/tvm/relay/frontend/onnx.py
@@ -931,6 +931,7 @@ class ConvTranspose(OnnxOpConverter):
data = inputs[0]
input_shape = infer_shape(data)
ndim = len(input_shape)
+ num_spatial_dims = ndim - 2
if "auto_pad" in attr or "output_shape" in attr:
if "auto_pad" in attr:
attr["auto_pad"] = attr["auto_pad"].decode("utf-8")
@@ -941,7 +942,8 @@ class ConvTranspose(OnnxOpConverter):
kndim = len(kernel_shape)
dilations = attr.get("dilations", [1] * kndim)
output_padding = attr.get("output_padding", [0] * kndim)
- strides = attr["strides"]
+ # this is meant to handle the field 'strides' being optional
for opsets 11+
+ strides = attr.get("strides", [1] * num_spatial_dims)
total_pad = [0] * kndim
#
https://github.com/onnx/onnx/blob/main/docs/Operators.md#ConvTranspose
if "output_shape" in attr:
diff --git a/tests/python/frontend/onnx/test_forward.py
b/tests/python/frontend/onnx/test_forward.py
index b9f2d14b78..9c9362aaf1 100644
--- a/tests/python/frontend/onnx/test_forward.py
+++ b/tests/python/frontend/onnx/test_forward.py
@@ -3340,6 +3340,15 @@ def test_convtranspose(target, dev):
repeat(1, dims),
auto_pad="SAME_UPPER",
)
+ # Convolution with default stride
+ verify_convtranspose_with_padding(
+ (1, 1) + repeat(5, dims),
+ (1, 1) + repeat(3, dims),
+ 2 * repeat(1, dims),
+ repeat(3, dims),
+ None,
+ repeat(1, dims),
+ )
# Convolution with dilation
# TODO(mbrookhart): Relay doesn't currently support convtranspose with
dilation
# verify_convtranspose_with_padding(