[GPU] Decompose NormalizeL2 for not supported cases (#12404)

This commit is contained in:
Mateusz Bencer
2022-08-11 11:32:03 +02:00
committed by GitHub
parent f0f6896fc0
commit e628fae196
4 changed files with 154 additions and 0 deletions

View File

@@ -64,6 +64,7 @@
#include <transformations/op_conversions/lstm_cell_decomposition.hpp>
#include <transformations/op_conversions/rnn_cell_decomposition.hpp>
#include <transformations/op_conversions/mvn6_decomposition.hpp>
#include <transformations/op_conversions/normalize_l2_decomposition.hpp>
#include <transformations/op_conversions/bidirectional_sequences_decomposition.hpp>
#include <transformations/op_conversions/convert_previous_nms_to_nms_5.hpp>
#include <transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp>
@@ -301,6 +302,35 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
return false;
});
pass_config->enable<ngraph::pass::NormalizeL2Decomposition>();
pass_config->set_callback<ngraph::pass::NormalizeL2Decomposition>(
[](const_node_ptr &node) -> bool {
// Condition to filter out axes such as [0, 1, 2] which is not supported currently.
const auto norm = ov::as_type_ptr<const ngraph::op::v0::NormalizeL2>(node);
const auto inputRank = norm->get_input_partial_shape(0).size();
auto axesNode = ov::as_type_ptr<const ngraph::op::v0::Constant>(norm->get_input_node_shared_ptr(1));
const auto axes = axesNode->cast_vector<size_t>();
const auto isSupportedAxes = [](const std::vector<size_t> &axes, const size_t inputRank) {
if (axes.size() == 1 && axes[0] == 1) {
return true;
} else if (axes.size() == inputRank - 1) {
auto sortAxes = axes;
std::sort(sortAxes.begin(), sortAxes.end());
for (size_t i = 0; i < sortAxes.size(); i++) {
if (sortAxes[i] != i + 1)
return false;
}
return true;
}
return false;
};
if (!isSupportedAxes(axes, inputRank) && ngraph::shape_size(axesNode->get_shape()) != 0) {
return false;
}
return true;
});
pass_config->enable<ngraph::pass::SoftmaxDecomposition>();
pass_config->set_callback<ngraph::pass::SoftmaxDecomposition>(
[](const_node_ptr &node) -> bool {

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "execution_graph_tests/normalize_l2_decomposition.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace ExecutionGraphTests;
namespace {
INSTANTIATE_TEST_SUITE_P(smoke_DecomposeNormalizeL2, ExecGrapDecomposeNormalizeL2,
::testing::Values(CommonTestUtils::DEVICE_GPU),
ExecGrapDecomposeNormalizeL2::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "gtest/gtest.h"
namespace ExecutionGraphTests {
class ExecGrapDecomposeNormalizeL2 : public testing::TestWithParam<std::string> {
public:
static std::string getTestCaseName(testing::TestParamInfo<std::string> obj);
};
} // namespace ExecutionGraphTests

View File

@@ -0,0 +1,92 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <memory>
#include <openvino/runtime/core.hpp>
#include <openvino/opsets/opset9.hpp>
#include "functional_test_utils/skip_tests_config.hpp"
#include "common_test_utils/ngraph_test_utils.hpp"
#include "execution_graph_tests/normalize_l2_decomposition.hpp"
namespace ExecutionGraphTests {
std::string ExecGrapDecomposeNormalizeL2::getTestCaseName(
testing::TestParamInfo<std::string> obj) {
std::string targetDevice = obj.param;
return "Dev=" + targetDevice;
}
TEST_P(ExecGrapDecomposeNormalizeL2, CheckIfDecomposeAppliedForNonContiguousAxes) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
auto device_name = this->GetParam();
const float eps_value = 0.000099f;
const auto input = std::make_shared<ov::opset9::Parameter>(ov::element::f32, ov::PartialShape{3, 4, 5});
const auto axes_const = ov::opset9::Constant::create(ov::element::i64, ov::Shape{2}, {0, 2});
const auto normalize_l2 = std::make_shared<ov::opset9::NormalizeL2>(input, axes_const, eps_value, ov::op::EpsMode::MAX);
const auto model = std::make_shared<ov::Model>(ov::NodeVector{normalize_l2}, ov::ParameterVector{input});
auto core = ov::Core();
const auto compiled_model = core.compile_model(model, device_name);
ASSERT_TRUE(model->get_ops().size() < compiled_model.get_runtime_model()->get_ops().size()); // decomposition applied
}
TEST_P(ExecGrapDecomposeNormalizeL2, CheckIfDecomposeAppliedForNormalizeOverAllAxes) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
auto device_name = this->GetParam();
const float eps_value = 0.000099f;
const auto input = std::make_shared<ov::opset9::Parameter>(ov::element::f32, ov::PartialShape{3, 4, 5});
const auto axes_const = ov::opset9::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 2});
const auto normalize_l2 = std::make_shared<ov::opset9::NormalizeL2>(input, axes_const, eps_value, ov::op::EpsMode::MAX);
const auto model = std::make_shared<ov::Model>(ov::NodeVector{normalize_l2}, ov::ParameterVector{input});
auto core = ov::Core();
const auto compiled_model = core.compile_model(model, device_name);
ASSERT_TRUE(model->get_ops().size() < compiled_model.get_runtime_model()->get_ops().size()); // decomposition applied
}
TEST_P(ExecGrapDecomposeNormalizeL2, CheckIfDecomposeNotAppliedForNotSorted) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
auto device_name = this->GetParam();
const float eps_value = 0.000099f;
const auto input = std::make_shared<ov::opset9::Parameter>(ov::element::f32, ov::PartialShape{2, 1});
const auto axes_const = ov::opset9::Constant::create(ov::element::i64, ov::Shape{1}, {1});
const auto normalize_l2 = std::make_shared<ov::opset9::NormalizeL2>(input, axes_const, eps_value, ov::op::EpsMode::ADD);
const auto model = std::make_shared<ov::Model>(ov::NodeVector{normalize_l2}, ov::ParameterVector{input});
auto core = ov::Core();
const auto compiled_model = core.compile_model(model, device_name);
ASSERT_TRUE(model->get_ops().size() >= compiled_model.get_runtime_model()->get_ops().size()); // decomposition not applied
}
TEST_P(ExecGrapDecomposeNormalizeL2, CheckIfDecomposeNotAppliedForSingleAxis) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
auto device_name = this->GetParam();
const float eps_value = 0.000099f;
const auto input = std::make_shared<ov::opset9::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 3});
const auto axes_const = ov::opset9::Constant::create(ov::element::i64, ov::Shape{1}, {1});
const auto normalize_l2 = std::make_shared<ov::opset9::NormalizeL2>(input, axes_const, eps_value, ov::op::EpsMode::ADD);
const auto model = std::make_shared<ov::Model>(ov::NodeVector{normalize_l2}, ov::ParameterVector{input});
auto core = ov::Core();
const auto compiled_model = core.compile_model(model, device_name);
ASSERT_TRUE(model->get_ops().size() >= compiled_model.get_runtime_model()->get_ops().size()); // decomposition not applied
}
} // namespace ExecutionGraphTests