Skip to content

Commit

Permalink
getting back transformations present in NPU
Browse files Browse the repository at this point in the history
  • Loading branch information
CuriousPanCake committed Mar 21, 2024
1 parent 4d51526 commit 85eb7ee
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 52 deletions.
6 changes: 0 additions & 6 deletions src/common/snippets/src/op/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,10 @@ auto Subgraph::wrap_node_as_subgraph(const std::shared_ptr<ov::Node>& node) -> s
}

void Subgraph::fill_empty_output_names(const Output<Node>& target_output_node, const Output<Node>& replacement_output_node) {
OPENVINO_SUPPRESS_DEPRECATED_START
auto& out_tensor = target_output_node.get_tensor();
const std::string new_name = ov::op::util::get_ie_output_name(replacement_output_node);
if (ov::descriptor::get_ov_tensor_legacy_name(out_tensor).empty()) {
ov::descriptor::set_ov_tensor_legacy_name(out_tensor, new_name);
}
if (!replacement_output_node.get_names().empty()) {
out_tensor.set_names(replacement_output_node.get_names());
}
OPENVINO_SUPPRESS_DEPRECATED_END
}

auto Subgraph::constant_input_should_be_inside_body(const std::shared_ptr<ov::Node>& node) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ bool ov::pass::UnrollIf::run_on_model(const std::shared_ptr<ov::Model>& f) {
}
for (const auto& output_desc : output_descriptions) {
std::shared_ptr<ov::op::v0::Result> result = body->get_results()[output_desc->m_body_value_index];
const auto& in_value = result->input_value(0);

// set output name to Tensor to store it for openvino to cnn conversion
OPENVINO_SUPPRESS_DEPRECATED_START
ov::descriptor::set_ov_tensor_legacy_name(
in_value.get_tensor(),
op::util::create_ie_output_name(if_node->output(output_desc->m_output_index)));
OPENVINO_SUPPRESS_DEPRECATED_END
for (const auto& input : if_node->output(output_desc->m_output_index).get_target_inputs()) {
input.replace_source_output(result->get_input_source_output(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Mode
std::any_of(target_inputs.begin(), target_inputs.end(), [](const ov::Input<ov::Node>& target_inp) {
return ov::as_type<ov::op::v0::Result>(target_inp.get_node()) != nullptr;
})) {
OPENVINO_SUPPRESS_DEPRECATED_START
ov::descriptor::set_ov_tensor_legacy_name(insert_to.get_tensor(),
ov::op::util::create_ie_output_name(ti_output));
OPENVINO_SUPPRESS_DEPRECATED_END
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ pass::ConvertMaxPool8ToMaxPool1::ConvertMaxPool8ToMaxPool1() {
maxpool_v8_node->get_rounding_type(),
maxpool_v8_node->get_auto_pad());

OPENVINO_SUPPRESS_DEPRECATED_START
auto out_name = ov::op::util::create_ie_output_name(maxpool_v8_node->output(0));
OPENVINO_SUPPRESS_DEPRECATED_END

maxpool_v1_node->set_friendly_name(maxpool_v8_node->get_friendly_name());
maxpool_v8_node->output(0).replace(maxpool_v1_node->output(0));
ov::copy_runtime_info(maxpool_v8_node, maxpool_v1_node);
maxpool_v8_node->clear_control_dependencies();

OPENVINO_SUPPRESS_DEPRECATED_START
ov::descriptor::set_ov_tensor_legacy_name(maxpool_v1_node->output(0).get_tensor(), out_name);
OPENVINO_SUPPRESS_DEPRECATED_END

return true;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {
Output<Node> output_0 = nms_legacy->output(0);
if (nms_9->output(0).get_element_type() != output_0.get_element_type()) {
output_0 = std::make_shared<ov::op::v0::Convert>(output_0, nms_9->output(0).get_element_type());
OPENVINO_SUPPRESS_DEPRECATED_START
output_0.get_node_shared_ptr()->set_friendly_name(op::util::create_ie_output_name(nms_9->output(0)));
OPENVINO_SUPPRESS_DEPRECATED_END
new_ops.emplace_back(output_0.get_node_shared_ptr());
}

Output<Node> output_2 = nms_legacy->output(2);
if (nms_9->output(2).get_element_type() != output_2.get_element_type()) {
output_2 = std::make_shared<ov::op::v0::Convert>(output_2, nms_9->output(2).get_element_type());
OPENVINO_SUPPRESS_DEPRECATED_START
output_2.get_node_shared_ptr()->set_friendly_name(op::util::create_ie_output_name(nms_9->output(2)));
OPENVINO_SUPPRESS_DEPRECATED_END
new_ops.emplace_back(output_2.get_node_shared_ptr());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,6 @@
using namespace testing;
using namespace ov;

TEST_F(TransformationTestsF, ConvertNMS1ToNMSIEInternal) {
{
auto boxes = std::make_shared<opset1::Parameter>(element::f32, Shape{1, 1000, 4});
auto scores = std::make_shared<opset1::Parameter>(element::f32, Shape{1, 1, 1000});
auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{}, {10});
auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75});
auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7});
auto nms = std::make_shared<opset1::NonMaxSuppression>(boxes,
scores,
max_output_boxes_per_class,
iou_threshold,
score_threshold,
op::v1::NonMaxSuppression::BoxEncodingType::CORNER,
true);

model = std::make_shared<Model>(NodeVector{nms}, ParameterVector{boxes, scores});

manager.register_pass<ov::pass::ConvertNMS1ToNMS5>();
manager.register_pass<ov::pass::ConvertNMSToNMSIEInternal>();
manager.register_pass<pass::ConstantFolding>();

// as inside test infrastructure we can not predict output names for given Model
// we have to enable soft names comparison manually
enable_soft_names_comparison();
}

{
auto boxes = std::make_shared<opset1::Parameter>(element::f32, Shape{1, 1000, 4});
auto scores = std::make_shared<opset1::Parameter>(element::f32, Shape{1, 1, 1000});
auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{1}, {10});
auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75});
auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7});
auto nms = std::make_shared<ov::op::internal::NonMaxSuppressionIEInternal>(boxes,
scores,
max_output_boxes_per_class,
iou_threshold,
score_threshold,
0,
true,
element::i32);
auto convert = std::make_shared<opset1::Convert>(nms->output(0), element::i64);

model_ref = std::make_shared<Model>(NodeVector{convert}, ParameterVector{boxes, scores});
}
}

TEST_F(TransformationTestsF, ConvertNMS3ToNMSIEInternal) {
{
auto boxes = std::make_shared<opset1::Parameter>(element::f32, Shape{1, 1000, 4});
Expand Down

0 comments on commit 85eb7ee

Please sign in to comment.