Skip to content

Commit

Permalink
[Core] Fixed shape inference for Reduce* (#22462)
Browse files Browse the repository at this point in the history
### Details:
- Fixed shape inference for Reduce* in case axes come as an input
parameter

### Tickets:
 - 134036

---------

Co-authored-by: Evgenya Nugmanova <eva.my.link@gmail.com>
Co-authored-by: Andrei Kochin <andrei.kochin@intel.com>
  • Loading branch information
3 people authored Feb 28, 2024
1 parent 19f5946 commit bd57987
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/core/shape_inference/include/reduce_shape_inference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ std::vector<TRShape> reduce_shape_infer(const util::ReductionBase* op,
if (keep_dims) {
output_shapes.push_back(ov::PartialShape::dynamic(data_shape.rank()));
} else {
output_shapes.push_back(ov::PartialShape::dynamic());
if (axes_shape.is_static() && shape_size(axes_shape.to_shape()) == 1) {
// since there is the only axis, it is unique/not duplicated by definition. we can safely propagate rank
output_shapes.push_back(ov::PartialShape::dynamic(data_rank - 1));
} else {
output_shapes.push_back(ov::PartialShape::dynamic());
}
}
}
return output_shapes;
Expand Down
17 changes: 16 additions & 1 deletion src/core/tests/type_prop_layers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2018-2023 Intel Corporation
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

Expand All @@ -10,6 +10,7 @@
#include "openvino/op/ctc_greedy_decoder.hpp"
#include "openvino/op/interpolate.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/reduce_prod.hpp"
#include "openvino/op/region_yolo.hpp"
#include "openvino/op/reorg_yolo.hpp"
#include "openvino/op/roi_pooling.hpp"
Expand Down Expand Up @@ -73,3 +74,17 @@ TEST(type_prop_layers, roi_pooling) {
auto op = make_shared<op::v0::ROIPooling>(inputs, coords, Shape{6, 6}, 0.0625f, "max");
ASSERT_EQ(op->get_shape(), (Shape{150, 3, 6, 6}));
}

TEST(type_prop_layers, reduce_axes_1) {
auto inputs = make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, 3, 4, 5});
auto axes = make_shared<ov::op::v0::Parameter>(element::i32, Shape{1});
auto op = make_shared<op::v1::ReduceProd>(inputs, axes, false);
ASSERT_EQ(op->get_output_partial_shape(0), PartialShape::dynamic(3));
}

TEST(type_prop_layers, reduce_axes_2) {
auto inputs = make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, 3, 4, 5});
auto axes = make_shared<ov::op::v0::Parameter>(element::i32, Shape{2});
auto op = make_shared<op::v1::ReduceProd>(inputs, axes, false);
ASSERT_EQ(op->get_output_partial_shape(0), PartialShape::dynamic());
}
1 change: 0 additions & 1 deletion src/frontends/onnx/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True):
xfail_issue_38735 = xfail_test(reason="RuntimeError: OV does not support the following ONNX operations: "
"ai.onnx.preview.training.Adagrad")
xfail_issue_48052 = xfail_test(reason="Dropout op is not supported in traning mode")
xfail_issue_45180 = xfail_test(reason="RuntimeError: Unsupported dynamic op: ReduceSum")
xfail_issue_44851 = xfail_test(reason="Expected: Unsupported dynamic op: Broadcast")
xfail_issue_44858 = xfail_test(reason="Expected: Unsupported dynamic op: Unsqueeze")
xfail_issue_44957 = xfail_test(reason="Expected: Unsupported dynamic op: NonZero")
Expand Down
14 changes: 0 additions & 14 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
skip_issue_58676,
xfail_issue_44858,
xfail_issue_44965,
xfail_issue_45180,
xfail_issue_47323,
xfail_issue_73538,
xfail_issue_48052,
Expand Down Expand Up @@ -276,11 +275,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_training_dropout_default_mask_cpu",
"OnnxBackendNodeModelTest.test_training_dropout_zero_ratio_mask_cpu",
),
(
xfail_issue_45180,
"OnnxBackendNodeModelTest.test_reduce_sum_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_do_not_keepdims_random_cpu",
),
(
xfail_issue_44858,
"OnnxBackendNodeModelTest.test_unsqueeze_axis_0_cpu",
Expand Down Expand Up @@ -483,17 +477,13 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
(
xfail_issue_99968,
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_example_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_random_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_keep_dims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_negative_axes_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_negative_axes_keep_dims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_do_not_keepdims_example_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_do_not_keepdims_random_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_keep_dims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_negative_axes_keep_dims_example_cpu",
Expand All @@ -503,9 +493,7 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_reduce_log_sum_desc_axes_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_desc_axes_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_do_not_keepdims_example_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_do_not_keepdims_random_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_exp_negative_axes_keepdims_example_cpu",
Expand Down Expand Up @@ -537,9 +525,7 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_reduce_prod_negative_axes_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_prod_negative_axes_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_do_not_keepdims_example_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_do_not_keepdims_random_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_sum_square_negative_axes_keepdims_example_cpu",
Expand Down

0 comments on commit bd57987

Please sign in to comment.