diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 5e72abd65d7b..05e86dbe004b 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -1988,6 +1988,7 @@ 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"): @@ -1995,7 +1996,8 @@ def _impl_v1(cls, inputs, attr, params): # 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 cf5795837cce..517514df7f7a 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -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],