[LPT] Remove legacy usage from LPT tests (#8985)

* delete convert_mul_or_add_finally_with_dequantization_function & mul_add_to_scaleshift_or_power_function.cpp

* delte reshape_fully_connected

* delete legacy layer_transformation.cpp & fix CMakeLists

* move createParams()
This commit is contained in:
Nikita Demashov 2021-12-07 23:22:58 +03:00 committed by GitHub
parent b6a5532c27
commit 524491c170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 4 additions and 524 deletions

View File

@ -91,7 +91,6 @@ ie_faster_build(${TARGET_NAME}
file(GLOB_RECURSE legacy_tests
"${CMAKE_CURRENT_SOURCE_DIR}/transformations/*.cpp" # CVS-55385
"${CMAKE_CURRENT_SOURCE_DIR}/lp_transformations/*.cpp" # CVS-55376
"${CMAKE_CURRENT_SOURCE_DIR}/ngraph_reader/*.cpp" # CVS-55365
"${CMAKE_CURRENT_SOURCE_DIR}/cnn_network/cnn_ngraph_impl_tests.cpp" # CVS-55375
)

View File

@ -1,109 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <string>
#include <sstream>
#include <memory>
#include <gtest/gtest.h>
#include <transformations/utils/utils.hpp>
#include <transformations/init_node_info.hpp>
#include <legacy/transformations/convert_opset1_to_legacy/reshape_fully_connected.hpp>
#include <ngraph/pass/constant_folding.hpp>
#include "layer_transformation.hpp"
#include "common_test_utils/ngraph_test_utils.hpp"
#include "lpt_ngraph_functions/reshape_fully_connected_function.hpp"
using namespace testing;
using namespace ngraph::pass;
namespace {
class ReshapeFullyConnectedTransformationTestValues {
public:
ngraph::Shape inputShape;
ngraph::element::Type inputPrecision1;
ngraph::element::Type inputPrecision2;
ngraph::element::Type inputPrecision3;
ngraph::Shape outputShape;
ngraph::element::Type outputPrecision;
};
class ReshapeFullyConnectedTransformation :
public LayerTransformation,
public testing::WithParamInterface<ReshapeFullyConnectedTransformationTestValues> {
public:
void SetUp() override {
using namespace ngraph::builder::subgraph;
const ReshapeFullyConnectedTransformationTestValues testValues = GetParam();
actualFunction = ReshapeFullyConnectedFunction::getOriginal(
testValues.inputShape,
testValues.inputPrecision1,
testValues.inputPrecision2,
testValues.inputPrecision3,
testValues.outputShape,
testValues.outputPrecision);
ngraph::pass::Manager manager;
manager.register_pass<ngraph::pass::ReshapeFullyConnected>();
manager.register_pass<ngraph::pass::ConstantFolding>();
manager.run_passes(actualFunction);
referenceFunction = ReshapeFullyConnectedFunction::getReference(
testValues.inputShape,
testValues.inputPrecision1,
testValues.inputPrecision2,
testValues.inputPrecision3,
testValues.outputShape,
testValues.outputPrecision);
}
static std::string getTestCaseName(testing::TestParamInfo<ReshapeFullyConnectedTransformationTestValues> obj) {
const ReshapeFullyConnectedTransformationTestValues testValues = obj.param;
std::ostringstream result;
result <<
testValues.inputShape << "_" <<
testValues.inputPrecision1 << "_" <<
testValues.inputPrecision2 << "_" <<
testValues.outputShape << "_" <<
testValues.outputPrecision;
return result.str();
}
};
TEST_P(ReshapeFullyConnectedTransformation, CompareFunctions) {
actualFunction->validate_nodes_and_infer_types();
auto res = compare_functions(referenceFunction, actualFunction, true, true, true);
ASSERT_TRUE(res.first) << res.second;
ASSERT_TRUE(LayerTransformation::allNamesAreUnique(actualFunction)) << "Not all names are unique";
}
std::vector<ReshapeFullyConnectedTransformationTestValues> testValues = {
{
{ 1, 1, 2048 },
ngraph::element::u8,
ngraph::element::i8,
ngraph::element::f32,
{ 1, 1000 },
ngraph::element::f32
},
{
{ 1, 1, 2048 },
ngraph::element::f32,
ngraph::element::f32,
ngraph::element::f32,
{ 1, 1000 },
ngraph::element::f32
}
};
INSTANTIATE_TEST_SUITE_P(
smoke_LPT,
ReshapeFullyConnectedTransformation,
::testing::ValuesIn(testValues),
ReshapeFullyConnectedTransformation::getTestCaseName);
} // namespace

View File

@ -21,11 +21,6 @@ addIeTargetTest(
GPU
)
# CVS-55376
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instances/low_precision_transformations/layer_transformation.cpp"
PROPERTIES INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:inference_engine_legacy,INTERFACE_INCLUDE_DIRECTORIES>)
# try to find VA libraries
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)

