Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[LPT] NetworkHelper: fixed core helpers (#33799)

Vladislav Golubev4786f64a18b9
diff --git a/src/common/low_precision_transformations/include/low_precision/network_helper.hpp b/src/common/low_precision_transformations/include/low_precision/network_helper.hpp
index bd400e0660a..daf88367a6c 100644
--- a/src/common/low_precision_transformations/include/low_precision/network_helper.hpp
+++ b/src/common/low_precision_transformations/include/low_precision/network_helper.hpp
@@ -6,6 +6,7 @@
#include <cmath>
#include <memory>
+#include <optional>
#include <string>
#include <vector>
#include <unordered_set>
@@ -139,6 +140,8 @@ public:
static FakeQuantizeDequantization getDequantizationBelow(const std::shared_ptr<Node>& node, const bool convertIsMandatory = false);
+ static std::optional<size_t> getDQConstBranchIndex(const std::shared_ptr<ov::Node>& eltwise);
+
static FakeQuantizeDequantization normalizeDequantization(FakeQuantizeDequantization dequantization);
static std::shared_ptr<ov::opset1::Constant> normalizeDequantizationShape(
diff --git a/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp b/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp
index 497c235d222..effeed8b019 100644
--- a/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp
+++ b/src/common/low_precision_transformations/src/fake_quantize_dequantization.cpp
@@ -31,6 +31,14 @@ FakeQuantizeDequantization::FakeQuantizeDequantization(
subtractConstant(subtractConstant),
multiply(multiply),
multiplyConstant(multiplyConstant) {
+ OPENVINO_ASSERT(data.get_node() != nullptr, "Incorrect dequantization operations: data node is null");
+ const auto dataNode = data.get_node_shared_ptr();
+ OPENVINO_ASSERT(convert == nullptr || subtractConvert == nullptr || convert != subtractConvert,
+ "Incorrect dequantization operations: convert and subtractConvert are the same");
+ OPENVINO_ASSERT(subtractConstant == nullptr || dataNode != subtractConstant,
+ "Incorrect dequantization operations: dataNode and subtractConstant are the same");
+ OPENVINO_ASSERT(multiplyConstant == nullptr || dataNode != multiplyConstant,
+ "Incorrect dequantization operations: dataNode and multiplyConstant are the same");
const auto rank = data.get_partial_shape().rank();
if (rank.is_static()) {
std::string data_src_type = data.get_node()->get_type_name();
@@ -242,56 +250,36 @@ int FakeQuantizeDequantization::fillDequantizationParams(
const std::shared_ptr<ov::Node>& elementwise,
std::shared_ptr<ov::opset1::Convert>& convert,
std::shared_ptr<ov::opset1::Constant>& constant) {
- auto fill = [](
- const std::shared_ptr<ov::Node>& elementwise,
- const size_t branchIndex,
- std::shared_ptr<ov::opset1::Convert>& convert,
- std::shared_ptr<ov::opset1::Constant>& constant) {
- convert = ov::as_type_ptr<opset1::Convert>(elementwise->get_input_node_shared_ptr(branchIndex));
- if (convert != nullptr) {
- constant = convert->get_destination_type().is_real() ?
- ov::as_type_ptr<opset1::Constant>(convert->get_input_node_shared_ptr(0)) :
- nullptr;
- } else {
- constant = elementwise->get_input_element_type(branchIndex).is_real() ?
- ov::as_type_ptr<opset1::Constant>(elementwise->get_input_node_shared_ptr(branchIndex)) :
- nullptr;
- }
- };
-
- fill(elementwise, 1ul, convert, constant);
- if (constant != nullptr) {
- return 1;
+ const auto constantBranchIndex = NetworkHelper::getDQConstBranchIndex(elementwise);
+ if (!constantBranchIndex.has_value()) {
+ return -1;
}
- fill(elementwise, 0ul, convert, constant);
- if (constant != nullptr) {
- return 0;
+ convert = ov::as_type_ptr<opset1::Convert>(elementwise->get_input_node_shared_ptr(*constantBranchIndex));
+ if (convert != nullptr) {
+ constant = convert->get_destination_type().is_real() ?
+ ov::as_type_ptr<opset1::Constant>(convert->get_input_node_shared_ptr(0)) :
+ nullptr;
+ } else {
+ constant = elementwise->get_input_element_type(*constantBranchIndex).is_real() ?
+ ov::as_type_ptr<opset1::Constant>(elementwise->get_input_node_shared_ptr(*constantBranchIndex)) :
+ nullptr;
}
-
- return -1;
+ return constant != nullptr ? static_cast<int>(*constantBranchIndex) : -1;
}
int FakeQuantizeDequantization::fillDequantizationParams(
const std::shared_ptr<ov::Node>& elementwise,
std::shared_ptr<ov::opset1::Constant>& constant) {
- constant = elementwise->get_input_element_type(1ul).is_real() ?
- ov::as_type_ptr<opset1::Constant>(elementwise->get_input_node_shared_ptr(1ul)) :
- nullptr;
-
- if (constant != nullptr) {
- return 1;
+ const auto constantBranchIndex = NetworkHelper::getDQConstBranchIndex(elementwise);
+ if (!constantBranchIndex.has_value()) {
+ return -1;
}
- constant = elementwise->get_input_element_type(0ul).is_real() ?
- ov::as_type_ptr<opset1::Constant>(elementwise->get_input_node_shared_ptr(0ul)) :
+ constant = elementwise->get_input_element_type(*constantBranchIndex).is_real() ?
+ ov::as_type_ptr<opset1::Constant>(elementwise->get_input_node_shared_ptr(*constantBranchIndex)) :
nullptr;
-
- if (constant != nullptr) {
- return 0;
- }
-
- return -1;
+ return constant != nullptr ? static_cast<int>(*constantBranchIndex) : -1;
}
} // namespace low_precision
diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cpp
index 0fe0420be73..472d0f140fc 100644
--- a/src/common/low_precision_transformations/src/network_helper.cpp
+++ b/src/common/low_precision_transformations/src/network_helper.cpp
@@ -560,40 +560,50 @@ std::shared_ptr<ov::Node> NetworkHelper::separateInStandaloneBranch(std::shared_
const std::vector<ov::element::Type>& defaultPrecisions) {
auto inputs = node->input_values();
auto separate_branch = [&](size_t input_idx) {
- const auto dequantization = NetworkHelper::normalizeDequantization(NetworkHelper::getDequantization(node, defaultPrecisions, input_idx));
+ const auto dequantization = normalizeDequantization(getDequantization(node, defaultPrecisions, input_idx));
if (dequantization.empty() || !dequantization.isShared())
return false;
+ const std::string name_postfix = "_" + std::to_string(input_idx);
Output<Node> parent = dequantization.data;
if (dequantization.convert != nullptr) {
- auto convert = dequantization.convert->clone_with_new_inputs({ parent });
- convert->set_friendly_name("");
- copy_runtime_info(parent.get_node_shared_ptr(), convert);
- parent = convert->output(0);
- }
-
- if (dequantization.subtract != nullptr) {
- const auto parentOnWeights = dequantization.subtract->get_input_node_shared_ptr(1);
- const std::vector<Input<Node>> inputs = parentOnWeights->inputs();
- OutputVector outputs;
- outputs.reserve(inputs.size());
- for (const auto& input : inputs) {
- outputs.push_back(input.get_source_output());
+ parent = dequantization.convert->clone_with_new_inputs({parent});
+ parent.get_node_shared_ptr()->set_friendly_name(dequantization.convert->get_friendly_name() + name_postfix);
+ copy_runtime_info(dequantization.convert, parent.get_node_shared_ptr());
+ }
+
+ auto cloneEltwiseBranch = [&](const std::shared_ptr<ov::Node>& eltwise,
+ const std::shared_ptr<ov::opset1::Constant>& eltwiseConstant,
+ const std::shared_ptr<ov::opset1::Convert>& eltwiseConvert) {
+ Output<Node> constantPath;
+ if (eltwiseConvert != nullptr) {
+ constantPath = eltwiseConvert->clone_with_new_inputs({eltwiseConstant->clone_with_new_inputs({})});
+ constantPath.get_node_shared_ptr()->set_friendly_name(eltwiseConvert->get_friendly_name() +
+ name_postfix);
+ copy_runtime_info(eltwiseConvert, constantPath.get_node_shared_ptr());
+ } else {
+ const auto parentOnWeights = eltwise->get_input_node_shared_ptr(1);
+ constantPath = parentOnWeights->clone_with_new_inputs(parentOnWeights->input_values());
+ constantPath.get_node_shared_ptr()->set_friendly_name(parentOnWeights->get_friendly_name() +
+ name_postfix);
+ copy_runtime_info(parentOnWeights, constantPath.get_node_shared_ptr());
}
+ auto clonedEltwise = eltwise->clone_with_new_inputs({parent, constantPath});
+ clonedEltwise->set_friendly_name(eltwise->get_friendly_name() + name_postfix);
+ copy_runtime_info(eltwise, clonedEltwise);
+ return clonedEltwise;
+ };
- auto subtract = dequantization.subtract->clone_with_new_inputs({parent, parentOnWeights->clone_with_new_inputs(outputs)->output(0) });
- subtract->set_friendly_name("");
- copy_runtime_info(parent.get_node_shared_ptr(), subtract);
- parent = subtract->output(0);
+ if (dequantization.subtract != nullptr) {
+ parent = cloneEltwiseBranch(dequantization.subtract, dequantization.subtractConstant, dequantization.subtractConvert);
}
if (dequantization.multiply != nullptr) {
- auto multiply = dequantization.multiply->clone_with_new_inputs({
- parent,
- dequantization.multiply->get_input_node_shared_ptr(1)->clone_with_new_inputs({})->output(0) });
- multiply->set_friendly_name("");
- copy_runtime_info(parent.get_node_shared_ptr(), multiply);
- parent = multiply->output(0);
+ std::shared_ptr<ov::opset1::Convert> mulConstConvert;
+ std::shared_ptr<ov::opset1::Constant> mulConst;
+ // WA: FakeQuantizeDequantization doesn't have multiplyConvert member, so we have to extract it manually
+ FakeQuantizeDequantization::fillDequantizationParams(dequantization.multiply, mulConstConvert, mulConst);
+ parent = cloneEltwiseBranch(dequantization.multiply, mulConst, mulConstConvert);
}
OPENVINO_ASSERT(dequantization.multiply != nullptr || dequantization.subtract != nullptr, "incorrect dequantization ops configuration");
@@ -1137,21 +1147,9 @@ FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_pt
const size_t parentIndex,
const bool inPlace) {
auto getDataIndex = [](const std::shared_ptr<ov::Node>& node) {
- if (ov::is_type<ov::opset1::Constant>(node->get_input_node_ptr(1))) {
- return 0ul;
- }
-
- if (ov::is_type<ov::opset1::Convert>(node->get_input_node_ptr(1)) &&
- ov::is_type<ov::opset1::Constant>(node->get_input_node_ptr(1)->get_input_node_ptr(0))) {
- return 0ul;
- }
-
- if (ov::is_type<ov::opset1::Convert>(node->get_input_node_ptr(0)) &&
- ov::is_type<ov::opset1::Constant>(node->get_input_node_ptr(0)->get_input_node_ptr(0))) {
- return 1ul;
- }
-
- return 1ul;
+ const auto dqConstBranchIndex = getDQConstBranchIndex(node);
+ OPENVINO_ASSERT(dqConstBranchIndex.has_value(), "getDataIndex cannot be determined for node: ", node);
+ return dqConstBranchIndex.value() == 0ul ? 1ul : 0ul;
};
Output<Node> dataNode;
@@ -1262,10 +1260,10 @@ FakeQuantizeDequantization NetworkHelper::getDequantizationBelow(const std::shar
return FakeQuantizeDequantization(dataNode, convert, subtract, subtractConvert, subtractConstant, multiply, multiplyConstant);
}
-FakeQuantizeDequantization NetworkHelper::normalizeDequantization(FakeQuantizeDequantization dequantization) {
- if (dequantization.empty()) {
- return dequantization;
- }
+std::optional<size_t> NetworkHelper::getDQConstBranchIndex(const std::shared_ptr<ov::Node>& eltwise) {
+ OPENVINO_ASSERT(eltwise != nullptr && eltwise->get_input_size() == 2,
+ "Expected binary eltwise operation, but got: ",
+ eltwise == nullptr ? "null" : std::to_string(eltwise->get_input_size()) + " inputs");
// Note: Dequantization operations might have converts between DQ constant and eltwise
auto is_branch_const = [](const ov::Output<ov::Node>& in) {
@@ -1274,24 +1272,57 @@ FakeQuantizeDequantization NetworkHelper::normalizeDequantization(FakeQuantizeDe
(ov::is_type<ov::opset1::Convert>(node) && ov::is_type<ov::opset1::Constant>(node->get_input_node_shared_ptr(0)));
};
- // Eltwise is unnormalized if it has constant 0th input and non-constant 1st input
- auto unnormalized_eltwise = [&is_branch_const](const std::shared_ptr<ov::Node>& eltwise) {
- return eltwise != nullptr && is_branch_const(eltwise->input_value(0)) && !is_branch_const(eltwise->input_value(1));
+ const auto& left_input = eltwise->input_value(0);
+ const auto& right_input = eltwise->input_value(1);
+ const bool left_is_const = is_branch_const(left_input);
+ const bool right_is_const = is_branch_const(right_input);
+
+ if (!left_is_const && right_is_const) {
+ return 1;
+ }
+ if (left_is_const && !right_is_const) {
+ return 0;
+ }
+
+ // When both branches are constant, we use shape-based criteria to determine dequantization const branch.
+ // Since the primary criteria (constant vs non-constant) cannot distinguish between branches,
+ // we apply secondary logic: the branch with larger volume is considered the main branch
+ // and should be placed on the left (0th input), while the smaller branch goes on the right (1st input).
+ if (left_is_const && right_is_const) {
+ const auto left_volume = ov::shape_size(left_input.get_shape());
+ const auto right_volume = ov::shape_size(right_input.get_shape());
+ return left_volume >= right_volume ? 1 : 0;
+ }
+ return std::nullopt;
+}
+
+FakeQuantizeDequantization NetworkHelper::normalizeDequantization(FakeQuantizeDequantization dequantization) {
+ if (dequantization.empty()) {
+ return dequantization;
+ }
+
+ // Determine if eltwise operation needs normalization (DQ constant branch should be on right)
+ auto should_normalize_eltwise = [](const std::shared_ptr<ov::Node>& eltwise) {
+ if (eltwise == nullptr) {
+ return false;
+ }
+ const auto dqConstBranchIndex = getDQConstBranchIndex(eltwise);
+ return dqConstBranchIndex.has_value() ? dqConstBranchIndex.value() == 0 : false;
};
- if (unnormalized_eltwise(dequantization.multiply)) {
+ if (should_normalize_eltwise(dequantization.multiply)) {
const auto leftParent = dequantization.multiply->input_value(0);
const auto rightParent = dequantization.multiply->input_value(1);
- std::shared_ptr<ov::opset1::Multiply> normalized_multiply = ov::as_type_ptr<ov::opset1::Multiply>(
- dequantization.multiply->clone_with_new_inputs({rightParent, leftParent}));
+ const auto normalized_multiply = ov::as_type_ptr<ov::opset1::Multiply>(
+ dequantization.multiply->clone_with_new_inputs({rightParent, leftParent}));
replace_node(dequantization.multiply, normalized_multiply);
dequantization.multiply = normalized_multiply;
}
- if (unnormalized_eltwise(dequantization.subtract)) {
+ if (should_normalize_eltwise(dequantization.subtract)) {
const auto leftParent = dequantization.subtract->input_value(0);
const auto rightParent = dequantization.subtract->input_value(1);
- std::shared_ptr<ov::opset1::Subtract> normalized_subtract = ov::as_type_ptr<ov::opset1::Subtract>(
- dequantization.subtract->clone_with_new_inputs({rightParent, leftParent}));
+ const auto normalized_subtract = ov::as_type_ptr<ov::opset1::Subtract>(
+ dequantization.subtract->clone_with_new_inputs({rightParent, leftParent}));
replace_node(dequantization.subtract, normalized_subtract);
dequantization.subtract = normalized_subtract;
}
diff --git a/src/common/low_precision_transformations/tests/normalize_dequantization_transformation.cpp b/src/common/low_precision_transformations/tests/normalize_dequantization_transformation.cpp
index 39b1f1fbefc..311f35157c5 100644
--- a/src/common/low_precision_transformations/tests/normalize_dequantization_transformation.cpp
+++ b/src/common/low_precision_transformations/tests/normalize_dequantization_transformation.cpp
@@ -233,6 +233,48 @@ const std::vector<NormalizeDequantizationTestValues> testValues = {
},
},
},
+ {
+ LayerTransformation::createParamsU8I8(),
+ { 1, 3, 16, 16 },
+ true,
+ {
+ ov::element::f32,
+ {
+ {ov::element::f16},
+ {},
+ { {10.f}, ov::element::f16, { 1, 3, 1, 1 }, false, 0 }
+ },
+ },
+ {
+ ov::element::f32,
+ {
+ {ov::element::f16},
+ {},
+ { {10.f}, ov::element::f16, { 1, 3, 1, 1 }, false, 1 }
+ }
+ },
+ },
+ {
+ LayerTransformation::createParamsU8I8(),
+ { 1, 3, 16, 16 },
+ true,
+ {
+ ov::element::f32,
+ {
+ {ov::element::f16},
+ { {128.f}, ov::element::f16, { 1, 3, 1, 1 }, false, 0 },
+ {}
+ },
+ },
+ {
+ ov::element::f32,
+ {
+ {ov::element::f16},
+ { {128.f}, ov::element::f16, { 1, 3, 1, 1 }, false, 1 },
+ {}
+ }
+ },
+ },
};
INSTANTIATE_TEST_SUITE_P(
diff --git a/src/common/low_precision_transformations/tests/separate_in_standalone_branch_transformation.cpp b/src/common/low_precision_transformations/tests/separate_in_standalone_branch_transformation.cpp
index 8655cbc1852..09863f38733 100644
--- a/src/common/low_precision_transformations/tests/separate_in_standalone_branch_transformation.cpp
+++ b/src/common/low_precision_transformations/tests/separate_in_standalone_branch_transformation.cpp
@@ -14,6 +14,7 @@
#include "transformations/init_node_info.hpp"
#include "low_precision/mat_mul.hpp"
+#include "common_test_utils/graph_comparator.hpp"
#include "common_test_utils/ov_test_utils.hpp"
#include "ov_lpt_models/common/builders.hpp"
#include "ov_lpt_models/mat_mul.hpp"
@@ -27,113 +28,117 @@ namespace {
using namespace testing;
using namespace ov::pass;
+using namespace ov::builder::subgraph;
class SeparateInStandaloneBranchTransformationTestValues {
public:
TestTransformationParams params;
ov::element::Type precisionBefore;
- ov::builder::subgraph::DequantizationOperations dequantization;
+ DequantizationOperations dequantization;
};
inline std::ostream& operator << (std::ostream& out, const SeparateInStandaloneBranchTransformationTestValues& testValues) {
return out << "_" << testValues.dequantization;
}
-typedef std::tuple<
- ov::Shape,
- SeparateInStandaloneBranchTransformationTestValues> SeparateInStandaloneBranchTransformationParams;
+typedef std::tuple<ov::Shape, // input shape
+ SeparateInStandaloneBranchTransformationTestValues,
+ bool> // is constant path
+ SeparateInStandaloneBranchTransformationParams;
class SeparateInStandaloneBranchTransformation :
public LayerTransformation,
public testing::WithParamInterface<SeparateInStandaloneBranchTransformationParams> {
public:
void SetUp() override {
- const ov::Shape shape = std::get<0>(GetParam());
- const SeparateInStandaloneBranchTransformationTestValues testValues = std::get<1>(GetParam());
-
- const auto createActualFunction = [](
- const ov::element::Type precision,
- const ov::Shape& inputShape,
- const ov::builder::subgraph::DequantizationOperations& dequantizations) -> std::shared_ptr<ov::Model> {
- const std::shared_ptr<ov::op::v0::Parameter> input = std::make_shared<ov::op::v0::Parameter>(precision, inputShape);
- const auto relu = std::make_shared<ov::op::v0::Relu>(input);
- const auto dequantizationsNode = ov::builder::subgraph::makeDequantization(relu, dequantizations);
-
- const std::shared_ptr<ov::Node> reshape1 = std::make_shared<ov::op::v1::Reshape>(
+ ov::Shape inputShape;
+ SeparateInStandaloneBranchTransformationTestValues testValues;
+ bool isConstantPath;
+ std::tie(inputShape, testValues, isConstantPath) = GetParam();
+ const auto& precision = testValues.precisionBefore;
+
+ const auto createActualFunction = [&](const DequantizationOperations& dequantizations) {
+ ov::ParameterVector params;
+ std::shared_ptr<ov::Node> input;
+ if (isConstantPath) {
+ input = ov::op::v0::Constant::create(precision, inputShape, std::vector<float>{137.f});
+ } else {
+ params.push_back(std::make_shared<ov::op::v0::Parameter>(precision, inputShape));
+ input = params.back();
+ }
+ const auto dequantizationsNode = makeDequantization(input, dequantizations);
+
+ const auto reshape1 = std::make_shared<ov::op::v1::Reshape>(
dequantizationsNode,
- std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{ 2 }, std::vector<double>({0, -1})),
+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>({0, -1})),
true);
reshape1->set_friendly_name("reshape1");
- const std::shared_ptr<ov::Node> reshape2 = std::make_shared<ov::op::v1::Reshape>(
+ const auto reshape2 = std::make_shared<ov::op::v1::Reshape>(
dequantizationsNode,
- std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{ 2 }, std::vector<double>({0, -1})),
+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>({0, -1})),
true);
reshape2->set_friendly_name("reshape2");
- return std::make_shared<ov::Model>(
- ov::ResultVector{
- std::make_shared<ov::op::v0::Result>(reshape1),
- std::make_shared<ov::op::v0::Result>(reshape2)
- },
- std::vector<std::shared_ptr<ov::op::v0::Parameter>> { input },
- "SeparateInStandaloneBranchTransformation");
+ return std::make_shared<ov::Model>(ov::OutputVector{reshape1, reshape2},
+ params,
+ "SeparateInStandaloneBranchTransformation");
};
- actualFunction = createActualFunction(testValues.precisionBefore, shape, testValues.dequantization);
+ actualFunction = createActualFunction(testValues.dequantization);
const auto result = actualFunction->get_results()[0];
ov::pass::low_precision::NetworkHelper::separateInStandaloneBranch(result->get_input_node_shared_ptr(0));
- const auto createReferenceFunction = [](
- const ov::element::Type precision,
- const ov::Shape& inputShape,
- ov::builder::subgraph::DequantizationOperations dequantization) -> std::shared_ptr<ov::Model> {
+ const auto createReferenceFunction = [&](DequantizationOperations dequantization) {
// Note: separateInStandaloneBranch normalizes dequantization so constant indexes become equal to 1
if (!dequantization.subtract.empty())
dequantization.subtract.constantIndex = 1;
if (!dequantization.multiply.empty())
dequantization.multiply.constantIndex = 1;
- const std::shared_ptr<ov::op::v0::Parameter> input = std::make_shared<ov::op::v0::Parameter>(precision, inputShape);
- const auto relu = std::make_shared<ov::op::v0::Relu>(input);
-
- const std::shared_ptr<ov::Node> reshape1 = std::make_shared<ov::op::v1::Reshape>(
- ov::builder::subgraph::makeDequantization(relu, dequantization),
- std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{ 2 }, std::vector<double>({0, -1})),
+ ov::ParameterVector params;
+ std::shared_ptr<ov::Node> input;
+ if (isConstantPath) {
+ input = ov::op::v0::Constant::create(precision, inputShape, std::vector<float>{137.f});
+ } else {
+ params.push_back(std::make_shared<ov::op::v0::Parameter>(precision, inputShape));
+ input = params.back();
+ }
+
+ const auto reshape1 = std::make_shared<ov::op::v1::Reshape>(
+ makeDequantization(input, dequantization),
+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>({0, -1})),
true);
reshape1->set_friendly_name("reshape1");
- const std::shared_ptr<ov::Node> reshape2 = std::make_shared<ov::op::v1::Reshape>(
- ov::builder::subgraph::makeDequantization(relu, dequantization),
- std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{ 2 }, std::vector<double>({0, -1})),
+ const auto reshape2 = std::make_shared<ov::op::v1::Reshape>(
+ makeDequantization(input, dequantization),
+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>({0, -1})),
true);
reshape2->set_friendly_name("reshape2");
- return std::make_shared<ov::Model>(
- ov::ResultVector{
- std::make_shared<ov::op::v0::Result>(reshape1),
- std::make_shared<ov::op::v0::Result>(reshape2)
- },
- std::vector<std::shared_ptr<ov::op::v0::Parameter>> { input },
- "SeparateInStandaloneBranchTransformation");
+ return std::make_shared<ov::Model>(ov::OutputVector{reshape1, reshape2},
+ params,
+ "SeparateInStandaloneBranchTransformation");
};
- referenceFunction = createReferenceFunction(testValues.precisionBefore, shape, testValues.dequantization);
+ referenceFunction = createReferenceFunction(testValues.dequantization);
}
static std::string getTestCaseName(testing::TestParamInfo<SeparateInStandaloneBranchTransformationParams> obj) {
- const auto& [shapes, testValues] = obj.param;
-
+ const auto& [shapes, testValues, isConstantPath] = obj.param;
std::stringstream ss;
- ss << shapes << "_" << testValues;
+ ss << shapes << "_" << testValues << "_is_constant_path_" << isConstantPath;
return ss.str();
}
};
TEST_P(SeparateInStandaloneBranchTransformation, CompareFunctions) {
- actualFunction->validate_nodes_and_infer_types();
- auto res = compare_functions(actualFunction, referenceFunction, true, true, false);
- ASSERT_TRUE(res.first) << res.second;
-
ASSERT_TRUE(LayerTransformation::allNamesAreUnique(actualFunction)) << "Not all names are unique";
+ auto comparator = FunctionsComparator::with_default()
+ .enable(FunctionsComparator::CmpValues::CONSUMERS_COUNT)
+ .enable(FunctionsComparator::CmpValues::CONST_VALUES)
+ .enable(FunctionsComparator::CmpValues::NAMES);
+ auto res = comparator.compare(actualFunction, referenceFunction);
+ ASSERT_TRUE(res.valid) << res.message;
}
const std::vector<ov::Shape> shapes = {
@@ -169,6 +174,15 @@ std::vector<SeparateInStandaloneBranchTransformationTestValues> testValues = {
{ {0.02f}, ov::element::f32, {}, false, 0ul }
}
},
+ {
+ LayerTransformation::createParamsU8U8(),
+ ov::element::u8,
+ {
+ ov::element::f32,
+ {},
+ {{0.02f}, ov::element::f32, {1, 3, 1, 1}, false, 0ul}
+ }
+ },
};
INSTANTIATE_TEST_SUITE_P(
@@ -176,7 +190,7 @@ INSTANTIATE_TEST_SUITE_P(
SeparateInStandaloneBranchTransformation,
::testing::Combine(
::testing::ValuesIn(shapes),
- ::testing::ValuesIn(testValues)),
+ ::testing::ValuesIn(testValues),
+ ::testing::Values(false, true)),
SeparateInStandaloneBranchTransformation::getTestCaseName);
-
} // namespace