Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ngraph] Fix compare runtime info function #14

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class TRANSFORMATIONS_API NetworkHelper {
// handles only specific case: Constant -> [dequantization operations] -> [node]
static void foldDequantization(std::shared_ptr<Node>& node, const size_t branchIndex, const bool inPlace = false);

static std::shared_ptr<Node> mark_as_dequantization_op(std::shared_ptr<Node> op);

private:
static std::shared_ptr<Node> foldFakeQuantize(const std::shared_ptr<opset1::FakeQuantize>& fq, const bool roundValues, const bool roundValuesWasSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,12 @@ std::shared_ptr<Node> NetworkHelper::toScalarIfPossible(std::shared_ptr<Node> no
return NetworkHelper::toScalar(constant);
}

std::shared_ptr<Node> NetworkHelper::mark_as_dequantization_op(std::shared_ptr<Node> op) {
auto opCopy = op->clone_with_new_inputs(op->input_values());
auto& rtInfo = opCopy->get_rt_info();
rtInfo["DEQUANTIZATION"] = std::make_shared<VariantWrapper<DequantizationAttr>>(DequantizationAttr());
return opCopy;
}

} // namespace low_precision
} // namespace pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ bool compare_rt_keys(const std::shared_ptr<ngraph::Node>& node1, const std::shar
const auto& first_node_rt_info = node1->get_rt_info();
const auto& second_node_rt_info = node2->get_rt_info();

// TODO: should be uncommented
// if (first_node_rt_info.size() != second_node_rt_info.size()) {
// return false;
// }

for (auto first_it = first_node_rt_info.begin(); first_it != first_node_rt_info.end(); ++first_it) {
bool was_found = false;
for (auto secont_it = second_node_rt_info.begin(); secont_it != second_node_rt_info.end(); ++secont_it) {
if (first_it->first == secont_it->first) {
was_found = true;
break;
}
}
if (!was_found) {
if (first_node_rt_info.empty() && second_node_rt_info.empty()) {
return true;
}

if (first_node_rt_info.size() != second_node_rt_info.size()) {
return false;
}

auto first_node_rt_info_it = first_node_rt_info.begin();
auto second_node_rt_info_it = second_node_rt_info.begin();
while (first_node_rt_info_it != first_node_rt_info.end()) {
if (first_node_rt_info_it->first != second_node_rt_info_it->first) {
return false;
}
++first_node_rt_info_it;
++second_node_rt_info_it;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ std::shared_ptr<ngraph::Function> ConvertMulOrAddWithDequantizationFunction::get

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);
const auto scaleShift = std::make_shared<ngraph::op::ScaleShiftIE>(relu, weights, bias);
std::shared_ptr<Node> scaleShift = std::make_shared<ngraph::op::ScaleShiftIE>(relu, weights, bias);

scaleShift = low_precision::NetworkHelper::mark_as_dequantization_op(scaleShift);

scaleShift->set_friendly_name("output");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace subgraph {

std::shared_ptr<ngraph::Node> lastNode;
if (isDequantization) {
const auto scaleshift = std::make_shared<ngraph::op::ScaleShiftIE>(input, weights, biases, precisionAfterOperation);
std::shared_ptr<Node> scaleshift = std::make_shared<ngraph::op::ScaleShiftIE>(input, weights, biases, precisionAfterOperation);
scaleshift = low_precision::NetworkHelper::mark_as_dequantization_op(scaleshift);
scaleshift->set_friendly_name("add");
lastNode = scaleshift;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ngraph_ops/type_relaxed.hpp>
#include <ngraph/opsets/opset1.hpp>
#include "ngraph_functions/subgraph_builders.hpp"
#include "transformations/low_precision/common/dequantization_op.hpp"

namespace ngraph {
namespace builder {
Expand Down Expand Up @@ -125,7 +126,7 @@ std::shared_ptr<ngraph::Function> NormalizeL2Function::getReference(
std::shared_ptr<ngraph::Node> output = normalizeL2;

if (!expectedValues.mutliplyValues.empty()) {
const std::shared_ptr<ngraph::Node> multiply = std::make_shared<ngraph::op::TypeRelaxed<ngraph::opset1::Multiply>>(
const std::shared_ptr<ngraph::Node> multiply = std::make_shared<ngraph::op::TypeRelaxed<pass::low_precision::DequantizationMultiply>>(
std::vector<ngraph::element::Type>{ element::f32, element::f32 }, std::vector<ngraph::element::Type>{element::f32},
ngraph::op::TemporaryReplaceOutputType(output, element::f32).get(),
ngraph::op::TemporaryReplaceOutputType(std::make_shared<ngraph::opset1::Constant>(
Expand Down