View File

@ -1,59 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp"
#include <memory>
#include <tuple>
#include <vector>
#include <string>
#include <ie_core.hpp>
#include <transformations/common_optimizations/common_optimizations.hpp>
#include <legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp>
#include <legacy/ngraph_ops/fully_connected.hpp>
#include <legacy/net_pass.h>
#include <transformations/opset_conversions/convert_opset2_to_opset1.hpp>
#include <transformations/opset_conversions/convert_opset3_to_opset2.hpp>
#include <transformations/init_node_info.hpp>
#include <ngraph/opsets/opset1.hpp>
#include <ngraph/opsets/opset2.hpp>
#include <ngraph/opsets/opset3.hpp>
#include <ngraph/opsets/opset4.hpp>
#include <ngraph/op/gelu.hpp>
#include <ngraph/pass/manager.hpp>
#include "ngraph_functions/pass/convert_prc.hpp"
#include "common_test_utils/common_utils.hpp"
#include <legacy/ie_util_internal.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 "shared_test_classes/base/layer_test_utils.hpp"
#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp"
using namespace InferenceEngine::details;
#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"
namespace LayerTestsUtils {
InferenceEngine::Precision LayerTransformation::getDeviceInternalPrecision(const InferenceEngine::Precision precision) {
if (precision == InferenceEngine::Precision::FP16) {
return InferenceEngine::Precision::FP32;
}
return precision;
}
ngraph::pass::low_precision::LayerTransformation::Params LayerTransformationParamsNGraphFactory::createParams() {
return ngraph::pass::low_precision::LayerTransformation::Params();
}
} // namespace LayerTestsUtils

View File

@ -51,7 +51,6 @@ addIeTarget(
lptNgraphFunctions
sharedTestClasses
PRIVATE
inference_engine_legacy # CVS-55376
openvino::util
inference_engine_transformations
DEPENDENCIES
@ -62,11 +61,6 @@ if(ENABLE_GAPI_PREPROCESSING)
target_compile_definitions(${TARGET_NAME} PUBLIC ENABLE_GAPI_PREPROCESSING)
endif()
# CVS-55376
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/low_precision_transformations/layer_transformation.cpp"
PROPERTIES INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:inference_engine_legacy,INTERFACE_INCLUDE_DIRECTORIES>)
ie_faster_build(${TARGET_NAME}
PCH PRIVATE "src/precomp.hpp"
)

View File

@ -1,56 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp"
#include <memory>
#include <tuple>
#include <vector>
#include <string>
#include <ie_core.hpp>
#include <legacy/net_pass.h>
#include <legacy/graph_transformer.h>
#include <legacy/convert_function_to_cnn_network.hpp>
#include <transformations/common_optimizations/common_optimizations.hpp>
#include <legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp>
#include <transformations/opset_conversions/convert_opset2_to_opset1.hpp>
#include <transformations/opset_conversions/convert_opset3_to_opset2.hpp>
#include <transformations/init_node_info.hpp>
#include <ngraph/opsets/opset1.hpp>
#include <ngraph/opsets/opset2.hpp>
#include <ngraph/opsets/opset3.hpp>
#include <ngraph/opsets/opset4.hpp>
#include "legacy/ngraph_ops/fully_connected.hpp"
#include <ngraph/op/gelu.hpp>
#include <ngraph/pass/manager.hpp>
#include "ngraph_functions/pass/convert_prc.hpp"
#include "common_test_utils/common_utils.hpp"
#include <legacy/ie_util_internal.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 "shared_test_classes/base/layer_test_utils.hpp"
#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp"
#include <low_precision/convolution.hpp>
namespace LayerTestsUtils {
InferenceEngine::Precision LayerTransformation::getDeviceInternalPrecision(const InferenceEngine::Precision precision) {
if (precision == InferenceEngine::Precision::FP16) {
return InferenceEngine::Precision::FP32;
}
return precision;
}
ngraph::pass::low_precision::LayerTransformation::Params LayerTransformationParamsNGraphFactory::createParams() {
return ngraph::pass::low_precision::LayerTransformation::Params();
}
} // namespace LayerTestsUtils

View File

@ -43,8 +43,6 @@ protected:
static std::string toString(const ngraph::pass::low_precision::LayerTransformation::Params& params);
static InferenceEngine::Precision getDeviceInternalPrecision(const InferenceEngine::Precision precision);
static std::string getTestCaseNameByParams(
const InferenceEngine::Precision precision,
const InferenceEngine::SizeVector& inputShapes,

View File

@ -29,6 +29,10 @@ ngraph::pass::low_precision::LayerTransformation::Params LayerTransformationPara
return ngraph::pass::low_precision::LayerTransformation::Params();
}
ngraph::pass::low_precision::LayerTransformation::Params LayerTransformationParamsNGraphFactory::createParams() {
return ngraph::pass::low_precision::LayerTransformation::Params();
}
LayerTransformation::LayerTransformation() {
threshold = 0.05;
auto& configuration = GetConfiguration();

View File

@ -1,31 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <sstream>
#include <vector>
#include <ngraph/ngraph.hpp>
#include "lpt_ngraph_functions/common/fake_quantize_on_data.hpp"
#include "lpt_ngraph_functions/common/dequantization_operations.hpp"
namespace ngraph {
namespace builder {
namespace subgraph {
class ConvertMulOrAddWithDequantizationFunction {
public:
static std::shared_ptr<ngraph::Function> getOriginal(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision,
const std::vector<float>& multiplyConst);
static std::shared_ptr<ngraph::Function> getReference(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision,
const std::vector<float>& multiplyConst);
};
} // namespace subgraph
} // namespace builder
} // namespace ngraph

View File

@ -1,37 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <sstream>
#include <vector>
#include <ngraph/ngraph.hpp>
#include "lpt_ngraph_functions/common/fake_quantize_on_data.hpp"
#include "lpt_ngraph_functions/common/dequantization_operations.hpp"
namespace ngraph {
namespace builder {
namespace subgraph {
class ReshapeFullyConnectedFunction {
public:
static std::shared_ptr<ngraph::Function> getOriginal(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision1,
const ngraph::element::Type inputPrecision2,
const ngraph::element::Type inputPrecision3,
const ngraph::Shape& outputShape,
const ngraph::element::Type outputPrecision);
static std::shared_ptr<ngraph::Function> getReference(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision1,
const ngraph::element::Type inputPrecision2,
const ngraph::element::Type inputPrecision3,
const ngraph::Shape& outputShape,
const ngraph::element::Type outputPrecision);
};
} // namespace subgraph
} // namespace builder
} // namespace ngraph

View File

@ -1,74 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "lpt_ngraph_functions/convert_mul_or_add_finally_with_dequantization_function.hpp"
#include <memory>
#include <vector>
#include <ngraph/ngraph.hpp>
#include <ngraph/opsets/opset1.hpp>
#include "ngraph_functions/subgraph_builders.hpp"
#include "lpt_ngraph_functions/common/builders.hpp"
#include "low_precision/network_helper.hpp"
#include <legacy/ngraph_ops/scaleshift.hpp>
namespace ngraph {
namespace builder {
namespace subgraph {
using namespace ngraph::pass;
std::shared_ptr<ngraph::Function> ConvertMulOrAddWithDequantizationFunction::getOriginal(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision,
const std::vector<float>& multiplyConst) {
const auto input = std::make_shared<ngraph::opset1::Parameter>(inputPrecision, inputShape);
const auto reluOriginal = ngraph::opset1::Relu(
ngraph::op::TemporaryReplaceOutputType(input, element::f32).get());
std::shared_ptr<ngraph::opset1::Relu> relu = std::make_shared<ngraph::op::TypeRelaxed<ngraph::opset1::Relu>>(
reluOriginal,
std::vector<element::Type>{ element::f32, element::f32 },
std::vector<element::Type>{});
const auto multiply = std::make_shared<opset1::Multiply>(
relu,
std::make_shared<opset1::Constant>(element::f32, inputShape, multiplyConst));
multiply->set_friendly_name("output");
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(multiply) };
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input },
"ConvertMulOrAddTransformationWithDequantization");
}
std::shared_ptr<ngraph::Function> ConvertMulOrAddWithDequantizationFunction::getReference(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision,
const std::vector<float>& multiplyConst) {
const auto input = std::make_shared<ngraph::opset1::Parameter>(inputPrecision, inputShape);
const auto reluOriginal = ngraph::opset1::Relu(
ngraph::op::TemporaryReplaceOutputType(input, element::f32).get());
std::shared_ptr<ngraph::opset1::Relu> relu = std::make_shared<ngraph::op::TypeRelaxed<ngraph::opset1::Relu>>(
reluOriginal,
std::vector<element::Type>{ element::f32, element::f32 },
std::vector<element::Type>{});
const auto weights = std::make_shared<opset1::Constant>(element::f32, inputShape, multiplyConst);
const auto bias = std::make_shared<opset1::Constant>(element::f32, inputShape, 0.0);
std::shared_ptr<Node> scaleShift = std::make_shared<ngraph::op::ScaleShiftIE>(relu, weights, bias);
scaleShift->set_friendly_name("output");
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(scaleShift) };
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "ConvertMulOrAddTransformationWithDequantization");
}
} // namespace subgraph
} // namespace builder
} // namespace ngraph

