Skip to content

Commit

Permalink
Resolved unexpected -1s in IRs (openvinotoolkit#7709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenya Stepyreva authored Sep 30, 2021
1 parent fab4056 commit b339bb7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unordered_set>

#include <ngraph/variant.hpp>
#include <transformations/rt_info/disable_constant_folding.hpp>
#include "ngraph/ops.hpp"
#include "ngraph/opsets/opset.hpp"
#include "ngraph/opsets/opset1.hpp"
Expand Down Expand Up @@ -718,7 +719,7 @@ bool resolve_dynamic_shapes(const ngraph::Function& f) {
for (size_t id = 0; id < f_ops.size(); ++id) {
auto & op = f_ops[id];
auto & clone_op = f_clone_ops[id];

enable_constant_folding(clone_op); // to be able to fold ShapeOfs
if (auto op_subgraph = std::dynamic_pointer_cast<ngraph::op::util::SubGraphOp>(op)) {
resolve_dynamic_shapes(*op_subgraph->get_function());
}
Expand Down Expand Up @@ -767,6 +768,56 @@ bool resolve_dynamic_shapes(const ngraph::Function& f) {
return true;
}

void auto_pad_resolving(ov::Node* node) {
const std::set<ov::op::PadType> pad_agnostic_types = {
ov::op::PadType::SAME_LOWER,
ov::op::PadType::SAME_UPPER,
ov::op::PadType::VALID,
ov::op::PadType::AUTO,
};
if (auto op = as_type<opset1::Convolution>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0));
op->set_adding_above(CoordinateDiff(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<opset1::GroupConvolution>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0));
op->set_adding_above(CoordinateDiff(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<opset1::ConvolutionBackpropData>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0));
op->set_pads_end(CoordinateDiff(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<opset1::GroupConvolutionBackpropData>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0));
op->set_pads_end(CoordinateDiff(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<ngraph::op::util::DeformableConvolutionBase>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0));
op->set_pads_end(CoordinateDiff(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<opset1::BinaryConvolution>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0));
op->set_adding_above(CoordinateDiff(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<opset1::AvgPool>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(Shape(op->get_pads_begin().size(), 0));
op->set_pads_end(Shape(op->get_pads_end().size(), 0));
}
} else if (auto op = as_type<ngraph::op::util::MaxPoolBase>(node)) {
if (pad_agnostic_types.count(op->get_auto_pad())) {
op->set_pads_begin(Shape(op->get_pads_begin().size(), 0));
op->set_adding_above(Shape(op->get_pads_end().size(), 0));
}
}
}

void ngfunction_2_irv10(pugi::xml_node& netXml,
const ngraph::Function& f,
const std::map<std::string, ngraph::OpSet>& custom_opsets,
Expand Down Expand Up @@ -905,6 +956,7 @@ void ngfunction_2_irv10(pugi::xml_node& netXml,
}

// fill <data> general attributes
auto_pad_resolving(node); // Backward compatibility: clear padding values for nodes with auto_pad
XmlSerializer visitor(data, node_type_name, custom_opsets, constant_node_write_handler);
NGRAPH_CHECK(node->visit_attributes(visitor), "Visitor API is not supported in ", node);
rt_info::XmlSerializer{data}.serialize(node->get_rt_info());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void LayerTestsCommon::Serialize() {
ngraph::pass::Manager manager;
manager.register_pass<ngraph::pass::Serialize>(out_xml_path, out_bin_path);
manager.run_passes(function);
function->validate_nodes_and_infer_types();

auto result = getCore()->ReadNetwork(out_xml_path, out_bin_path);

Expand Down

0 comments on commit b339bb7

Please sign in to comment.