masahi commented on issue #4497: [WIP] [Relay] Add a PyTorch to Relay Parser
URL: https://github.com/apache/incubator-tvm/pull/4497#issuecomment-578365956
 
 
   @alexwong I had a big success in refactoring, the parser itself (except op 
conversion) is about 150 lines and the "main loop" is just:
   
   ```
       parse_inputs()
       parse_params()
       parse_ops()
   
       outputs = []
       for k, v in {**inputs_r, **params}.items():
           node_name_to_nid[k] = len(outputs)
           outputs.append(v)
   
       for node_name, op_node in ops.items():
           operator = op_node.kind()
           if operator == 'prim::ListConstruct':
               nid = node_name_to_nid[node_name]
               outputs.append(outputs[nid])
           elif operator == "prim::Constant":
               node_name_to_nid[node_name] = len(outputs)
               outputs.append(consts[node_name])
           else:
               node_name_to_nid[node_name] = len(outputs)
               op_inputs = []
               for ind, i in enumerate(op_node.inputs()):
                   inode_name = node_name_to_nid[i.debugName()]
                   op_inputs.append(outputs[inode_name])
   
               call = convert_map[operator](op_inputs,
                                            op_inputs_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 merge this after you fixed the CI issue. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to