View File

@ -1,75 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "lpt_ngraph_functions/mul_add_to_scaleshift_or_power_function.hpp"
#include <ngraph/opsets/opset1.hpp>
#include "ngraph_ops/type_relaxed.hpp"
#include "low_precision/network_helper.hpp"
#include <legacy/ngraph_ops/power.hpp>
#include <legacy/ngraph_ops/scaleshift.hpp>
#include "lpt_ngraph_functions/common/builders.hpp"
#include "lpt_ngraph_functions/common/dequantization_operations.hpp"
namespace ngraph {
namespace builder {
namespace subgraph {
using namespace ngraph::pass;
std::shared_ptr<ngraph::Function> MulAddToScaleshiftOrPowerFunction::getOriginal(
const ngraph::element::Type precision,
const ngraph::Shape& inputShape,
bool isDequantization,
const ngraph::builder::subgraph::DequantizationOperations::Multiply& mulValues,
const ngraph::builder::subgraph::Add& addValues) {
const auto input = std::make_shared<ngraph::op::v0::Parameter>(precision, inputShape);
const auto mulConst = ngraph::op::Constant::create(ngraph::element::f32, mulValues.constantShape, mulValues.values);
const auto mul = std::make_shared<ngraph::op::TypeRelaxed<opset1::Multiply>>(
std::vector<element::Type>{element::f32, element::f32}, std::vector<element::Type>{ element::f32 },
ngraph::op::TemporaryReplaceOutputType(input, element::f32).get(),
ngraph::op::TemporaryReplaceOutputType(mulConst, element::f32).get());
const auto addConst = ngraph::op::Constant::create(ngraph::element::f32, addValues.constantShape, addValues.values);
const auto add = std::make_shared<opset1::Add>(mul, addConst);
add->set_friendly_name("add");
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(add) };
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "MulAddToScaleshiftOrPowerFunction");
}
std::shared_ptr<ngraph::Function> MulAddToScaleshiftOrPowerFunction::getReference(
const ngraph::element::Type precision,
const ngraph::Shape& inputShape,
bool isDequantization,
const ngraph::builder::subgraph::DequantizationOperations::Multiply& weightsValues,
const ngraph::builder::subgraph::Add& biasesValues,
const ngraph::element::Type precisionAfterOperation) {
const auto input = std::make_shared<ngraph::op::v0::Parameter>(precision, inputShape);
ngraph::Shape constShape = { 1, inputShape[1], 1, 1 };
const auto weights = ngraph::op::Constant::create(ngraph::element::f32, constShape, weightsValues.values);
const auto biases = ngraph::op::Constant::create(ngraph::element::f32, constShape, biasesValues.values);
std::shared_ptr<ngraph::Node> lastNode;
if (isDequantization) {
std::shared_ptr<Node> scaleshift = std::make_shared<ngraph::op::ScaleShiftIE>(input, weights, biases, precisionAfterOperation);
scaleshift->set_friendly_name("add");
lastNode = scaleshift;
} else {
float scale = weightsValues.values[0];
float shift = biasesValues.values[0];
const auto power = std::make_shared<ngraph::op::PowerIE>(input, 1.f, scale, shift, precisionAfterOperation);
power->set_friendly_name("add");
lastNode = power;
}
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(lastNode) };
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "MulAddToScaleshiftOrPowerFunction");
}
} // namespace subgraph
} // namespace builder
} // namespace ngraph

