-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
289 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...hared_tests_instances/low_precision_transformations/move_fake_quantize_transformation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <vector> | ||
|
||
#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<ngraph::element::Type> netPrecisions = { | ||
ngraph::element::f32, | ||
// ngraph::element::f16 | ||
}; | ||
|
||
const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = { | ||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true), | ||
//LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false), | ||
}; | ||
|
||
const std::vector<LayerTestsDefinitions::MoveFakeQuantizeTransformationParam> 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<ngraph::Shape> 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<LayerTestsDefinitions::ConvolutionWIthIncorrectWeightsParam> 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 |
56 changes: 56 additions & 0 deletions
56
...plugin/shared/include/low_precision_transformations/move_fake_quantize_transformation.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <memory> | ||
|
||
#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<MoveFakeQuantizeTransformationParams>, | ||
public LayerTestsUtils::LayerTransformation { | ||
public: | ||
static std::string getTestCaseName(testing::TestParamInfo<MoveFakeQuantizeTransformationParams> obj); | ||
|
||
protected: | ||
void SetUp() override; | ||
|
||
void Run() override; | ||
}; | ||
|
||
} // namespace LayerTestsDefinitions |
79 changes: 79 additions & 0 deletions
79
...nal/plugin/shared/src/low_precision_transformations/move_fake_quantize_transformation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <memory> | ||
#include <tuple> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include <ie_core.hpp> | ||
|
||
#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<MoveFakeQuantizeTransformationParams> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters