samskalicky commented on a change in pull request #16131: Fix for duplicate subgraph inputs/outputs URL: https://github.com/apache/incubator-mxnet/pull/16131#discussion_r324948919
########## File path: src/operator/subgraph/subgraph_property.h ########## @@ -296,8 +296,20 @@ class SubgraphProperty { */ virtual void ConnectSubgraphOutputs(const nnvm::NodePtr subgraph_node, std::vector<nnvm::NodeEntry*>* output_entries) const { + // Collapse output_entries pointing to same NodeEntry Review comment: @ZhennanQin Would you approve changing the connectSubgraphOutputs API to pass in a map instead for output_entries? Then it will simplify the implementation of connectSubgraphOutputs and help backend developers avoid making bugs by having to dedupe in this weird way. @HahTK and I are willing to make this change. Heres what we propose: Change FindOutputEntries to populate a map<int, vector<nodeentry*> > instead of the vector<nodeentry*>. The integer refers to the i'th output of the subgraph, and nodeentry pointer is the same as it is in output_entries. The job of connectSubgraphOutputs is to connect all nodeentries in the vector to that indexed output of the subgraph. Then in CreateSubgraphNode (in build_subgraph.cc) the code will look like: ``` nnvm::Symbol sym; size_t idx = 0; sym.outputs.resize(output_map.size()); for (size_t i = 0; i < output_map.size(); ++i) { sym.outputs[i] = *output_map[i][0]; } ``` And ConnectSubgraphOutputs will take the output_map and do: ``` for (size_t i = 0; i < output_map->size(); ++i) { for(auto e : output_map[i]) { *e = nnvm::NodeEntry{subgraph_node, static_cast<uint32_t>(i), 0}; } } ``` This vastly simplifies/clarifies the code backend devs need to write. And helps avoid confusion and prevents bugs. ---------------------------------------------------------------- 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