Skip to content

Add torch AdaptiveAvgPool2d test. #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2022
Merged
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
34 changes: 31 additions & 3 deletions coremltools/converters/mil/frontend/torch/test/test_torch_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ class TestAdaptiveMaxPool(TorchBaseTest):
@pytest.mark.parametrize(
"output_size, magnification, delta, depth, backend",
itertools.product(
[(1,1), (3,2)],
[(1, 1), (3, 2)],
[1, 2, 7],
[0, 11],
[1, 2, 3],
Expand All @@ -1466,15 +1466,43 @@ def test_adaptive_max_pool2d(
# since coremltools reproduces PyTorch's kernel sizes and
# offsets for adaptive pooling layers only when input_size is
# a multiple of output_size, we expect failures otherwise
if not (input_size[0] % output_size[0] == 0 and input_size[1] % output_size[1] == 0):
if not (input_size[0] % output_size[0] == 0 and input_size[1] % output_size[1] == 0):
pytest.xfail("Test should fail because input_size is not a multiple of output_size")
n = 1
in_shape = (n,depth) + input_size
in_shape = (n, depth) + input_size
model = nn.AdaptiveMaxPool2d(
output_size
)
self.run_compare_torch(in_shape, model, backend=backend)

class TestAdaptiveAvgPool(TorchBaseTest):
@pytest.mark.parametrize(
"output_size, magnification, delta, depth, backend",
itertools.product(
[(1, 1), (3, 2)],
[1, 2, 7],
[0, 11],
[1, 2, 3],
backends,
),
)
def test_adaptive_avg_pool2d(
self, output_size, magnification, delta, depth, backend
):
# input_size = output_size * magnification + delta
input_size = (delta + magnification * output_size[0], delta + magnification * output_size[1])
# since coremltools reproduces PyTorch's kernel sizes and
# offsets for adaptive pooling layers only when input_size is
# a multiple of output_size, we expect failures otherwise
if not (input_size[0] % output_size[0] == 0 and input_size[1] % output_size[1] == 0):
pytest.xfail("Test should fail because input_size is not a multiple of output_size")
n = 1
in_shape = (n, depth) + input_size
model = nn.AdaptiveAvgPool2d(
output_size
)
self.run_compare_torch(in_shape, model, backend=backend)

class TestMaxPool(TorchBaseTest):

@pytest.mark.parametrize(
Expand Down