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
[core] ShapeOf preserve lower bound when upper is infinite (#21414)
Pawel Raasz67a4c1807549
diff --git a/src/core/src/op/shape_of.cpp b/src/core/src/op/shape_of.cppindex 1c12b54b1fd..293c1b5fc5a 100644--- a/src/core/src/op/shape_of.cpp+++ b/src/core/src/op/shape_of.cpp@@ -68,17 +68,16 @@ bool evaluate_bound(const Node* const node, ov::TensorVector& outputs, const boo// use node output type as it can be different than output tensor type// e.g. when v3::ShapeOf is converted to v0::ShapeOf then the output tensor will have always i64// but node output type is transferred from v3 and can be i32 (dimension inf bound is i32 max)- const auto is_out_type_i32 = node->get_output_element_type(0) == element::i32;- if (is_out_type_i32 || !is_upper) {+ if (node->get_output_element_type(0) == element::i32) {const auto in_shape_rank = in_shape.size();- const auto max_et_val = is_out_type_i32 ? static_cast<int64_t>(std::numeric_limits<int32_t>::max())- : std::numeric_limits<int64_t>::max();+ constexpr auto max_et_val = static_cast<int64_t>(std::numeric_limits<int32_t>::max());+ const auto get_val = is_upper ? &Interval::get_max_val : &Interval::get_min_val;auto limit_val = is_upper ? max_et_val : static_cast<decltype(max_et_val)>(0);auto dynamic_mask = std::vector<char>(in_shape_rank);std::transform(in_shape.begin(), in_shape.end(), dynamic_mask.begin(), [&](const Dimension& d) {- return static_cast<char>(d.get_interval().get_max_val() >= max_et_val);+ return static_cast<char>((d.get_interval().*get_val)() >= max_et_val);});const auto limit = Tensor(out_et, Shape{}, &limit_val);diff --git a/src/core/tests/type_prop/prior_box.cpp b/src/core/tests/type_prop/prior_box.cppindex 67595a3d980..0e75ef576c9 100644--- a/src/core/tests/type_prop/prior_box.cpp+++ b/src/core/tests/type_prop/prior_box.cpp@@ -212,7 +212,7 @@ TYPED_TEST_P(PriorBoxTest, preseve_partial_values_and_symbols_on_inputs) {}TYPED_TEST_P(PriorBoxTest, preseve_partial_values_inf_bound) {- auto out_size_shape = PartialShape{{1, 4}, {5, -1}}; // ShapeOf make 2nd Dim {0, -1}+ auto out_size_shape = PartialShape{{1, 4}, {5, -1}};set_shape_symbols(out_size_shape);const auto output_size = std::make_shared<Parameter>(element::u64, out_size_shape);@@ -223,7 +223,7 @@ TYPED_TEST_P(PriorBoxTest, preseve_partial_values_inf_bound) {EXPECT_EQ(op->get_output_size(), 1);EXPECT_EQ(op->get_output_element_type(0), element::f32);- EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, {0, -1}}));+ EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, {100, -1}}));EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)), Each(nullptr));}diff --git a/src/core/tests/type_prop/prior_box_clustered.cpp b/src/core/tests/type_prop/prior_box_clustered.cppindex 3470d798df6..ba5a3603aff 100644--- a/src/core/tests/type_prop/prior_box_clustered.cpp+++ b/src/core/tests/type_prop/prior_box_clustered.cpp@@ -186,7 +186,7 @@ TYPED_TEST_P(PriorBoxClusteredTest, preseve_partial_values_and_symbols_on_inputs}TYPED_TEST_P(PriorBoxClusteredTest, preseve_partial_values_inf_bound) {- auto out_size_shape = PartialShape{{1, 4}, {5, -1}}; // ShapeOf make 2nd Dim {0, -1}+ auto out_size_shape = PartialShape{{1, 4}, {5, -1}};set_shape_symbols(out_size_shape);const auto output_size = std::make_shared<Parameter>(element::u64, out_size_shape);@@ -197,7 +197,7 @@ TYPED_TEST_P(PriorBoxClusteredTest, preseve_partial_values_inf_bound) {EXPECT_EQ(op->get_output_size(), 1);EXPECT_EQ(op->get_output_element_type(0), element::f32);- EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, {0, -1}}));+ EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, {60, -1}}));EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)), Each(nullptr));}diff --git a/src/core/tests/type_prop/shape_of.cpp b/src/core/tests/type_prop/shape_of.cppindex 3556bf654d6..e383ddbaaae 100644--- a/src/core/tests/type_prop/shape_of.cpp+++ b/src/core/tests/type_prop/shape_of.cpp@@ -151,5 +151,5 @@ TEST(type_prop, shape_of_3_dynamic_value_propagation_out_i32) {auto bc_param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1});auto bc = std::make_shared<op::v1::Broadcast>(bc_param, op);- EXPECT_EQ(bc->get_output_partial_shape(0), PartialShape({-1, -1, -1, -1, {1, 1021}}));+ EXPECT_EQ(bc->get_output_partial_shape(0), PartialShape({{2, -1}, {3, -1}, -1, -1, {1, 1021}}));}diff --git a/src/core/tests/type_prop/split.cpp b/src/core/tests/type_prop/split.cppindex 7485b9487fd..1f46200b5f3 100644--- a/src/core/tests/type_prop/split.cpp+++ b/src/core/tests/type_prop/split.cpp@@ -356,7 +356,7 @@ INSTANTIATE_TEST_SUITE_P(std::make_tuple(PartialShape{Dimension(2, 6), Dimension::dynamic(), Dimension(-1, 6), Dimension(7, -1)},2,std::vector<PartialShape>{{Dimension(2, 6), Dimension::dynamic()},- {Dimension(-1, 6), Dimension::dynamic()}})),+ {Dimension(-1, 6), Dimension{7, -1}}})),PrintToStringParamName());TEST_P(SplitBoundTest, propagate_symbol_and_dynamic_value) {diff --git a/src/core/tests/type_prop/squeeze.cpp b/src/core/tests/type_prop/squeeze.cppindex 3e60a654f4b..c7d81fd97c2 100644--- a/src/core/tests/type_prop/squeeze.cpp+++ b/src/core/tests/type_prop/squeeze.cpp@@ -391,7 +391,7 @@ INSTANTIATE_TEST_SUITE_P(std::make_tuple(PartialShape{Dimension(-1)}, PartialShape{Dimension(-1)}),std::make_tuple(PartialShape{Dimension::dynamic(), 8}, PartialShape{Dimension::dynamic()}),std::make_tuple(PartialShape{Dimension(4, 8), Dimension::dynamic()}, PartialShape{Dimension(4, 8)}),- std::make_tuple(PartialShape{Dimension(20, -1), Dimension::dynamic()}, PartialShape::dynamic(1)),+ std::make_tuple(PartialShape{Dimension(20, -1), Dimension::dynamic()}, PartialShape{{20, -1}}),std::make_tuple(PartialShape{Dimension(-1, 5), Dimension::dynamic()}, PartialShape{Dimension(-1, 5)}),std::make_tuple(PartialShape{15}, PartialShape{15}),std::make_tuple(PartialShape{2, 6}, PartialShape{2})),diff --git a/src/core/tests/type_prop/tile.cpp b/src/core/tests/type_prop/tile.cppindex d3a9e5377ea..09768df294f 100644--- a/src/core/tests/type_prop/tile.cpp+++ b/src/core/tests/type_prop/tile.cpp@@ -136,7 +136,7 @@ TEST_F(TypePropTileTest, preserve_partial_values_and_symbols) {const auto op = make_op(data, shape_of_repeats);- EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, {2, 4}, {-1, 6}, -1, -1}));+ EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({2, {2, 4}, {-1, 6}, {2, -1}, -1}));EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)),ElementsAre(nullptr, nullptr, nullptr, symbols[3], symbols[4]));}diff --git a/src/core/tests/type_prop/top_k.cpp b/src/core/tests/type_prop/top_k.cppindex d34c8f17fc1..6c674efffd8 100644--- a/src/core/tests/type_prop/top_k.cpp+++ b/src/core/tests/type_prop/top_k.cpp@@ -309,12 +309,12 @@ TYPED_TEST_P(topk_type_prop, preserve_partial_values_and_symbols_k_is_interval)}TYPED_TEST_P(topk_type_prop, preserve_partial_values_and_symbols_k_is_interval_with_no_upper_bound) {- auto shape = PartialShape{{10, -1}};+ auto shape = PartialShape{{4, -1}};auto k_symbols = set_shape_symbols(shape);const auto p_k = std::make_shared<Parameter>(element::i64, shape);const auto shape_of_k = std::make_shared<ShapeOf>(p_k);- // Squeeze make scalar but if interval value has no upper bound result will be {0,inf}+ // Squeeze make scalar of interval value {4,inf}const auto k = std::make_shared<Squeeze>(shape_of_k, Constant::create(element::i64, Shape{}, {0}));auto data_shape = PartialShape{5, {2, 8}, {2, 100}};@@ -322,24 +322,24 @@ TYPED_TEST_P(topk_type_prop, preserve_partial_values_and_symbols_k_is_interval_wconst auto data = std::make_shared<Parameter>(element::f32, data_shape);{- // dim{5} k{0,inf} -> {0,5}+ // dim{5} k{4,inf} -> {4,5}const auto op = this->make_op(data, k, 0, "max", "value");EXPECT_THAT(op->get_output_partial_shape(0),- AllOf(PartialShape({{0, 5}, {2, 8}, {2, 100}}),+ AllOf(PartialShape({{4, 5}, {2, 8}, {2, 100}}),ResultOf(get_shape_symbols, ElementsAre(nullptr, symbols[1], symbols[2]))));}{- // dim{2,8} k{0,inf} -> {0,8}+ // dim{2,8} k{4,inf} -> {2,8}const auto op = this->make_op(data, k, 1, "max", "value");EXPECT_THAT(op->get_output_partial_shape(0),- AllOf(PartialShape({5, {0, 8}, {2, 100}}),+ AllOf(PartialShape({5, {2, 8}, {2, 100}}),ResultOf(get_shape_symbols, ElementsAre(symbols[0], nullptr, symbols[2]))));}{- // dim{2,100} k{0,inf} -> {0,100}+ // dim{2,100} k{4,inf} -> {2,100}const auto op = this->make_op(data, k, 2, "max", "value");EXPECT_THAT(op->get_output_partial_shape(0),- AllOf(PartialShape({5, {2, 8}, {0, 100}}),+ AllOf(PartialShape({5, {2, 8}, {2, 100}}),ResultOf(get_shape_symbols, ElementsAre(symbols[0], symbols[1], nullptr))));}}diff --git a/src/core/tests/type_prop/unsqueeze.cpp b/src/core/tests/type_prop/unsqueeze.cppindex 4796dea9f22..b3543632272 100644--- a/src/core/tests/type_prop/unsqueeze.cpp+++ b/src/core/tests/type_prop/unsqueeze.cpp@@ -264,7 +264,7 @@ INSTANTIATE_TEST_SUITE_P(std::make_tuple(PartialShape{Dimension(-1)}, PartialShape{Dimension(-1)}),std::make_tuple(PartialShape{Dimension::dynamic(), 8}, PartialShape{Dimension::dynamic()}),std::make_tuple(PartialShape{Dimension(2, 5), Dimension::dynamic()}, PartialShape{Dimension(2, 5)}),- std::make_tuple(PartialShape{Dimension(2, -1), Dimension::dynamic()}, PartialShape::dynamic(1)),+ std::make_tuple(PartialShape{Dimension(2, -1), Dimension::dynamic()}, PartialShape{{2, -1}}),std::make_tuple(PartialShape{Dimension(-1, 3), Dimension::dynamic()}, PartialShape{Dimension(-1, 3)}),std::make_tuple(PartialShape{5}, PartialShape{5}),std::make_tuple(PartialShape{2, 6}, PartialShape{2})),