From ddd16c3a28b391507619b3b883c44566d48c3f13 Mon Sep 17 00:00:00 2001 From: Aleksandr Pertovsky Date: Fri, 9 Oct 2020 01:56:13 +0300 Subject: [PATCH] [LPT] Add NetworkHelper::mark_as_dequantization_op function [ngraph] Fix compare runtime info function [LPT] Fix test cases with no DEQUANTIZATION runtime attribute --- .../low_precision/network_helper.hpp | 2 ++ .../low_precision/network_helper.cpp | 6 ++++ .../common_test_utils/ngraph_test_utils.cpp | 28 +++++++++---------- ...d_finally_with_dequantization_function.cpp | 4 ++- ...ul_add_to_scaleshift_or_power_function.cpp | 3 +- .../normalize_l2_function.cpp | 3 +- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/inference-engine/src/transformations/include/transformations/low_precision/network_helper.hpp b/inference-engine/src/transformations/include/transformations/low_precision/network_helper.hpp index f27462bf79617e..6e872d7b91d923 100644 --- a/inference-engine/src/transformations/include/transformations/low_precision/network_helper.hpp +++ b/inference-engine/src/transformations/include/transformations/low_precision/network_helper.hpp @@ -160,6 +160,8 @@ class TRANSFORMATIONS_API NetworkHelper { // handles only specific case: Constant -> [dequantization operations] -> [node] static void foldDequantization(std::shared_ptr& node, const size_t branchIndex, const bool inPlace = false); + static std::shared_ptr mark_as_dequantization_op(std::shared_ptr op); + private: static std::shared_ptr foldFakeQuantize(const std::shared_ptr& fq, const bool roundValues, const bool roundValuesWasSet); diff --git a/inference-engine/src/transformations/src/transformations/low_precision/network_helper.cpp b/inference-engine/src/transformations/src/transformations/low_precision/network_helper.cpp index 12303a44e66c9b..f6c2112e800655 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/network_helper.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/network_helper.cpp @@ -1037,6 +1037,12 @@ std::shared_ptr NetworkHelper::toScalarIfPossible(std::shared_ptr no return NetworkHelper::toScalar(constant); } +std::shared_ptr NetworkHelper::mark_as_dequantization_op(std::shared_ptr op) { + auto opCopy = op->clone_with_new_inputs(op->input_values()); + auto& rtInfo = opCopy->get_rt_info(); + rtInfo["DEQUANTIZATION"] = std::make_shared>(DequantizationAttr()); + return opCopy; +} } // namespace low_precision } // namespace pass diff --git a/inference-engine/tests/ie_test_utils/common_test_utils/ngraph_test_utils.cpp b/inference-engine/tests/ie_test_utils/common_test_utils/ngraph_test_utils.cpp index 9832aaceb0fdfb..25dab635aeca6e 100644 --- a/inference-engine/tests/ie_test_utils/common_test_utils/ngraph_test_utils.cpp +++ b/inference-engine/tests/ie_test_utils/common_test_utils/ngraph_test_utils.cpp @@ -47,22 +47,22 @@ bool compare_rt_keys(const std::shared_ptr& node1, const std::shar const auto& first_node_rt_info = node1->get_rt_info(); const auto& second_node_rt_info = node2->get_rt_info(); - // TODO: should be uncommented - // if (first_node_rt_info.size() != second_node_rt_info.size()) { - // return false; - // } - - for (auto first_it = first_node_rt_info.begin(); first_it != first_node_rt_info.end(); ++first_it) { - bool was_found = false; - for (auto secont_it = second_node_rt_info.begin(); secont_it != second_node_rt_info.end(); ++secont_it) { - if (first_it->first == secont_it->first) { - was_found = true; - break; - } - } - if (!was_found) { + if (first_node_rt_info.empty() && second_node_rt_info.empty()) { + return true; + } + + if (first_node_rt_info.size() != second_node_rt_info.size()) { + return false; + } + + auto first_node_rt_info_it = first_node_rt_info.begin(); + auto second_node_rt_info_it = second_node_rt_info.begin(); + while (first_node_rt_info_it != first_node_rt_info.end()) { + if (first_node_rt_info_it->first != second_node_rt_info_it->first) { return false; } + ++first_node_rt_info_it; + ++second_node_rt_info_it; } return true; diff --git a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/convert_mul_or_add_finally_with_dequantization_function.cpp b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/convert_mul_or_add_finally_with_dequantization_function.cpp index 4402518bbd317d..4767cf88bed1d2 100644 --- a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/convert_mul_or_add_finally_with_dequantization_function.cpp +++ b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/convert_mul_or_add_finally_with_dequantization_function.cpp @@ -62,7 +62,9 @@ std::shared_ptr ConvertMulOrAddWithDequantizationFunction::get const auto weights = std::make_shared(element::f32, inputShape, multiplyConst); const auto bias = std::make_shared(element::f32, inputShape, 0.0); - const auto scaleShift = std::make_shared(relu, weights, bias); + std::shared_ptr scaleShift = std::make_shared(relu, weights, bias); + + scaleShift = low_precision::NetworkHelper::mark_as_dequantization_op(scaleShift); scaleShift->set_friendly_name("output"); diff --git a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/mul_add_to_scaleshift_or_power_function.cpp b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/mul_add_to_scaleshift_or_power_function.cpp index 409edefeb746f6..b3f4d84798afa7 100644 --- a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/mul_add_to_scaleshift_or_power_function.cpp +++ b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/mul_add_to_scaleshift_or_power_function.cpp @@ -60,7 +60,8 @@ namespace subgraph { std::shared_ptr lastNode; if (isDequantization) { - const auto scaleshift = std::make_shared(input, weights, biases, precisionAfterOperation); + std::shared_ptr scaleshift = std::make_shared(input, weights, biases, precisionAfterOperation); + scaleshift = low_precision::NetworkHelper::mark_as_dequantization_op(scaleshift); scaleshift->set_friendly_name("add"); lastNode = scaleshift; } else { diff --git a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/normalize_l2_function.cpp b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/normalize_l2_function.cpp index e3ff4089186601..28ef6d53e98727 100644 --- a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/normalize_l2_function.cpp +++ b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/normalize_l2_function.cpp @@ -7,6 +7,7 @@ #include #include #include "ngraph_functions/subgraph_builders.hpp" +#include "transformations/low_precision/common/dequantization_op.hpp" namespace ngraph { namespace builder { @@ -125,7 +126,7 @@ std::shared_ptr NormalizeL2Function::getReference( std::shared_ptr output = normalizeL2; if (!expectedValues.mutliplyValues.empty()) { - const std::shared_ptr multiply = std::make_shared>( + const std::shared_ptr multiply = std::make_shared>( std::vector{ element::f32, element::f32 }, std::vector{element::f32}, ngraph::op::TemporaryReplaceOutputType(output, element::f32).get(), ngraph::op::TemporaryReplaceOutputType(std::make_shared(