[Torch] fix unordered dictionary problem for python version under 3.6 (#4982)
authorpyjhzwh <pyjhzwh@gmail.com>
Wed, 4 Mar 2020 09:40:37 +0000 (04:40 -0500)
committerGitHub <noreply@github.com>
Wed, 4 Mar 2020 09:40:37 +0000 (18:40 +0900)
* fix unordered dictionary problem for python version 3.5

* modify style

python/tvm/relay/frontend/pytorch.py

index b256faa..19bccca 100644 (file)
@@ -918,7 +918,7 @@ def _get_constant(node):
 
 def _get_operator_nodes(nodes):
     """ Returns torch IR nodes that need conversion to Relay """
-    ops = {}
+    ops = []
     # Traverse nodes and add to graph
     for node in nodes:
         if node.outputsSize() > 1:
@@ -927,7 +927,7 @@ def _get_operator_nodes(nodes):
             node_name = _get_output_name(node)
 
         if node.kind() != "prim::GetAttr":
-            ops[node_name] = node
+            ops.append((node_name, node))
 
     return ops
 
@@ -1015,7 +1015,7 @@ def parse_params(graph, state_dict):
 
 def parse_operators(operators, outputs, output_index_map, ret_name):
     """ Convert each Torch IR operators to Relay equivalent """
-    for node_name, op_node in operators.items():
+    for node_name, op_node in operators:
         operator = op_node.kind()
         inputs = _get_op_inputs(op_node, outputs, output_index_map)