Skip to content

Commit

Permalink
comments: fixes & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eshoguli committed Sep 12, 2023
1 parent 1c3f10e commit 5b83a63
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 83 deletions.
10 changes: 4 additions & 6 deletions src/common/low_precision_transformations/src/batch_to_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

#include <memory>
#include <ngraph/ngraph.hpp>
#include <ngraph/opsets/opset1.hpp>
#include <ngraph/opsets/opset2.hpp>

#include <openvino/op/batch_to_space.hpp>
#include <ngraph/pattern/op/wrap_type.hpp>

#include "low_precision/network_helper.hpp"
Expand All @@ -20,7 +18,7 @@ namespace low_precision {

BatchToSpaceTransformation::BatchToSpaceTransformation(const Params& params) : LayerTransformation(params) {
MATCHER_SCOPE(BatchToSpaceTransformation);
auto matcher = pattern::wrap_type<opset2::BatchToSpace>();
auto matcher = pattern::wrap_type<ov::op::v1::BatchToSpace>();

ngraph::graph_rewrite_callback callback = [this](pattern::Matcher& m) {
auto op = m.get_match_root();
Expand Down Expand Up @@ -52,8 +50,8 @@ bool BatchToSpaceTransformation::transform(TransformationContext& context, ngrap
return false;
}

const std::shared_ptr<Node> pooling = NetworkHelper::separateInStandaloneBranch(m.get_match_root(), defaultPrecisions);
moveDequantizationAfter(context, pooling, NetworkHelper::getDequantization(pooling, defaultPrecisions), false);
const std::shared_ptr<Node> op = NetworkHelper::separateInStandaloneBranch(m.get_match_root(), defaultPrecisions);
moveDequantizationAfter(context, op, NetworkHelper::getDequantization(op, defaultPrecisions), false);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ bool ngraph::pass::low_precision::MarkupPrecisions::isSupported(const std::share
static std::unordered_set<std::string> supportedOps = {
{ name<opset1::Add>() },
{ name<opset1::AvgPool>() },
{ name<opset2::BatchToSpace>() },
{ name<opset1::Clamp>() },
{ name<opset1::Concat>() },
// ?
Expand Down Expand Up @@ -220,6 +221,7 @@ bool ngraph::pass::low_precision::MarkupPrecisions::isSupported(const std::share
{ name<opset1::Relu>() },
// TODO: there are conditions
{ name<opset1::Reshape>() },
{ name<opset2::SpaceToBatch>() },
{ name<opset1::Squeeze>() },
{ name<opset1::ShuffleChannels>() },
{ name<opset1::Split>() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include <memory>
#include <ngraph/ngraph.hpp>
#include <ngraph/opsets/opset1.hpp>
#include <ngraph/opsets/opset2.hpp>
#include <openvino/op/space_to_batch.hpp>

#include <ngraph/pattern/op/wrap_type.hpp>

Expand All @@ -20,7 +19,7 @@ namespace low_precision {

SpaceToBatchTransformation::SpaceToBatchTransformation(const Params& params) : LayerTransformation(params) {
MATCHER_SCOPE(SpaceToBatchTransformation);
auto matcher = pattern::wrap_type<opset2::SpaceToBatch>();
auto matcher = pattern::wrap_type<ov::op::v1::SpaceToBatch>();

ngraph::graph_rewrite_callback callback = [this](pattern::Matcher& m) {
auto op = m.get_match_root();
Expand Down Expand Up @@ -52,8 +51,8 @@ bool SpaceToBatchTransformation::transform(TransformationContext& context, ngrap
return false;
}

const std::shared_ptr<Node> pooling = NetworkHelper::separateInStandaloneBranch(m.get_match_root(), defaultPrecisions);
moveDequantizationAfter(context, pooling, NetworkHelper::getDequantization(pooling, defaultPrecisions), false);
const std::shared_ptr<Node> op = NetworkHelper::separateInStandaloneBranch(m.get_match_root(), defaultPrecisions);
moveDequantizationAfter(context, op, NetworkHelper::getDequantization(op, defaultPrecisions), false);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ class BatchToSpaceTransformation : public LayerTransformation,
TEST_P(BatchToSpaceTransformation, CompareFunctions) {
actualFunction->validate_nodes_and_infer_types();

const auto testValues = std::get<1>(GetParam());
const auto output_precision = LayerTransformation::get_output_precision<ngraph::opset2::BatchToSpace>(actualFunction);
ASSERT_EQ(testValues.expected.preicsionAfterOperation, output_precision);

auto res = compare_functions(actualFunction, referenceFunction, true, false, false);
ASSERT_TRUE(res.first) << res.second;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,6 @@ class LayerTransformation : public ov::test::TestsCommon {
return true;
}

template <class Operation>
static ov::element::Type get_output_precision(const std::shared_ptr<ov::Model>& model) {
auto result = ov::element::undefined;
for (const auto& op : model->get_ops()) {
if (ov::is_type<Operation>(op)) {
if (result != ov::element::undefined) {
THROW_IE_LPT_EXCEPTION(*op) << "not one operation";
}
if (op->get_output_size() != 1) {
THROW_IE_LPT_EXCEPTION(*op) << "not expected outputs count";
}
result = op->get_output_element_type(0);
}
}

if (result == ov::element::undefined) {
THROW_IE_LPT_EXCEPTION_BASE << "operation was not found";
}

return result;
}

protected:
std::shared_ptr<Model> actualFunction;
std::shared_ptr<Model> referenceFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ class SpaceToBatchTransformation : public LayerTransformation, public testing::W
TEST_P(SpaceToBatchTransformation, CompareFunctions) {
actualFunction->validate_nodes_and_infer_types();

const auto testValues = std::get<1>(GetParam());
const auto output_precision = LayerTransformation::get_output_precision<ngraph::opset2::SpaceToBatch>(actualFunction);
ASSERT_EQ(testValues.expected.preicsionAfterOperation, output_precision);

auto res = compare_functions(actualFunction, referenceFunction, true, false, false);
ASSERT_TRUE(res.first) << res.second;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const std::vector<ngraph::element::Type> netPrecisions = {
// ngraph::element::f16
};

const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams()
};

const std::vector<BatchToSpaceTransformationParam> params = {
// per-tensor quantization
{
Expand Down Expand Up @@ -49,7 +45,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_LPT, BatchToSpaceTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(ov::test::utils::DEVICE_CPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(params)),
BatchToSpaceTransformation::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const std::vector<ngraph::element::Type> netPrecisions = {
// ngraph::element::f16
};

const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams()
};

const std::vector<SpaceToBatchTransformationParam> params = {
{
{ 1, 3, 100, 171 },
Expand Down Expand Up @@ -47,7 +43,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_LPT, SpaceToBatchTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(ov::test::utils::DEVICE_CPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(params)),
SpaceToBatchTransformation::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const std::vector<ngraph::element::Type> netPrecisions = {
ngraph::element::f16
};

const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams(),
};

const std::vector<BatchToSpaceTransformationParam> params = {
{
{ 4, 3, 50, 86 },
Expand Down Expand Up @@ -47,7 +43,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_LPT, BatchToSpaceTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(ov::test::utils::DEVICE_GPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(params)),
BatchToSpaceTransformation::getTestCaseName);
} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const std::vector<ngraph::element::Type> netPrecisions = {
ngraph::element::f16
};

const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams(),
};

const std::vector<SpaceToBatchTransformationParam> params = {
{
{ 1, 3, 100, 171 },
Expand Down Expand Up @@ -47,7 +43,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_LPT, SpaceToBatchTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(ov::test::utils::DEVICE_GPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(params)),
SpaceToBatchTransformation::getTestCaseName);
} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BatchToSpaceTransformationParam {
typedef std::tuple<
ngraph::element::Type,
std::string,
ngraph::pass::low_precision::LayerTransformation::Params,
BatchToSpaceTransformationParam
> BatchToSpaceTransformationParams;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SpaceToBatchTransformationParam {
typedef std::tuple<
ngraph::element::Type,
std::string,
ngraph::pass::low_precision::LayerTransformation::Params,
SpaceToBatchTransformationParam
> SpaceToBatchTransformationParams;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ namespace LayerTestsDefinitions {
std::string BatchToSpaceTransformation::getTestCaseName(const testing::TestParamInfo<BatchToSpaceTransformationParams>& obj) {
ngraph::element::Type input_type;
std::string target_device;
ngraph::pass::low_precision::LayerTransformation::Params params;
BatchToSpaceTransformationParam param;
std::tie(input_type, target_device, params, param) = obj.param;
std::tie(input_type, target_device, param) = obj.param;

std::ostringstream result;
result << input_type << "_" << target_device << "_" << toString(params) << "_" << param.input_shape << "_" << param.fake_quantize;
result << input_type << "_" << target_device << "_" << param.input_shape << "_" << param.fake_quantize;
return result.str();
}

void BatchToSpaceTransformation::SetUp() {
ngraph::element::Type input_type;
ngraph::pass::low_precision::LayerTransformation::Params params;
BatchToSpaceTransformationParam param;
std::tie(input_type, targetDevice, params, param) = this->GetParam();
std::tie(input_type, targetDevice, param) = this->GetParam();

function = ngraph::builder::subgraph::BatchToSpaceFunction::get(
param.input_shape,
Expand All @@ -43,7 +41,7 @@ void BatchToSpaceTransformation::SetUp() {
void BatchToSpaceTransformation::Run() {
LayerTestsCommon::Run();

const auto params = std::get<3>(GetParam());
const auto params = std::get<2>(GetParam());
auto actual_type = getRuntimePrecisionByType(params.layer_type);
const auto expected_type = params.expected_kernel_type;
if ((expected_type == "FP32") && (actual_type == "FP16")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ namespace LayerTestsDefinitions {
std::string SpaceToBatchTransformation::getTestCaseName(const testing::TestParamInfo<SpaceToBatchTransformationParams>& obj) {
ngraph::element::Type input_type;
std::string target_device;
ngraph::pass::low_precision::LayerTransformation::Params params;
SpaceToBatchTransformationParam param;
std::tie(input_type, target_device, params, param) = obj.param;
std::tie(input_type, target_device, param) = obj.param;

std::ostringstream result;
result << input_type << "_" << target_device << "_" << toString(params) << "_" << param.input_shape << "_" << param.fake_quantize;
result << input_type << "_" << target_device << "_" << param.input_shape << "_" << param.fake_quantize;
return result.str();
}

void SpaceToBatchTransformation::SetUp() {
ngraph::element::Type input_type;
ngraph::pass::low_precision::LayerTransformation::Params params;
SpaceToBatchTransformationParam param;
std::tie(input_type, targetDevice, params, param) = this->GetParam();
std::tie(input_type, targetDevice, param) = this->GetParam();

function = ngraph::builder::subgraph::SpaceToBatchFunction::get(
param.input_shape,
Expand All @@ -43,7 +41,7 @@ void SpaceToBatchTransformation::SetUp() {
void SpaceToBatchTransformation::Run() {
LayerTestsCommon::Run();

const auto params = std::get<3>(GetParam());
const auto params = std::get<2>(GetParam());
auto actual_type = getRuntimePrecisionByType(params.layer_type);
const auto expected_type = params.expected_kernel_type;
if ((expected_type == "FP32") && (actual_type == "FP16")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::shared_ptr<ngraph::Function> BatchToSpaceFunction::get(const ngraph::Partia
parent,
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ block_shape.size() }, block_shape),
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ crops_begin.size() }, crops_begin),
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ crops_end.size()}, crops_end));
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ crops_end.size() }, crops_end));

ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(parent)};
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "BatchToSpaceFunction");
Expand All @@ -50,11 +50,9 @@ std::shared_ptr<ngraph::Function> BatchToSpaceFunction::get(const ngraph::Partia
parent,
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ block_shape.size() }, block_shape),
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ crops_begin.size() }, crops_begin),
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ crops_end.size()}, crops_end));
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ crops_end.size() }, crops_end));

if (!dequantization_after.empty()) {
parent = makeDequantization(parent, dequantization_after);
}
parent = makeDequantization(parent, dequantization_after);

ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(parent)};
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "BatchToSpaceFunction");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ std::shared_ptr<ngraph::Function> SpaceToBatchFunction::get(const ngraph::Partia
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ pads_begin.size() }, pads_begin),
std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{ pads_end.size() }, pads_end));

if (!dequantization_after.empty()) {
parent = makeDequantization(parent, dequantization_after);
}
parent = makeDequantization(parent, dequantization_after);

ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(parent)};
return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "SpaceToBatchFunction");
Expand Down

0 comments on commit 5b83a63

Please sign in to comment.