alexwong commented on issue #4497: [WIP] [Relay] Add a PyTorch to Relay Parser
URL: https://github.com/apache/incubator-tvm/pull/4497#issuecomment-579028784
 
 
   > @alexwong I had a big success in refactoring, the parser itself (except op 
conversion) is about 150 lines and the "main loop" is just:
   > 
   > ```python
   >     def get_op_inputs(op_node, outputs, name_map):
   >         inputs = []
   >         for i in op_node.inputs():
   >             inode_name = name_map[i.debugName()]
   >             inputs.append(outputs[inode_name])
   >         return inputs
   > 
   >     outputs = list(input_vars.values())
   >     node_name_to_nid = dict(zip(input_vars.keys(), range(len(outputs))))
   > 
   >     for node_name, op_node in ops.items():
   >         operator = op_node.kind()
   >         if operator == "prim::Constant":
   >             node_name_to_nid[node_name] = len(outputs)
   >             outputs.append(consts[node_name])
   >         elif operator != 'prim::ListConstruct':
   >             node_name_to_nid[node_name] = len(outputs)
   >             inputs = get_op_inputs(op_node, outputs, node_name_to_nid)
   >             call = convert_map[operator](inputs, op_in_types[node_name])
   >             outputs.append(call)
   > 
   >     body = outputs[-1]
   >     func = tvm.relay.Function(_analysis.free_vars(body), body)
   >     param = {k: tvm.nd.array(v) for k, v in param_tensors.items()}
   > ```
   > 
   > My updated version is 
[here](https://gist.github.com/masahi/7704856919563c4b8a74bf085686b519)
   > 
   > Maybe this is a too much change for you, I'm happy to send my change as a 
follow up after this PR. We can merge this after you fix the CI issue.
   
   It is a lot of feedback but I think I can manage, just have been sidetracked 
with other things that keep pulling me away from this. I'm not sure about today 
but I should be able to work on this tomorrow. I'm all for simpler code though, 
would you prefer I pull in the changes above in this PR or just try and make 
all of the simpler changes to get this merged first?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to