Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? we should use the default strides

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/pytorch/pytorch/blob/17a5c677963dc3ecb7ff505585ed15eadaaf74ef/torch/nn/functional.py#L269-L270
According to the description of strides above, for avg_pool2d. Stride's default value kernel_size, which should have the same size as pool_size here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

padding = _infer_shape(inputs[3])

ceil_mode = int(inputs[4])
Expand Down
5 changes: 5 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down