OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Use AvgPool-14 in PT FE (#25471)
Przemyslaw Wysockif569b775fe4a
diff --git a/src/frontends/pytorch/src/op/avg_poolnd.cpp b/src/frontends/pytorch/src/op/avg_poolnd.cppindex 65e1e3ba92d..03c32259b45 100644--- a/src/frontends/pytorch/src/op/avg_poolnd.cpp+++ b/src/frontends/pytorch/src/op/avg_poolnd.cpp@@ -40,35 +40,15 @@ OutputVector translate_avg_poolnd(const NodeContext& context) {}ov::op::RoundingType rounding_type = ov::op::RoundingType::FLOOR;if (!(context.input_is_none(4))) {- rounding_type = context.const_input<bool>(4) ? ov::op::RoundingType::CEIL : ov::op::RoundingType::FLOOR;+ rounding_type = context.const_input<bool>(4) ? ov::op::RoundingType::CEIL_TORCH : ov::op::RoundingType::FLOOR;}if (!(context.input_is_none(5))) {count_include_pad = context.const_input<bool>(5);}PYTORCH_OP_CONVERSION_CHECK(context.input_is_none(6),"Translation for aten::avg_pool2d do not support divisor_override input.");- // Although ov::AvgPool provides exclude_pad=false,- // The corner case of Average Pooling with ceil_mode on- // PyTorch allows sliding window go off bound, which leads to this accommodation.- // More detail on https://github.com/pytorch/pytorch/issues/57178- if (count_include_pad) {- auto zero = context.mark_node(v0::Constant::create(element::f32, Shape{}, {0}));- zero = context.mark_node(std::make_shared<v1::ConvertLike>(zero, input));- auto zero_i32 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0}));- Output<Node> rank;- std::tie(std::ignore, rank) = get_shape_rank(context, input);- auto pad_values = get_input_as_i32(context, 3);- auto pads_len = context.mark_node(v0::Constant::create(element::i32, Shape{}, {pads.size()}));- auto pads_diff = context.mark_node(std::make_shared<v1::Subtract>(rank, pads_len));- auto pads_remaining = context.mark_node(std::make_shared<v3::Broadcast>(zero_i32, pads_diff));- auto padding = context.mark_node(- std::make_shared<v0::Concat>(OutputVector{std::move(pads_remaining), std::move(pad_values)}, 0));- input = context.mark_node(std::make_shared<v1::Pad>(input, padding, padding, zero, ov::op::PadMode::CONSTANT));- pads = Shape(pads.size(), 0);- }-return {context.mark_node(- std::make_shared<v1::AvgPool>(input, strides, pads, pads, kernel, !count_include_pad, rounding_type))};+ std::make_shared<v14::AvgPool>(input, strides, pads, pads, kernel, !count_include_pad, rounding_type))};};} // namespace opdiff --git a/tests/layer_tests/pytorch_tests/test_pooling.py b/tests/layer_tests/pytorch_tests/test_pooling.pyindex 0cf2446abd1..32c8a973cb1 100644--- a/tests/layer_tests/pytorch_tests/test_pooling.py+++ b/tests/layer_tests/pytorch_tests/test_pooling.py@@ -17,10 +17,9 @@ d2_params = [{'kernel_size': [3, 3], 'stride': 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},+ {'kernel_size': [8, 8], 'stride': [8, 4], 'padding': 1},]-d2_params_corner_case = [{'kernel_size': [8, 8], 'stride': [8, 4], 'padding': 1}]-d1_params = [{'kernel_size': 3, 'stride': 1, 'padding': 0},{'kernel_size': (4,), 'stride': 1, 'padding': 1},{'kernel_size': 4, 'stride': (5,), 'padding': 2},@@ -144,14 +143,7 @@ class TestPooling(PytorchLayerTest):dynamic_shapes=False)@pytest.mark.parametrize(- "params",- d2_params- + [- pytest.param(- {"kernel_size": [8, 8], "stride": [8, 4], "padding": 1},- marks=pytest.mark.xfail(reason="Sliding windows that would start in the right padded are ignored.")- )- ])+ "params", d2_params)@pytest.mark.parametrize("ceil_mode", [True, False])@pytest.mark.parametrize("count_include_pad", [True, False])@pytest.mark.nightly@@ -161,6 +153,8 @@ class TestPooling(PytorchLayerTest):@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',reason='Ticket - 122715')def test_avg_pool2d(self, params, ceil_mode, count_include_pad, ie_device, precision, ir_version):+ if ceil_mode and count_include_pad and np.array_equal(np.array(params["kernel_size"]), np.array([8, 8])):+ pytest.xfail("Ticket - 150292")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, freeze_model=False, dynamic_shapes=False)@@ -190,7 +184,7 @@ 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_params + d2_params_corner_case)+ @pytest.mark.parametrize("params", d2_params)@pytest.mark.parametrize("ceil_mode", [True, False])@pytest.mark.parametrize("dilation", [1, 2])@pytest.mark.parametrize("dtype", [torch.float32, torch.int32])@@ -227,7 +221,7 @@ class TestPooling(PytorchLayerTest):self._test(*self.create_model("max_pool1d_with_indices", **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_params + d2_params_corner_case)+ @pytest.mark.parametrize("params", d2_params)@pytest.mark.parametrize("ceil_mode", [True, False])@pytest.mark.parametrize("dilation", [1, 2])@pytest.mark.nightly