mseth10 commented on a change in pull request #15886: Graph Partition API
URL: https://github.com/apache/incubator-mxnet/pull/15886#discussion_r317783611
##########
File path: src/operator/subgraph/build_subgraph.cc
##########
@@ -572,27 +572,30 @@ void CreateSubgraphNode(nnvm::Graph* g,
}
const SubgraphPropertyPtr& subg_prop =
g->GetAttr<SubgraphPropertyPtr>("subgraph_property");
nnvm::NodePtr n = subg_prop->CreateSubgraphNode(sym, subgraph_selector,
subgraph_id);
-
- // Connect the external nodes to the subgraph node.
- subg_prop->ConnectSubgraphOutputs(n, &output_entries);
- subg_prop->ConnectSubgraphInputs(n, &input_entries, &orig_input_entries);
-
- const auto& indexed_graph = g->indexed_graph();
- for (size_t i = 0; i < n->inputs.size(); ++i) {
- auto& e = n->inputs[i];
- // update entry_top_order_map with newly created orig_input_entries
- auto it = entry_top_order_map->find(input_entries[i]);
- CHECK(it != entry_top_order_map->end());
- entry_top_order_map->emplace(&e, it->second);
- // update input entries' source simple nodes' outputs map
- nnvm::Node* node = e.node.get();
- if (indexed_graph.exist(node)) {
- const auto nid = indexed_graph.node_id(node);
- BiDirectedNode* sn = simple_nodes[nid].get();
- for (BiDirectedNode* dest_node : subgraph_nodes) {
- sn->outputs.erase(dest_node->node);
+ // CreateSubgraphNode returns NULL if subgraph property determines that
subgraph is sub-optimal
+ // In that case, subgraph node is not created and graph is not modified
+ if (n) {
+ // Connect the external nodes to the subgraph node.
+ subg_prop->ConnectSubgraphOutputs(n, &output_entries);
+ subg_prop->ConnectSubgraphInputs(n, &input_entries, &orig_input_entries);
+
+ const auto& indexed_graph = g->indexed_graph();
+ for (size_t i = 0; i < n->inputs.size(); ++i) {
+ auto& e = n->inputs[i];
+ // update entry_top_order_map with newly created orig_input_entries
+ auto it = entry_top_order_map->find(input_entries[i]);
+ CHECK(it != entry_top_order_map->end());
+ entry_top_order_map->emplace(&e, it->second);
+ // update input entries' source simple nodes' outputs map
+ nnvm::Node* node = e.node.get();
+ if (indexed_graph.exist(node)) {
+ const auto nid = indexed_graph.node_id(node);
+ BiDirectedNode* sn = simple_nodes[nid].get();
+ for (BiDirectedNode* dest_node : subgraph_nodes) {
+ sn->outputs.erase(dest_node->node);
+ }
+ sn->outputs[n.get()].push_back(i);
}
- sn->outputs[n.get()].push_back(i);
}
}
#if DEBUG_SUBGRAPH
Review comment:
`output_entries` is set
[here](https://github.com/apache/incubator-mxnet/blob/master/src/operator/subgraph/build_subgraph.cc#L565),
before subgraph node is created. We update `output_entries` if subgraph node
is created. If subgraph node is not created, `output_entries` is not updated
and we print the same values again.
I am adding a log message for whether the node is created and
`output_entries` updated.
----------------------------------------------------------------
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