From 17311c46b3e8e5680cca6846afe24cc357959055 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 18 Feb 2022 09:41:17 +0300 Subject: [PATCH] [LPT] checkElementwise extending for 1D tensor (#10498) --- .../src/fake_quantize_dequantization.cpp | 6 +- .../src/network_helper.cpp | 2 + .../multiply_transformation.cpp | 72 ++++++++++++++++++- .../src/multiply_function.cpp | 14 ---- 4 files changed, 78 insertions(+), 16 deletions(-) diff --git a/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp b/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp index f1fff57fcf4..9e9b93280cf 100644 --- a/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp +++ b/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp @@ -123,12 +123,16 @@ bool FakeQuantizeDequantization::checkElementwise(const std::shared_ptr 1ul ? 1ul : 0ul]; if (channelsDimension.is_dynamic()) { return false; } const size_t channelsShapeVal = channelsDimension.get_length(); + if (constShape.size() == 1ul) { + return constShape[0] == channelsShapeVal; + } + const size_t rank = partialShape.rank().get_length(); if (constShape.size() == rank) { if ((constShape[0] != 1ul) || (constShape[1] != channelsShapeVal)) { diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cpp index a07910b7fcc..2ede193b4f9 100644 --- a/src/common/low_precision_transformations/src/network_helper.cpp +++ b/src/common/low_precision_transformations/src/network_helper.cpp @@ -1424,6 +1424,8 @@ FakeQuantizeDequantization NetworkHelper::normalizeDequantization(FakeQuantizeDe if (dequantization.empty()) { return dequantization; } + + // task: 79740 if (dequantization.multiply != nullptr && ov::as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(0))) { const auto leftParent = dequantization.multiply->input_value(0); const auto rightParent = dequantization.multiply->input_value(1); diff --git a/src/tests/functional/inference_engine/lp_transformations/multiply_transformation.cpp b/src/tests/functional/inference_engine/lp_transformations/multiply_transformation.cpp index 5a4114efa65..74181a5b753 100644 --- a/src/tests/functional/inference_engine/lp_transformations/multiply_transformation.cpp +++ b/src/tests/functional/inference_engine/lp_transformations/multiply_transformation.cpp @@ -697,7 +697,7 @@ const std::vector multiplyTransformationTestVa } }, - // Constant as input + // Constant as input with empty shape { LayerTransformation::createParamsU8I8(), { @@ -732,6 +732,76 @@ const std::vector multiplyTransformationTestVa } }, + // Constant as input with 1 dimension shape + { + LayerTransformation::createParamsU8I8(), + { + { + {}, + {{ 7.f, 8.f, 9.f }, ngraph::element::i8, ngraph::Shape{3}}, // Constant as input + ngraph::element::i8, + {ngraph::element::f32, { }, { {0.1f, 0.2f, 0.3f}, element::f32, ngraph::Shape{3} }}, + }, + { + { 1, 2, 3 }, + {}, + ngraph::element::f32, + {{}, {}, {{0.2f, 0.3f, 0.4f}, element::f32, ngraph::Shape{3}}}, + }, + false + }, + { + { + { 1, 2, 3 }, + {}, + ngraph::element::f32, + {}, + }, + { + {}, + { {0.14f, 0.48f, 1.08f}, ngraph::element::f32, ngraph::Shape{3}}, // Constant as input + {}, + {}, + }, + true + } + }, + + // Parameter as input with, Constant with 1 dimension shape + { + LayerTransformation::createParamsU8I8(), + { + { + { 1, 2, 3 }, + {}, + ngraph::element::f32, + {{}, {}, {{0.2f, 0.3f, 0.4f}, element::f32, ngraph::Shape{3}}}, + }, + { + {}, + {{ 7.f, 8.f, 9.f }, ngraph::element::i8, ngraph::Shape{3}}, // Constant as input + ngraph::element::i8, + {ngraph::element::f32, { }, { {0.1f, 0.2f, 0.3f}, element::f32, ngraph::Shape{3} }}, + }, + false + }, + { + { + { 1, 2, 3 }, + {}, + ngraph::element::f32, + {}, + }, + { + {}, + { {0.14f, 0.48f, 1.08f}, ngraph::element::f32, ngraph::Shape{3}}, // Constant as input + {}, + {}, + }, + true + } + }, + // Actual: // // Parameter Constant Constant Constant diff --git a/src/tests/ngraph_helpers/lpt_ngraph_functions/src/multiply_function.cpp b/src/tests/ngraph_helpers/lpt_ngraph_functions/src/multiply_function.cpp index 86a5889739e..493054a95d1 100644 --- a/src/tests/ngraph_helpers/lpt_ngraph_functions/src/multiply_function.cpp +++ b/src/tests/ngraph_helpers/lpt_ngraph_functions/src/multiply_function.cpp @@ -24,20 +24,6 @@ struct BranchNodes { }; BranchNodes getBranch(const MultiplyBranch& branch) { - if (!branch.constant.empty()) { - if (branch.inputShape != branch.constant.shape) { - std::ostringstream message; - message << "shapes are not equals: " << branch.inputShape << " & " << branch.constant.shape; - throw std::runtime_error(message.str()); - } - - if (branch.precisionBeforeDequantization != branch.constant.outPrecision) { - std::ostringstream message; - message << "precisions are not equals: " << branch.precisionBeforeDequantization << " & " << branch.constant.outPrecision; - throw std::runtime_error(message.str()); - } - } - const std::shared_ptr parent = branch.constant.empty() ? std::make_shared(branch.precisionBeforeDequantization, branch.inputShape) : std::dynamic_pointer_cast(std::make_shared(