You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by an...@apache.org on 2023/05/01 16:29:46 UTC
[tvm] branch main updated: [Relay][Bugfix] Fix stride in LpPool for default (#14740)
This is an automated email from the ASF dual-hosted git repository.
andrewzhaoluo 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 a8d26f4452 [Relay][Bugfix] Fix stride in LpPool for default (#14740)
a8d26f4452 is described below
commit a8d26f44523e2163526f474e2e87a49a3270a539
Author: Qingchao Shen <qi...@outlook.com>
AuthorDate: Tue May 2 00:29:38 2023 +0800
[Relay][Bugfix] Fix stride in LpPool for default (#14740)
* Update onnx.py
* Update test_forward.py
* Update test_forward.py
* Update onnx.py
* add comment
* modify test case
---
python/tvm/relay/frontend/onnx.py | 4 +++-
tests/python/frontend/onnx/test_forward.py | 11 +++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py
index 5e72abd65d..05e86dbe00 100644
--- a/python/tvm/relay/frontend/onnx.py
+++ b/python/tvm/relay/frontend/onnx.py
@@ -1988,6 +1988,7 @@ class LpPool(OnnxOpConverter):
data = inputs[0]
input_shape = infer_shape(data)
ndim = len(input_shape)
+ num_spatial_dims = ndim - 2
if "auto_pad" in attr:
attr["auto_pad"] = attr["auto_pad"].decode("utf-8")
if attr["auto_pad"] in ("SAME_UPPER", "SAME_LOWER"):
@@ -1995,7 +1996,8 @@ class LpPool(OnnxOpConverter):
# one will need to run dynamic_to_static on this model after import
data = autopad(
data,
- attr["strides"],
+ # this is meant to handle the field 'strides' being optional for opsets 11+
+ attr.get("strides", [1] * num_spatial_dims),
attr["kernel_shape"],
[1] * ndim,
mode=attr["auto_pad"],
diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py
index cf5795837c..517514df7f 100644
--- a/tests/python/frontend/onnx/test_forward.py
+++ b/tests/python/frontend/onnx/test_forward.py
@@ -3939,6 +3939,17 @@ def test_lppool(target, dev):
auto_pad="SAME_UPPER",
)
+ # Pool2D with empty stride
+ verify_lppool(
+ x_shape=[1, 3, 32, 32],
+ kernel_shape=[2, 2],
+ p=4,
+ strides=None,
+ pads=None,
+ out_shape=[1, 3, 32, 32],
+ auto_pad="SAME_LOWER",
+ )
+
# Pool3D with stride
verify_lppool(
x_shape=[1, 1, 32, 32, 32],