Fix of tensor names loosing for cf=True flag in MOC transformations. (#19014)
* Added shape and type infer for result nodes in MOC transformations. * Clang format. * Added validate_nodes_and_infer_types() pass at the end of MOC pipeline. * Clang format. * Added test. * Clang format.
This commit is contained in:
parent
2bdb7bd23e
commit
6bf75f569c
@ -255,8 +255,8 @@ bool ov::pass::MOCTransformations::run_on_model(const std::shared_ptr<ngraph::Fu
|
||||
for (auto&& param : f->get_parameters()) {
|
||||
param->set_partial_shape(input_shapes.at(param.get()));
|
||||
}
|
||||
f->validate_nodes_and_infer_types();
|
||||
}
|
||||
f->validate_nodes_and_infer_types();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <transformations/common_optimizations/moc_transformations.hpp>
|
||||
|
||||
#include "openvino/core/model.hpp"
|
||||
#include "openvino/opsets/opset12.hpp"
|
||||
#include "openvino/pass/manager.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace ov;
|
||||
using namespace ov::opset12;
|
||||
|
||||
TEST(TransformationTests, TestModelTensorsConsistencyUseShapesTrue) {
|
||||
auto input = std::make_shared<opset12::Parameter>(element::f32, Shape{1});
|
||||
auto const1 = opset12::Constant::create(element::f32, Shape{1}, {1});
|
||||
auto const2 = opset12::Constant::create(element::f32, Shape{1}, {2});
|
||||
auto const3 = opset12::Constant::create(element::f32, Shape{1}, {3});
|
||||
auto add1 = std::make_shared<opset12::Add>(input, const1);
|
||||
auto add2 = std::make_shared<opset12::Add>(add1, const2);
|
||||
auto add3 = std::make_shared<opset12::Add>(add2, const3);
|
||||
|
||||
auto model = std::make_shared<Model>(NodeVector{add3}, ParameterVector{input});
|
||||
ov::pass::Manager m;
|
||||
m.register_pass<ov::pass::MOCTransformations>(true);
|
||||
m.run_passes(model);
|
||||
|
||||
std::unordered_set<std::string> new_tensors = {"new_name"};
|
||||
model->outputs()[0].set_names(new_tensors);
|
||||
EXPECT_TRUE(model->outputs()[0].get_names() == new_tensors);
|
||||
|
||||
model->validate_nodes_and_infer_types();
|
||||
EXPECT_TRUE(model->outputs()[0].get_names() == new_tensors);
|
||||
}
|
||||
|
||||
TEST(TransformationTests, TestModelTensorsConsistencyUseShapesFalse) {
|
||||
auto input = std::make_shared<opset12::Parameter>(element::f32, Shape{1});
|
||||
auto const1 = opset12::Constant::create(element::f32, Shape{1}, {1});
|
||||
auto const2 = opset12::Constant::create(element::f32, Shape{1}, {2});
|
||||
auto const3 = opset12::Constant::create(element::f32, Shape{1}, {3});
|
||||
auto add1 = std::make_shared<opset12::Add>(input, const1);
|
||||
auto add2 = std::make_shared<opset12::Add>(add1, const2);
|
||||
auto add3 = std::make_shared<opset12::Add>(add2, const3);
|
||||
|
||||
auto model = std::make_shared<Model>(NodeVector{add3}, ParameterVector{input});
|
||||
ov::pass::Manager m;
|
||||
m.register_pass<ov::pass::MOCTransformations>(false);
|
||||
m.run_passes(model);
|
||||
|
||||
std::unordered_set<std::string> new_tensors = {"new_name"};
|
||||
model->outputs()[0].set_names(new_tensors);
|
||||
EXPECT_TRUE(model->outputs()[0].get_names() == new_tensors);
|
||||
|
||||
model->validate_nodes_and_infer_types();
|
||||
EXPECT_TRUE(model->outputs()[0].get_names() == new_tensors);
|
||||
}
|
@ -903,6 +903,38 @@ class TestMoConvertTF(CommonMOConvertTest):
|
||||
assert CommonLayerTest().compare_ie_results_with_framework(ov_infer2, {"add:0": fw_infer2}, eps)
|
||||
assert CommonLayerTest().compare_ie_results_with_framework(ov_infer1, {"add:0": [2.6, 9.6, 12.4]}, eps)
|
||||
|
||||
def test_tensor_names(self, ie_device, precision, ir_version, temp_dir):
|
||||
import tensorflow as tf
|
||||
class LayerModel(tf.Module):
|
||||
def __init__(self):
|
||||
super(LayerModel, self).__init__()
|
||||
self.var1 = tf.Variable([7., 5., 6.], name='var1')
|
||||
self.var2 = tf.Variable([5., 7., 3.], name='var2')
|
||||
self.var3 = tf.Variable([5., 7., 3.], name='var2')
|
||||
|
||||
|
||||
@tf.function
|
||||
def sub_function(self, input):
|
||||
return input + self.var1 + self.var2 + self.var3
|
||||
|
||||
@tf.function()
|
||||
def __call__(self, input):
|
||||
return self.sub_function(input)
|
||||
|
||||
from openvino.tools.ovc import convert_model
|
||||
model = LayerModel()
|
||||
ov_model = convert_model(model)
|
||||
|
||||
ov_model.outputs[0].get_tensor().set_names({"name1"})
|
||||
assert ov_model.outputs[0].names == {"name1"}
|
||||
|
||||
ov_model.validate_nodes_and_infer_types()
|
||||
assert ov_model.outputs[0].names == {"name1"}
|
||||
|
||||
ov_model.outputs[0].get_tensor().set_names({"name2"})
|
||||
assert ov_model.outputs[0].names == {"name2"}
|
||||
|
||||
|
||||
|
||||
class TFConvertTest(unittest.TestCase):
|
||||
@pytest.mark.nightly
|
||||
|
Loading…
Reference in New Issue
Block a user