diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index b256faa5d6f9..ca1d31cb9fe8 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -458,7 +458,10 @@ def _impl(inputs, input_types): data = inputs[0] pool_size = _infer_shape(inputs[1]) - strides = _infer_shape(inputs[2]) + if inputs[2]: + strides = _infer_shape(inputs[2]) + else: + strides = pool_size padding = _infer_shape(inputs[3]) ceil_mode = int(inputs[4]) diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index c2ff94de546f..e60c1fd88183 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -375,8 +375,13 @@ class AvgPool2D1(Module): def forward(self, *args): return torch.nn.AvgPool2d(kernel_size=[10, 10])(args[0]) + class AvgPool2D2(Module): + def forward(self, *args): + return torch.nn.functional.avg_pool2d(args[0], kernel_size=[10, 10]) + input_data = torch.rand(input_shape).float() verify_model(AvgPool2D1().float().eval(), input_data=input_data) + verify_model(AvgPool2D2().float().eval(), input_data=input_data) def test_forward_hardtanh(): torch.set_grad_enabled(False)