From 4835beae45bb3d8d5d00feb9df035792aa4d58ba Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Thu, 20 May 2021 13:44:06 +0300 Subject: [PATCH] Make order of port names determined in IR (#5701) * Make order of port names determined in IR Signed-off-by: Roman Kazantsev * Make port names in determined order and adopted tests Signed-off-by: Roman Kazantsev --- model-optimizer/mo/graph/port.py | 2 +- .../unit_tests/mo/graph/port_test.py | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/model-optimizer/mo/graph/port.py b/model-optimizer/mo/graph/port.py index c4859087f45447..9a5132e387c909 100644 --- a/model-optimizer/mo/graph/port.py +++ b/model-optimizer/mo/graph/port.py @@ -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': diff --git a/model-optimizer/unit_tests/mo/graph/port_test.py b/model-optimizer/unit_tests/mo/graph/port_test.py index 1b8f9d83ba407d..005b7b46e1640b 100644 --- a/model-optimizer/unit_tests/mo/graph/port_test.py +++ b/model-optimizer/unit_tests/mo/graph/port_test.py @@ -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) @@ -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) @@ -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) @@ -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'), @@ -79,26 +79,26 @@ 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}), @@ -106,13 +106,13 @@ def test_reconnect_middle_case2(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']) class TestPortMethods(unittest.TestCase):