Skip to content

Commit

Permalink
Make order of port names determined in IR (openvinotoolkit#5701)
Browse files Browse the repository at this point in the history
* Make order of port names determined in IR

Signed-off-by: Roman Kazantsev <[email protected]>

* Make port names in determined order and adopted tests

Signed-off-by: Roman Kazantsev <[email protected]>
  • Loading branch information
rkazants authored and rnugmanx committed Aug 26, 2021
1 parent d9862ba commit 4835bea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion model-optimizer/mo/graph/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_tensor_names_list(attrs):
if node_idx in self.node.out_nodes():
out_node = self.node.out_node(node_idx)
fw_names += get_tensor_names_list(out_node.attrs())
return fw_names
return sorted(fw_names)

def disconnect(self):
if self.type == 'out':
Expand Down
22 changes: 11 additions & 11 deletions model-optimizer/unit_tests/mo/graph/port_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_front(self):
('Op1', 'Op1,Op2')]})])
graph.stage = 'front'
input_node = Node(graph, 'input')
self.assertTrue(input_node.out_port(0).get_tensor_names() == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node.out_port(0).get_tensor_names() == ['Op1\\,Op2', 'input'])

op1_node = Node(graph, 'Op1')
op1_node.add_output_port(0)
Expand All @@ -37,7 +37,7 @@ def test_middle(self):
('input_data', 'Op2')])

input_node = Node(graph, 'input')
self.assertTrue(input_node.out_port(0).get_tensor_names() == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node.out_port(0).get_tensor_names() == ['Op1\\,Op2', 'input'])

op1_node = Node(graph, 'Op1')
op1_node.add_output_port(0)
Expand All @@ -51,7 +51,7 @@ def test_port_renumber(self):
graph = build_graph(nodes, [('input', 'input_data'), ('input_data', 'Op1'),
('Op1', 'Op1_data', {'out': 1}), ('Op1_data', 'Op2')])
input_node = Node(graph, 'input')
self.assertTrue(input_node.out_port(0).get_tensor_names(port_renumber=True) == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node.out_port(0).get_tensor_names(port_renumber=True) == ['Op1\\,Op2', 'input'])

op1_node = Node(graph, 'Op1')
op1_node.add_output_port(0)
Expand All @@ -63,13 +63,13 @@ def test_reconnect_middle_case1(self):
input_node = Node(graph, 'input')

input_node_out_port = input_node.out_port(0)
self.assertTrue(input_node_out_port.get_tensor_names() == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node_out_port.get_tensor_names() == ['Op1\\,Op2', 'input'])

op3_node = Node(graph, 'Op3')
input_node_out_port.get_connection().set_source(op3_node.out_port(0))

self.assertTrue(input_node_out_port.get_tensor_names() is None)
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op3', 'input', 'Op1\\,Op2'])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op1\\,Op2', 'Op3', 'input'])

def test_reconnect_front_case1(self):
graph = build_graph(nodes, [('input', 'Op1', {'in': 0, 'out': 0, 'fw_tensor_debug_info': [('input', 'input'),
Expand All @@ -79,40 +79,40 @@ def test_reconnect_front_case1(self):
input_node = Node(graph, 'input')

input_node_out_port = input_node.out_port(0)
self.assertTrue(input_node_out_port.get_tensor_names() == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node_out_port.get_tensor_names() == ['Op1\\,Op2', 'input'])

op3_node = Node(graph, 'Op3')
input_node_out_port.get_connection().set_source(op3_node.out_port(0))

self.assertTrue(input_node_out_port.get_tensor_names() == [])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op3', 'input', 'Op1\\,Op2'])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op1\\,Op2', 'Op3', 'input'])

def test_reconnect_middle_case1(self):
graph = build_graph(nodes, [('input', 'input_data'), ('input_data', 'Op1'), ('Op3', 'Op3_data')])
input_node = Node(graph, 'input')

input_node_out_port = input_node.out_port(0)
self.assertTrue(input_node_out_port.get_tensor_names() == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node_out_port.get_tensor_names() == ['Op1\\,Op2', 'input'])

op3_node = Node(graph, 'Op3')
input_node_out_port.get_connection().set_source(op3_node.out_port(0))

self.assertTrue(input_node_out_port.get_tensor_names() == [])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op3', 'input', 'Op1\\,Op2'])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op1\\,Op2', 'Op3', 'input'])

def test_reconnect_middle_case2(self):
graph = build_graph(nodes, [('input', 'input_data'), ('input_data', 'Op1', {'out': 0}),
('input_data', 'Op1', {'out': 1}), ('Op3', 'Op3_data')])
input_node = Node(graph, 'input')

input_node_out_port = input_node.out_port(0)
self.assertTrue(input_node_out_port.get_tensor_names() == ['input', 'Op1\\,Op2'])
self.assertTrue(input_node_out_port.get_tensor_names() == ['Op1\\,Op2', 'input'])

op3_node = Node(graph, 'Op3')
input_node_out_port.get_connection().set_source(op3_node.out_port(0))

self.assertTrue(input_node_out_port.get_tensor_names() == [])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op3', 'input', 'Op1\\,Op2'])
self.assertTrue(op3_node.out_port(0).get_tensor_names() == ['Op1\\,Op2', 'Op3', 'input'])


class TestPortMethods(unittest.TestCase):
Expand Down

0 comments on commit 4835bea

Please sign in to comment.