From 4c74924fb05bb73a35f7c6a9f392965a3c408965 Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Fri, 9 Jun 2023 18:31:20 +0200 Subject: [PATCH] AlignEltwiseInputRanks - fix when output rank is less than constant rank (#17895) Fixes an issue when AlignEltwiseInputRanks is applied on FakeQuantize with scalar as a first input and input/output low/high being Shape{1} constants. In such case FakeQuantize output is still a scalar, so the difference between output rank and input/output low/high rank is negative. Ticket: CVS-112454 --- .../align_eltwise_input_ranks.cpp | 4 ++-- .../align_eltwise_input_ranks.cpp | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp b/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp index 229e8df7d7fc07..2d192222fca15a 100644 --- a/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp @@ -39,14 +39,14 @@ ov::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() { return false; } - const auto rank = node->get_output_partial_shape(0).size(); + const auto rank = static_cast(node->get_output_partial_shape(0).size()); for (size_t i = 0; i < node->get_input_size(); i++) { auto const_node = as_type(node->get_input_node_ptr(i)); if (const_node == nullptr) continue; const auto& const_shape = const_node->get_shape(); - auto diff = rank - const_shape.size(); + auto diff = rank - static_cast(const_shape.size()); if (diff > 0) { Shape new_shape = const_shape; new_shape.insert(new_shape.begin(), diff, 1); diff --git a/src/common/transformations/tests/common_optimizations/align_eltwise_input_ranks.cpp b/src/common/transformations/tests/common_optimizations/align_eltwise_input_ranks.cpp index 16f3ce89895e45..456a2866c96919 100644 --- a/src/common/transformations/tests/common_optimizations/align_eltwise_input_ranks.cpp +++ b/src/common/transformations/tests/common_optimizations/align_eltwise_input_ranks.cpp @@ -14,10 +14,10 @@ using namespace ngraph; using AlignEltwiseInputRanksParams = std::tuple; -class AlignEltwiseInputRanksTest : public testing::WithParamInterface, - public TransformationTestsF {}; +class AlignEltwiseInputRanksTestP : public testing::WithParamInterface, + public TransformationTestsF {}; -TEST_P(AlignEltwiseInputRanksTest, FusionTest) { +TEST_P(AlignEltwiseInputRanksTestP, FusionTest) { auto params = GetParam(); const auto& input_shape = std::get<0>(params); auto const_shape = std::get<1>(params); @@ -77,4 +77,20 @@ static std::vector params = { AlignEltwiseInputRanksParams(Shape{}, {2, 3, 4}, {}, false), }; -INSTANTIATE_TEST_SUITE_P(TransformationTests, AlignEltwiseInputRanksTest, ::testing::ValuesIn(params)); +INSTANTIATE_TEST_SUITE_P(TransformationTests, AlignEltwiseInputRanksTestP, ::testing::ValuesIn(params)); + +class AlignEltwiseInputRanksTestF : public TransformationTestsF {}; + +TEST_F(AlignEltwiseInputRanksTestF, NegativeFakeQuantizeWithScalarFirstInput) { + { + auto data = op::Constant::create(element::f32, Shape{}, {10}); + auto low = op::Constant::create(element::f32, Shape{1}, {0}); + auto high = op::Constant::create(element::f32, Shape{1}, {20}); + auto fq = std::make_shared(data, low, high, low, high, 256); + function = std::make_shared(fq->outputs()); + + manager.register_pass(); + } + + comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES); +}