88#include " openvino/opsets/opset8.hpp"
99#include " openvino/pass/manager.hpp"
1010
11+ using namespace ov ;
12+ using namespace ov ::opset8;
13+
1114TEST (ResolveNameCollisionsTest, FixGeneratedNames) {
12- auto arg0 = std::make_shared<ov::opset8:: Parameter>(ov::element::f32 , ov::PartialShape{1 , 3 , 3 , 3 });
15+ auto arg0 = std::make_shared<Parameter>(ov::element::f32 , ov::PartialShape{1 , 3 , 3 , 3 });
1316 const auto gen_friendly_name = arg0->get_friendly_name ();
1417
1518 std::string name = " Parameter_" ;
@@ -19,10 +22,10 @@ TEST(ResolveNameCollisionsTest, FixGeneratedNames) {
1922
2023 arg0->set_friendly_name (name);
2124
22- auto arg1 = std::make_shared<ov::opset8:: Parameter>(ov::element::f32 , ov::PartialShape{1 , 2 , 3 , 3 });
25+ auto arg1 = std::make_shared<Parameter>(ov::element::f32 , ov::PartialShape{1 , 2 , 3 , 3 });
2326
24- auto concat = std::make_shared<ov::opset8:: Concat>(ov::NodeVector{arg0, arg1}, 1 );
25- auto result1 = std::make_shared<ov::opset8:: Result>(concat);
27+ auto concat = std::make_shared<Concat>(ov::NodeVector{arg0, arg1}, 1 );
28+ auto result1 = std::make_shared<Result>(concat);
2629
2730 auto model = std::make_shared<ov::Model>(ov::ResultVector{result1}, ov::ParameterVector{arg0, arg1});
2831
@@ -38,50 +41,102 @@ TEST(ResolveNameCollisionsTest, FixGeneratedNames) {
3841 EXPECT_EQ (arg1->get_friendly_name (), arg0->get_friendly_name () + " _2" );
3942}
4043
41- TEST (ResolveNameCollisionsTest, DoNotFixFriendlyNamesForParameters ) {
42- auto arg0 = std::make_shared<ov::opset8:: Parameter>(ov::element::f32 , ov::PartialShape{1 , 3 , 3 , 3 });
44+ TEST (ResolveNameCollisionsTest, FixFriendlyNamesForAutogeneratedNames ) {
45+ auto arg0 = std::make_shared<Parameter>(ov::element::f32 , ov::PartialShape{1 , 3 , 3 , 3 });
4346 const auto gen_friendly_name = arg0->get_friendly_name ();
4447
45- arg0->set_friendly_name (gen_friendly_name);
46-
47- auto arg1 = std::make_shared<ov::opset8::Parameter>(ov::element::f32 , ov::PartialShape{1 , 2 , 3 , 3 });
48+ auto arg1 = std::make_shared<Parameter>(ov::element::f32 , ov::PartialShape{1 , 2 , 3 , 3 });
49+ // set the same name as for the first Parameter
4850 arg1->set_friendly_name (gen_friendly_name);
4951
50- auto concat = std::make_shared<ov::opset8::Concat>(ov::NodeVector{arg0, arg1}, 1 );
51- auto result1 = std::make_shared<ov::opset8::Result>(concat);
52+ auto concat1 = std::make_shared<Concat>(ov::NodeVector{arg0, arg1}, 1 );
53+ concat1->set_friendly_name (" concat" );
54+ auto concat = std::make_shared<Concat>(ov::NodeVector{concat1, arg1}, 1 );
55+ concat->set_friendly_name (" concat" );
56+
57+ auto result1 = std::make_shared<Result>(concat);
5258
5359 auto model = std::make_shared<ov::Model>(ov::ResultVector{result1}, ov::ParameterVector{arg0, arg1});
5460
55- EXPECT_EQ (gen_friendly_name, arg0->get_friendly_name ());
56- EXPECT_EQ (arg1->get_friendly_name (), arg0->get_friendly_name ());
57- EXPECT_NE (arg1->get_friendly_name (), arg0->get_friendly_name () + " _2" );
61+ EXPECT_EQ (concat->get_friendly_name (), concat1->get_friendly_name ());
5862
5963 ov::pass::Manager pass_manager;
6064 pass_manager.register_pass <ov::pass::ResolveNameCollisions>();
6165 pass_manager.run_passes (model);
62- EXPECT_EQ (gen_friendly_name, arg0->get_friendly_name ());
63- EXPECT_EQ (arg1->get_friendly_name (), arg0->get_friendly_name ());
64- EXPECT_NE (arg1->get_friendly_name (), arg0->get_friendly_name () + " _2" );
65- }
66-
67- TEST (ResolveNameCollisionsTest, FixFriendlyNamesForInternalOperations) {
68- auto arg0 = std::make_shared<ov::opset8::Parameter>(ov::element::f32 , ov::PartialShape{1 , 3 , 3 , 3 });
69- const auto gen_friendly_name = arg0->get_friendly_name ();
70-
71- auto arg1 = std::make_shared<ov::opset8::Parameter>(ov::element::f32 , ov::PartialShape{1 , 2 , 3 , 3 });
72-
73- auto concat1 = std::make_shared<ov::opset8::Concat>(ov::NodeVector{arg0, arg1}, 1 );
74- concat1->set_friendly_name (" concat" );
75- auto concat = std::make_shared<ov::opset8::Concat>(ov::NodeVector{concat1, arg1}, 1 );
76- concat->set_friendly_name (" concat" );
77- auto result1 = std::make_shared<ov::opset8::Result>(concat);
78-
79- auto model = std::make_shared<ov::Model>(ov::ResultVector{result1}, ov::ParameterVector{arg0, arg1});
8066
67+ // these names weren't set automatically, and have to remain the same.
8168 EXPECT_EQ (concat->get_friendly_name (), concat1->get_friendly_name ());
69+ // arg0's name was set automatically and matches with another name in the graph,
70+ // so it have to be changed.
71+ EXPECT_NE (arg0->get_friendly_name (), arg1->get_friendly_name ());
72+ EXPECT_EQ (arg0->get_friendly_name (), arg1->get_friendly_name () + " _2" );
73+ }
74+
75+ TEST (ResolveNameCollisionsTest, FixFriendlyNamesForAutogeneratedNamesMultiSubgraphOp) {
76+ // external params
77+ auto X = std::make_shared<Parameter>(element::f32 , Shape{4 });
78+ auto Y = std::make_shared<Parameter>(element::f32 , Shape{4 });
79+ auto Z = std::make_shared<Parameter>(element::f32 , Shape{8 });
80+
81+ auto axis = std::make_shared<Constant>(element::i32 , Shape{}, 0 );
82+ auto external_split = std::make_shared<Split>(X, axis, 2 );
83+
84+ // internal params
85+ auto Xt = std::make_shared<Parameter>(element::f32 , PartialShape::dynamic ());
86+ Xt->set_friendly_name (X->get_friendly_name ());
87+ auto Yt = std::make_shared<Parameter>(element::f32 , PartialShape::dynamic ());
88+ Yt->set_friendly_name (Y->get_friendly_name ());
89+ auto Ze = std::make_shared<Parameter>(element::f32 , PartialShape::dynamic ());
90+
91+ // then body
92+ auto cond = std::make_shared<Constant>(element::boolean, Shape{1 }, true );
93+ auto axis_then = std::make_shared<Constant>(element::i32 , Shape{}, 0 );
94+ auto split_y = std::make_shared<Split>(Yt, axis_then, 2 );
95+ split_y->set_friendly_name (external_split->get_friendly_name ());
96+ auto then_op = std::make_shared<Subtract>(Xt, split_y->output (0 ));
97+ auto res0 = std::make_shared<Result>(then_op);
98+
99+ // else body
100+ auto axis_else = std::make_shared<Constant>(element::i32 , Shape{}, 0 );
101+ auto split_z = std::make_shared<Split>(Ze, axis_else, 4 );
102+ split_z->set_friendly_name (external_split->get_friendly_name ());
103+ auto else_op = std::make_shared<Relu>(split_z);
104+ else_op->set_friendly_name (then_op->get_friendly_name ());
105+ auto res1 = std::make_shared<Result>(else_op);
106+
107+ // If set up
108+ auto then_body = std::make_shared<ov::Model>(OutputVector{res0}, ParameterVector{Yt, Xt}, " then_body" );
109+ auto else_body = std::make_shared<ov::Model>(OutputVector{res1}, ParameterVector{Ze}, " else_body" );
110+ auto if_op = std::make_shared<op::v8::If>(cond);
111+ if_op->set_then_body (then_body);
112+ if_op->set_else_body (else_body);
113+ if_op->set_input (external_split->output (0 ), Xt, nullptr );
114+ if_op->set_input (Y, Yt, nullptr );
115+ if_op->set_input (Z, nullptr , Ze);
116+ auto result = if_op->set_output (res0, res1);
117+
118+ auto res = std::make_shared<Result>(result);
119+ auto model = std::make_shared<Model>(OutputVector{res}, ParameterVector{X, Y, Z});
120+
121+ EXPECT_EQ (external_split->get_friendly_name (), split_y->get_friendly_name ());
122+ EXPECT_EQ (external_split->get_friendly_name (), split_z->get_friendly_name ());
123+
124+ EXPECT_EQ (X->get_friendly_name (), Xt->get_friendly_name ());
125+ EXPECT_EQ (Y->get_friendly_name (), Yt->get_friendly_name ());
126+
127+ EXPECT_EQ (then_op->get_friendly_name (), else_op->get_friendly_name ());
82128
83129 ov::pass::Manager pass_manager;
84130 pass_manager.register_pass <ov::pass::ResolveNameCollisions>();
85131 pass_manager.run_passes (model);
86- EXPECT_NE (concat->get_friendly_name (), concat1->get_friendly_name ());
132+
133+ EXPECT_EQ (external_split->get_friendly_name (), split_y->get_friendly_name () + " _2" );
134+
135+ EXPECT_EQ (X->get_friendly_name (), Xt->get_friendly_name () + " _2" );
136+ EXPECT_EQ (Y->get_friendly_name (), Yt->get_friendly_name () + " _2" );
137+
138+ EXPECT_EQ (then_op->get_friendly_name (), else_op->get_friendly_name () + " _2" );
139+ // remain the same, because they were set via "set_friendly_name" method
140+ // and are not autogenerated.
141+ EXPECT_EQ (split_y->get_friendly_name (), split_z->get_friendly_name ());
87142}
0 commit comments