Skip to content

Commit

Permalink
[Relay][Bugfix] Fix stride in LpPool for default (#14740)
Browse files Browse the repository at this point in the history
* Update onnx.py

* Update test_forward.py

* Update test_forward.py

* Update onnx.py

* add comment

* modify test case
  • Loading branch information
jikechao authored May 1, 2023
1 parent e2e1696 commit a8d26f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,14 +1988,16 @@ def _impl_v1(cls, inputs, attr, params):
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"):
# Warning: LpPool does not yet support dynamic shapes,
# 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"],
Expand Down
11 changes: 11 additions & 0 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3939,6 +3939,17 @@ def verify_lppool(x_shape, kernel_shape, p, strides, pads, out_shape, auto_pad="
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],
Expand Down

0 comments on commit a8d26f4

Please sign in to comment.