[PT FE] Support default strides for avg and max pooling (#17337)

* Support default strides for avg and max pooling

* Fix code style

* Remove changes from other ticket
This commit is contained in:
Maxim Vafin 2023-05-04 09:27:10 +02:00 committed by GitHub
parent ec90869969
commit c1933fcaf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 25 deletions

View File

@ -22,7 +22,14 @@ OutputVector translate_avg_poolnd(const NodeContext& context) {
num_inputs_check(context, 6, 7);
auto input = context.get_input(0);
auto kernel = context.const_input<Shape>(1);
auto strides = context.const_input<Strides>(2);
Strides strides;
if (!context.input_is_none(2)) {
strides = context.const_input<Strides>(2);
}
if (context.input_is_none(2) || strides.size() == 0) {
// In case strides are not provided default is kernel
strides = kernel;
}
auto pads = context.const_input<Shape>(3); // pytorch supports only symmetric padding
auto rounding_type = context.const_input<bool>(4) ? ov::op::RoundingType::CEIL : ov::op::RoundingType::FLOOR;
auto count_include_pad = context.const_input<bool>(5);

View File

@ -16,7 +16,14 @@ using namespace ov::op;
OutputVector translate_max_poolnd(const NodeContext& context) {
num_inputs_check(context, 6, 6);
auto kernel = context.const_input<Shape>(1);
auto strides = context.const_input<Strides>(2);
Strides strides;
if (!context.input_is_none(2)) {
strides = context.const_input<Strides>(2);
}
if (context.input_is_none(2) || strides.size() == 0) {
// In case strides are not provided default is kernel
strides = kernel;
}
auto pads = context.const_input<Shape>(3); // pytorch supports only symmetric paddings
auto dilations = context.const_input<Strides>(4);
auto rounding_type = context.const_input<bool>(5) ? RoundingType::CEIL : RoundingType::FLOOR;

View File

@ -5,23 +5,29 @@ import pytest
from pytorch_layer_test_class import PytorchLayerTest
d2_avg_params = [{'kernel_size': [3, 3], 'stride': 1, 'padding': 0},
{'kernel_size': [3, 3], 'stride': [1, 1], 'padding': 1},
{'kernel_size': [3, 3], 'stride': [1, 1], 'padding': [0, 1]},
{'kernel_size': [3, 3], 'stride': [1, 1], 'padding': [1, 0]},
{'kernel_size': [3, 3], 'stride': [2, 1], 'padding': 0},
{'kernel_size': [2, 1], 'stride': [2, 1], 'padding': 0},
]
d2_params = [{'kernel_size': [3, 3], 'stride': 1, 'padding': 0},
{'kernel_size': [3, 3], 'stride': [1, 1], 'padding': 1},
{'kernel_size': [3, 3], 'stride': [1, 1], 'padding': [0, 1]},
{'kernel_size': [3, 3], 'stride': [1, 1], 'padding': [1, 0]},
{'kernel_size': [3, 3], 'stride': [2, 1], 'padding': 0},
{'kernel_size': [2, 1], 'stride': [2, 1], 'padding': 0},
{'kernel_size': [2, 1], 'stride': None, 'padding': 0},
{'kernel_size': [2, 1], 'stride': [], 'padding': 0},
]
d1_avg_params = [{'kernel_size': 3, 'stride': 1, 'padding': 0},
{'kernel_size': (4,), 'stride': 1, 'padding': 1},
{'kernel_size': 4, 'stride': (5,), 'padding': 2},
]
d3_avg_params = [{'kernel_size': [3, 3, 3], 'stride': 1, 'padding': 0},
{'kernel_size': [3, 3, 3], 'stride': [1, 1, 1], 'padding': 1},
{'kernel_size': [3, 3, 3], 'stride': [3, 3, 3], 'padding': [0, 0, 0]},
{'kernel_size': [3, 2, 1], 'stride': [3, 1, 1], 'padding': [0, 0, 0]},
]
d1_params = [{'kernel_size': 3, 'stride': 1, 'padding': 0},
{'kernel_size': (4,), 'stride': 1, 'padding': 1},
{'kernel_size': 4, 'stride': (5,), 'padding': 2},
{'kernel_size': 4, 'stride': None, 'padding': 0},
]
d3_params = [{'kernel_size': [3, 3, 3], 'stride': 1, 'padding': 0},
{'kernel_size': [3, 3, 3], 'stride': [1, 1, 1], 'padding': 1},
{'kernel_size': [3, 3, 3], 'stride': [
3, 3, 3], 'padding': [0, 0, 0]},
{'kernel_size': [3, 2, 1], 'stride': [
3, 1, 1], 'padding': [0, 0, 0]},
{'kernel_size': [3, 2, 1], 'stride': None, 'padding': [0, 0, 0]},
]
class TestPooling(PytorchLayerTest):
@ -101,7 +107,7 @@ class TestPooling(PytorchLayerTest):
return aten_pooling(), ref_net, f"aten::{op_type}"
@pytest.mark.parametrize("params", d1_avg_params)
@pytest.mark.parametrize("params", d1_params)
@pytest.mark.parametrize("ceil_mode", [True, False])
@pytest.mark.parametrize("count_include_pad", [True, False])
@pytest.mark.nightly
@ -111,7 +117,7 @@ class TestPooling(PytorchLayerTest):
ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 3}, trace_model=True,
dynamic_shapes=False)
@pytest.mark.parametrize("params", d2_avg_params)
@pytest.mark.parametrize("params", d2_params)
@pytest.mark.parametrize("ceil_mode", [True, False])
@pytest.mark.parametrize("count_include_pad", [True, False])
@pytest.mark.nightly
@ -120,7 +126,7 @@ class TestPooling(PytorchLayerTest):
self._test(*self.create_model("avg_pool2d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad),
ie_device, precision, ir_version, trace_model=True, dynamic_shapes=False)
@pytest.mark.parametrize("params", d3_avg_params)
@pytest.mark.parametrize("params", d3_params)
@pytest.mark.parametrize("ceil_mode", [True, False])
@pytest.mark.parametrize("count_include_pad", [True, False])
@pytest.mark.nightly
@ -130,7 +136,7 @@ class TestPooling(PytorchLayerTest):
ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 5}, trace_model=True,
dynamic_shapes=False)
@pytest.mark.parametrize("params", d1_avg_params)
@pytest.mark.parametrize("params", d1_params)
@pytest.mark.parametrize("ceil_mode", [True, False])
@pytest.mark.parametrize("dilation", [1, 2])
@pytest.mark.nightly
@ -139,16 +145,19 @@ class TestPooling(PytorchLayerTest):
self._test(*self.create_model("max_pool1d", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, kwargs_to_prepare_input={'ndim': 3}, dynamic_shapes=False)
@pytest.mark.parametrize("params", d2_avg_params)
@pytest.mark.parametrize("params", d2_params)
@pytest.mark.parametrize("ceil_mode", [True, False])
@pytest.mark.parametrize("dilation", [1, 2])
@pytest.mark.nightly
@pytest.mark.precommit
def test_max_pool2d(self, params, ceil_mode, dilation, ie_device, precision, ir_version):
to_trace = False
if params["stride"] == []:
to_trace = True
self._test(*self.create_model("max_pool2d", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, dynamic_shapes=False)
ie_device, precision, ir_version, dynamic_shapes=False, trace_model=to_trace)
@pytest.mark.parametrize("params", d3_avg_params)
@pytest.mark.parametrize("params", d3_params)
@pytest.mark.parametrize("ceil_mode", [True, False])
@pytest.mark.parametrize("dilation", [1, 2])
@pytest.mark.nightly