From bdfed624b65c6622ee256202ae322ee4f7469c7b Mon Sep 17 00:00:00 2001 From: NikDemoShow Date: Wed, 4 Aug 2021 18:42:33 +0300 Subject: [PATCH] add cpu test --- ...ake_quatize.hpp => move_fake_quantize.hpp} | 2 +- .../src/low_precision.cpp | 2 + .../src/move_fake_quantize.cpp | 2 +- .../src/mkldnn_plugin/mkldnn_plugin.cpp | 4 + ...ake_quantize_for_concat_transformation.cpp | 6 +- .../move_fake_quantize_transformation.cpp | 142 ++++++++++++++++++ .../move_fake_quantize_transformation.hpp | 56 +++++++ .../move_fake_quantize_transformation.cpp | 79 ++++++++++ .../src/move_fake_quantize_function.cpp | 2 +- 9 files changed, 289 insertions(+), 6 deletions(-) rename inference-engine/src/low_precision_transformations/include/low_precision/{move_fake_quatize.hpp => move_fake_quantize.hpp} (91%) create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/move_fake_quantize_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/move_fake_quantize_transformation.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/move_fake_quantize_transformation.cpp diff --git a/inference-engine/src/low_precision_transformations/include/low_precision/move_fake_quatize.hpp b/inference-engine/src/low_precision_transformations/include/low_precision/move_fake_quantize.hpp similarity index 91% rename from inference-engine/src/low_precision_transformations/include/low_precision/move_fake_quatize.hpp rename to inference-engine/src/low_precision_transformations/include/low_precision/move_fake_quantize.hpp index 701ffaec40d505..ae9a822753a192 100644 --- a/inference-engine/src/low_precision_transformations/include/low_precision/move_fake_quatize.hpp +++ b/inference-engine/src/low_precision_transformations/include/low_precision/move_fake_quantize.hpp @@ -14,7 +14,7 @@ namespace low_precision { class LP_TRANSFORMATIONS_API MoveFakeQuantize : public LayerTransformation { public: - MoveFakeQuantize(const Params& params); + MoveFakeQuantize(const Params& params = Params()); bool transform(TransformationContext& context, ngraph::pattern::Matcher &m) override; bool isPrecisionPreserved(std::shared_ptr layer) const noexcept override; }; diff --git a/inference-engine/src/low_precision_transformations/src/low_precision.cpp b/inference-engine/src/low_precision_transformations/src/low_precision.cpp index a138b484d7f0d2..2ab11127115191 100644 --- a/inference-engine/src/low_precision_transformations/src/low_precision.cpp +++ b/inference-engine/src/low_precision_transformations/src/low_precision.cpp @@ -65,6 +65,7 @@ #include "low_precision/transpose.hpp" #include "low_precision/unsqueeze.hpp" #include "low_precision/variadic_split.hpp" +#include "low_precision/move_fake_quantize.hpp" // cleanup transformations #include "low_precision/convert.hpp" @@ -197,6 +198,7 @@ bool ngraph::pass::low_precision::LowPrecision::run_on_function(std::shared_ptr< prerequisites->add_matcher(supportedTypes); prerequisites->add_matcher(supportedTypes); prerequisites->add_matcher(); + prerequisites->add_matcher(); manager.register_pass(); diff --git a/inference-engine/src/low_precision_transformations/src/move_fake_quantize.cpp b/inference-engine/src/low_precision_transformations/src/move_fake_quantize.cpp index 553a2889cfef68..aac6fb36f2c7dc 100644 --- a/inference-engine/src/low_precision_transformations/src/move_fake_quantize.cpp +++ b/inference-engine/src/low_precision_transformations/src/move_fake_quantize.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "low_precision/move_fake_quatize.hpp" +#include "low_precision/move_fake_quantize.hpp" #include #include diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index c7907aa55692b2..0f5d525021dff7 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -324,6 +324,9 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { manager.run_passes(nGraphFunc); + //ngraph::pass: + ngraph::pass::VisualizeTree("C:/Users/ndemasho/rep/Visual/cpu.common.svg").run_on_function(nGraphFunc); + using namespace ngraph::pass::low_precision; if (useLpt) { OV_ITT_SCOPE(FIRST_INFERENCE, MKLDNNPlugin::itt::domains::MKLDNN_LT, "LowPrecisionTransformations"); @@ -367,6 +370,7 @@ static void Transformation(CNNNetwork& clonedNetwork, const Config& conf) { return MultiplyToGroupConvolutionTransformation::isDynamicOrScalar(node); }); lptManager.run_passes(nGraphFunc); + ngraph::pass::VisualizeTree("C:/Users/ndemasho/rep/Visual/cpu.commonAfter.svg").run_on_function(nGraphFunc); } ngraph::pass::Manager postLPTPassManager; diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_for_concat_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_for_concat_transformation.cpp index 5155de259624a4..d5b905e15b2a46 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_for_concat_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_for_concat_transformation.cpp @@ -43,14 +43,14 @@ namespace { class MoveFakeQuantizeActualValues { public: - ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeBefore1; //before1 + ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeBefore1; ngraph::builder::subgraph::DequantizationOperations::Convert convertBefore1; ngraph::builder::subgraph::DequantizationOperations dequantizationBefore1; - ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeBefore2; //before1 + ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeBefore2; ngraph::builder::subgraph::DequantizationOperations::Convert convertBefore2; ngraph::builder::subgraph::DequantizationOperations dequantizationBefore2; std::string operation; - ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeAfter; // after + ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeAfter; ngraph::builder::subgraph::DequantizationOperations::Convert convertAfter; ngraph::builder::subgraph::DequantizationOperations dequantizationAfter; }; diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/move_fake_quantize_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/move_fake_quantize_transformation.cpp new file mode 100644 index 00000000000000..4a9d877e6a304e --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/move_fake_quantize_transformation.cpp @@ -0,0 +1,142 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "low_precision_transformations/move_fake_quantize_transformation.hpp" +#include "low_precision_transformations/convolution_with_incorrect_weights.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector netPrecisions = { + ngraph::element::f32, + // ngraph::element::f16 +}; + +const std::vector trasformationParamValues = { + LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true), + //LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false), +}; + +const std::vector params = { + { + {}, + {}, + {}, + {}, + {}, + {}, + "relu", + { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}}, + {}, + {}, + "Concat", + "U8" + }, + /*{ + {}, + false, + { 255ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "FP32" + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + false, + { 255ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "U8" + }, + { + { 256ul, ngraph::Shape {}, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + false, + { 255ul, ngraph::Shape {}, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "U8" + }, + { + { 16ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + false, + { 16ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "FP32" + }, + { + { 16ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 25.5f }, { 0.f }, { 25.5f } }, + false, + { 255ul, ngraph::Shape { 1, 1, 1, 1 }, { -12.7f }, { 12.7f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "FP32" + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + false, + { 16ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "FP32" + }, + { + { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { -12.7f }, { 12.8f } }, + true, + { 255ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "U8" + }, + { + { 256ul, ngraph::Shape { 1 }, { 0.f }, { 255.f }, { -18.7f }, { 18.8f } }, + true, + { 255ul, ngraph::Shape { 1 }, { 0.f }, { 254.f }, { -18.7f }, { 18.7f } }, + false, + "Convolution", + "U8" + },*/ +}; + +const std::vector shapes = { + { 1, 3, 16, 16 }, + //{ 4, 3, 16, 16 } +}; + +INSTANTIATE_TEST_SUITE_P(smoke_LPT, MoveFakeQuantizeTransformation, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(shapes), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::ValuesIn(trasformationParamValues), + ::testing::ValuesIn(params)), + MoveFakeQuantizeTransformation::getTestCaseName); + +//const std::vector incorrectWeightsParams = { +// // incorrect weights +// { +// { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, +// { 255ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -127.f }, { 127.f } }, +// false +// }, +// // correct weights +// { +// { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, +// { 255ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 254.f }, { -127.f }, { 127.f } }, +// true +// } +//}; +// +//INSTANTIATE_TEST_SUITE_P(smoke_LPT, ConvolutionWIthIncorrectWeightsTransformation, +// ::testing::Combine( +// ::testing::ValuesIn(netPrecisions), +// ::testing::Values(ngraph::Shape({ 1, 3, 16, 16 })), +// ::testing::Values(CommonTestUtils::DEVICE_CPU), +// ::testing::ValuesIn(trasformationParamValues), +// ::testing::ValuesIn(incorrectWeightsParams)), +// ConvolutionWIthIncorrectWeightsTransformation::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/move_fake_quantize_transformation.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/move_fake_quantize_transformation.hpp new file mode 100644 index 00000000000000..7d193a71798d4d --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/move_fake_quantize_transformation.hpp @@ -0,0 +1,56 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp" +#include "lpt_ngraph_functions/common/fake_quantize_on_data.hpp" +#include "lpt_ngraph_functions/common/fake_quantize_on_weights.hpp" + +#include "low_precision/move_fake_quantize.hpp" + +#include "lpt_ngraph_functions/move_fake_quantize_function.hpp" + +namespace LayerTestsDefinitions { + + class MoveFakeQuantizeTransformationParam { + public: + ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeBefore1; + ngraph::builder::subgraph::DequantizationOperations::Convert convertBefore1; + ngraph::builder::subgraph::DequantizationOperations dequantizationBefore1; + ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeBefore2; + ngraph::builder::subgraph::DequantizationOperations::Convert convertBefore2; + ngraph::builder::subgraph::DequantizationOperations dequantizationBefore2; + std::string operation; + ngraph::builder::subgraph::FakeQuantizeOnDataWithConstant fakeQuantizeAfter; + ngraph::builder::subgraph::DequantizationOperations::Convert convertAfter; + ngraph::builder::subgraph::DequantizationOperations dequantizationAfter; + std::string layerName; + std::string expectedKernelType; + }; + +typedef std::tuple < + ngraph::element::Type, + ngraph::Shape, + std::string, + ngraph::pass::low_precision::LayerTransformation::Params, + MoveFakeQuantizeTransformationParam +> MoveFakeQuantizeTransformationParams; + +class MoveFakeQuantizeTransformation : + public testing::WithParamInterface, + public LayerTestsUtils::LayerTransformation { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + +protected: + void SetUp() override; + + void Run() override; +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/move_fake_quantize_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/move_fake_quantize_transformation.cpp new file mode 100644 index 00000000000000..266163b60247fa --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/move_fake_quantize_transformation.cpp @@ -0,0 +1,79 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "low_precision_transformations/move_fake_quantize_transformation.hpp" + +#include +#include +#include +#include + +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "functional_test_utils/blob_utils.hpp" +#include "ngraph_functions/pass/convert_prc.hpp" +#include "lpt_ngraph_functions/move_fake_quantize_function.hpp" + +namespace LayerTestsDefinitions { + +std::string MoveFakeQuantizeTransformation::getTestCaseName(testing::TestParamInfo obj) { + ngraph::element::Type netPrecision; + ngraph::PartialShape inputShape; + std::string targetDevice; + ngraph::pass::low_precision::LayerTransformation::Params params; + MoveFakeQuantizeTransformationParam param; + std::tie(netPrecision, inputShape, targetDevice, params, param) = obj.param; + + std::ostringstream result; + result << getTestCaseNameByParams(netPrecision, inputShape, targetDevice, params); + return result.str(); +} + +void MoveFakeQuantizeTransformation::SetUp() { + threshold = 0.1f; + + ngraph::element::Type netPrecision; + ngraph::PartialShape inputShape; + ngraph::pass::low_precision::LayerTransformation::Params params; + MoveFakeQuantizeTransformationParam param; + std::tie(netPrecision, inputShape, targetDevice, params, param) = this->GetParam(); + + function = ngraph::builder::subgraph::MoveFakeQuantize::get( + netPrecision, + inputShape, + param.fakeQuantizeBefore1, + param.convertBefore1, + param.dequantizationBefore1, + param.fakeQuantizeBefore2, + param.convertBefore2, + param.dequantizationBefore2, + param.operation, + param.fakeQuantizeAfter, + param.convertAfter, + param.dequantizationAfter, + {}, + {}, + {}); +} + +void MoveFakeQuantizeTransformation::Run() { + LayerTestsCommon::Run(); + + const auto params = std::get<4>(GetParam()); + const auto actualPrecision = getRuntimePrecisionByType(params.layerName); + auto expectedPrecision = params.expectedKernelType; + if (expectedPrecision == "FP32" && std::get<0>(GetParam()) == ngraph::element::f16) { + expectedPrecision = "FP16"; + } + EXPECT_EQ(actualPrecision, expectedPrecision); +} + +TEST_P(MoveFakeQuantizeTransformation, CompareWithRefImpl) { + Run(); +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp index c5b9d92610aa4b..aaa1170b1433ed 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp @@ -48,7 +48,7 @@ namespace ngraph { if (operation == "relu") { auto relu1 = std::make_shared(input1->output(0)); auto relu2 = std::make_shared(input2->output(0)); - parent1 = makeFakeQuantizeTypeRelaxed(relu1, inputPrecision, fqOnData1); + parent1 = makeFakeQuantizeTypeRelaxed(relu1, inputPrecision, fqOnData1);// ???????? ?? MoveFakeQuantize parent2 = makeFakeQuantizeTypeRelaxed(relu2, inputPrecision, fqOnData2); } else {