diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index 4d565ca0c2d975..3c91f18dc3bd7f 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -470,7 +470,6 @@ void GNAPlugin::UpdateInputScaleFromNetwork(InferenceEngine::CNNNetwork & networ auto data = input.second->getInputData(); for (auto && nextToInputLayer : getInputTo(data)) { if (!LayerInfo(nextToInputLayer.second).isFakeQuantize()) { - inputIdx++; continue; } // replacing scale factor from this fq layer @@ -493,6 +492,9 @@ void GNAPlugin::UpdateInputScaleFromNetwork(InferenceEngine::CNNNetwork & networ scaleInput = (fqLayer.getLevels() - 1) / (2 * maxAbsVal); } + IE_ASSERT(config.inputScaleFactors.size() > inputIdx); + IE_ASSERT(inputsDesc->inputScaleFactors.size() > inputIdx); + if (!config.inputScaleFactors.empty()) { gnalog() << "Scale factor calculated during model quantization (" << scaleInput << ") will be used instead of user input (" << inputsDesc->inputScaleFactors[inputIdx] << ").\n"; @@ -505,9 +507,9 @@ void GNAPlugin::UpdateInputScaleFromNetwork(InferenceEngine::CNNNetwork & networ config.inputScaleFactors[inputIdx] = scaleInput; inputsDesc->inputScaleFactors[inputIdx] = scaleInput; - - inputIdx++; } + + inputIdx++; } } diff --git a/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp b/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp index 8ab4af9f1083f9..f4e5fc7a9316d9 100644 --- a/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp +++ b/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp @@ -2177,7 +2177,7 @@ void MoveFakeQuantizeLayerIntoQuantParamsPass :: run() { } if (isFQFuseAllowed) { - getInputTo(prevData).clear(); + getInputTo(prevData).erase(l->name); } // Connect all next layers after FQ to the layer that is before FQ diff --git a/inference-engine/tests/functional/plugin/gna/pass_tests/fq_fusion_with_sigmoid.cpp b/inference-engine/tests/functional/plugin/gna/pass_tests/fq_fusion_with_sigmoid.cpp new file mode 100644 index 00000000000000..ec3b500b60858e --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/pass_tests/fq_fusion_with_sigmoid.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "ngraph_functions/builders.hpp" +#include "common_test_utils/test_constants.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" + +namespace LayerTestsDefinitions { + +typedef std::tuple< + std::string, // Target device name + InferenceEngine::Precision, // Network precision + size_t, // level + std::pair, // min, max + size_t, // Input size + std::map // Configuration +> fqFusionWithSigmoidParams; + +class FqFusionWithSigmoidTest : public LayerTestsUtils::LayerTestsCommon, + public testing::WithParamInterface { +protected: + void SetUp() override { + InferenceEngine::Precision netPrecision; + std::map config; + size_t levelFq; + std::pair minMaxFq; + size_t inputSize; + std::tie(targetDevice, netPrecision, levelFq, minMaxFq, inputSize, config) = this->GetParam(); + configuration.insert(config.begin(), config.end()); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + + auto input = ngraph::builder::makeParams(ngPrc, {{1, inputSize}}); + auto constant = ngraph::builder::makeConstant(ngPrc, {1, inputSize}, std::vector{1}); + auto mul1 = ngraph::builder::makeEltwise(input[0], constant, ngraph::helpers::EltwiseTypes::ADD); + auto sigmoid1 = std::make_shared(mul1); + auto mul2 = ngraph::builder::makeEltwise(input[0], sigmoid1, ngraph::helpers::EltwiseTypes::MULTIPLY); + auto fake3 = ngraph::builder::makeFakeQuantize(sigmoid1, ngPrc, levelFq, + { 1 }, { minMaxFq.first }, { minMaxFq.second }, { minMaxFq.first }, { minMaxFq.second }); + auto mul3 = ngraph::builder::makeEltwise(mul2, fake3, ngraph::helpers::EltwiseTypes::ADD); + auto result = std::make_shared(mul3); + function = std::make_shared(ngraph::ResultVector{result}, input, "fq_fusion_with_sigmoid"); + } +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj) { + std::string targetDevice; + InferenceEngine::Precision netPrecision; + size_t levelFq; + std::pair minMaxFq; + size_t inputSize; + std::map config; + std::tie(targetDevice, netPrecision, levelFq, minMaxFq, inputSize, config) = obj.param; + std::ostringstream result; + result << "netPrecision=" << netPrecision.name() << "_"; + result << "IS=" << inputSize << "_"; + result << "targetDevice=" << targetDevice << "_"; + result << "levelFq=" << levelFq << "_"; + result << "(minFq,maxFq)=" << std::to_string(minMaxFq.first) << "_" << std::to_string(minMaxFq.first) << "_"; + result << "inputSize=" << std::to_string(inputSize); + return result.str(); + } +}; // class FqFusionWithSigmoidTest + +TEST_P(FqFusionWithSigmoidTest, CompareWithRefs) { + Run(); +}; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +std::vector levelFq = { + 65535 +}; + +std::vector> minMaxFq = { + {-1, 1}, + {-5, 5} +}; + +std::vector input = { + 64, +}; + +std::map additional_config = { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_fq_fusion_with_sigmoid, FqFusionWithSigmoidTest, + ::testing::Combine( + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(levelFq), + ::testing::ValuesIn(minMaxFq), + ::testing::ValuesIn(input), + ::testing::Values(additional_config)), + FqFusionWithSigmoidTest::getTestCaseName); + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multiple_input_fq.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multiple_input_fq.cpp new file mode 100644 index 00000000000000..b6b2e5dab43782 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multiple_input_fq.cpp @@ -0,0 +1,26 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "common_test_utils/test_constants.hpp" + +namespace SubgraphTestsDefinitions { +namespace { +std::vector input = { + 64, +}; + +std::map additional_config = { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, +}; +} // namespace + +INSTANTIATE_TEST_SUITE_P(smoke_multiple_input, MultipleInputTest, + ::testing::Combine( + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(input), + ::testing::Values(additional_config)), + MultipleInputTest::getTestCaseName); +} // namespace SubgraphTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/multiple_input_fq.hpp b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/multiple_input_fq.hpp new file mode 100644 index 00000000000000..da53cc54050b68 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/multiple_input_fq.hpp @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef MULTIPLE_INPUT_HPP +#define MULTIPLE_INPUT_HPP + +#include "shared_test_classes/subgraph/multiple_input_fq.hpp" + +namespace SubgraphTestsDefinitions { + +TEST_P(MultipleInputTest, CompareWithRefs) { + Run(); +}; + +} // namespace SubgraphTestsDefinitions + +#endif // MULTIPLE_INPUT_HPP diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiple_input_fq.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiple_input_fq.hpp new file mode 100644 index 00000000000000..3cd546edca47f5 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multiple_input_fq.hpp @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef SUBGRAPH_MULTIPLE_INPUT_HPP +#define SUBGRAPH_MULTIPLE_INPUT_HPP + +#include "common_test_utils/test_common.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include + +namespace SubgraphTestsDefinitions { +typedef std::tuple< + std::string, // Target device name + InferenceEngine::Precision, // Network precision + size_t, // Input size + std::map // Configuration +> multipleInputParams; + +class MultipleInputTest : public LayerTestsUtils::LayerTestsCommon, + public testing::WithParamInterface { +protected: + void SetUp() override; +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); +}; +} // namespace SubgraphTestsDefinitions + +#endif // SUBGRAPH_MULTIPLE_INPUT_HPP diff --git a/inference-engine/tests/functional/shared_test_classes/src/subgraph/multiple_input_fq.cpp b/inference-engine/tests/functional/shared_test_classes/src/subgraph/multiple_input_fq.cpp new file mode 100644 index 00000000000000..f2ac77989bf407 --- /dev/null +++ b/inference-engine/tests/functional/shared_test_classes/src/subgraph/multiple_input_fq.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ngraph_functions/builders.hpp" +#include "shared_test_classes/subgraph/multiple_input_fq.hpp" + +namespace SubgraphTestsDefinitions { + +std::string MultipleInputTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::string targetDevice; + InferenceEngine::Precision netPrecision; + size_t inputSize; + std::map config; + std::tie(targetDevice, netPrecision, inputSize, config) = obj.param; + std::ostringstream result; + result << "netPrecision=" << netPrecision.name() << "_"; + result << "IS=" << inputSize << "_"; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void MultipleInputTest::SetUp() { + InferenceEngine::Precision netPrecision; + std::map config; + size_t inputSize; + std::tie(targetDevice, netPrecision, inputSize, config) = this->GetParam(); + configuration.insert(config.begin(), config.end()); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto input = ngraph::builder::makeParams(ngPrc, {{1, inputSize}, {1, inputSize}, {1, inputSize}}); + auto fake1 = ngraph::builder::makeFakeQuantize(input[0], ngPrc, 255, { 1 }, { -0.5 }, { 0.5 }, { -0.5 }, { 0.5 }); + auto mul1 = ngraph::builder::makeEltwise(input[0], fake1, ngraph::helpers::EltwiseTypes::ADD); + auto fake2 = ngraph::builder::makeFakeQuantize(input[1], ngPrc, 255, { 1 }, { -0.5 }, { 0.5 }, { -0.5 }, { 0.5 }); + auto mul2 = ngraph::builder::makeEltwise(input[1], fake2, ngraph::helpers::EltwiseTypes::ADD); + auto mul3 = ngraph::builder::makeEltwise(mul1, mul2, ngraph::helpers::EltwiseTypes::ADD); + auto fake3 = ngraph::builder::makeFakeQuantize(input[2], ngPrc, 255, { 1 }, { -0.5 }, { 0.5 }, { -0.5 }, { 0.5 }); + auto mul4 = ngraph::builder::makeEltwise(fake3, mul3, ngraph::helpers::EltwiseTypes::ADD); + auto result = std::make_shared(mul4); + function = std::make_shared(ngraph::ResultVector{result}, input, "multiple_input"); +} + +} // namespace SubgraphTestsDefinitions +