View File

@ -1,69 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "lpt_ngraph_functions/reshape_fully_connected_function.hpp"
#include <memory>
#include <vector>
#include <ngraph/ngraph.hpp>
#include <ngraph/opsets/opset1.hpp>
#include <legacy/ngraph_ops/fully_connected.hpp>
#include "ngraph_functions/subgraph_builders.hpp"
#include "lpt_ngraph_functions/common/builders.hpp"
#include "low_precision/network_helper.hpp"
namespace ngraph {
namespace builder {
namespace subgraph {
using namespace ngraph::pass;
std::shared_ptr<ngraph::Function> ReshapeFullyConnectedFunction::getOriginal(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision1,
const ngraph::element::Type inputPrecision2,
const ngraph::element::Type inputPrecision3,
const ngraph::Shape& outputShape,
const ngraph::element::Type outputPrecision) {
const auto input = std::make_shared<ngraph::opset1::Parameter>(inputPrecision1, inputShape);
const auto weightsShape = Shape{ outputShape[1], inputShape[1] };
const auto weights = std::make_shared<opset1::Constant>(inputPrecision2, weightsShape, std::vector<float>(shape_size(weightsShape), 1.f));
const auto bias = std::make_shared<opset1::Constant>(inputPrecision3, Shape{ inputShape[1] }, 0.f);
const std::shared_ptr<op::FullyConnected> fullyConnected = std::make_shared<op::FullyConnected>(input, weights, bias, outputShape, outputPrecision);
fullyConnected->set_friendly_name("fullyConnected");
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(fullyConnected) };
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "ReshapeFullyConnectedFunction");
}
std::shared_ptr<ngraph::Function> ReshapeFullyConnectedFunction::getReference(
const ngraph::Shape& inputShape,
const ngraph::element::Type inputPrecision1,
const ngraph::element::Type inputPrecision2,
const ngraph::element::Type inputPrecision3,
const ngraph::Shape& outputShape,
const ngraph::element::Type outputPrecision) {
const auto input = std::make_shared<ngraph::opset1::Parameter>(inputPrecision1, inputShape);
std::vector<int64_t> reshapeShape{ -1, static_cast<int64_t>(inputShape.back()) };
auto reshape = std::make_shared<opset1::Reshape>(input, opset1::Constant::create(element::i64, Shape{ 2 }, reshapeShape), true);
const auto weightsShape = Shape{ outputShape[1], inputShape[1] };
const auto weights = std::make_shared<opset1::Constant>(inputPrecision2, weightsShape, std::vector<float>(shape_size(weightsShape), 1.f));
const auto bias = std::make_shared<opset1::Constant>(inputPrecision3, Shape{ inputShape[1] }, 0.f);
const std::shared_ptr<op::FullyConnected> fullyConnected = std::make_shared<op::FullyConnected>(reshape, weights, bias, outputShape, outputPrecision);
fullyConnected->set_friendly_name("fullyConnected");
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(fullyConnected) };
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "ReshapeFullyConnectedFunction");
}
} // namespace subgraph
} // namespace builder
} // namespace ngraph