Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Remove check for subgraph with cycles
Browse files Browse the repository at this point in the history
Signed-off-by: Serge Panev <[email protected]>
  • Loading branch information
Kh4L committed Jun 25, 2020
1 parent 1bf881f commit 926f5a4
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/operator/subgraph/build_subgraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ bool LabelSubgraph(const nnvm::Graph& g, SubgraphSelectorV2Ptr subgraph_selector
std::stack<const nnvm::Node*> s;
s.push(descendant);
size_t count = 0;
while (!s.empty()) {
CHECK_LT(count, indexed_graph.num_nodes()) << "Finding ancestor failed. There is probably"
" a loop in the graph";
while (!s.empty() && count < indexed_graph.num_nodes()) {
++count;
const nnvm::Node* top = s.top();
s.pop();
Expand Down Expand Up @@ -276,10 +274,6 @@ bool LabelSubgraph(const nnvm::Graph& g, SubgraphSelectorV2Ptr subgraph_selector

if (excluded_node_id != -1) {
CHECK_LT(excluded_node_id, static_cast<int>(simple_nodes.size()));
CHECK_NE(excluded_node_id, static_cast<int>(snid))
<< "A cycle is found in the computational graph between nodes "
<< simple_nodes[excluded_node_id]->node->attrs.name << " and "
<< simple_nodes[snid]->node->attrs.name;
excluded_nodes->insert(simple_nodes[excluded_node_id].get());
ResetNodeLabels(g, simple_nodes, subgraph_nodes);
return false;
Expand All @@ -306,14 +300,19 @@ void PreSelectSubgraphNodes(const nnvm::Graph& g, SubgraphSelectorV2Ptr subgraph
const std::vector<BiDirectedNodePtr>& simple_nodes,
std::vector<BiDirectedNode*>* subgraph_nodes) {
std::unordered_set<const BiDirectedNode*> excluded_nodes;
size_t n_excluded_nodes = 0;
const size_t max_num_retry = simple_nodes.size() * simple_nodes.size();
size_t count = 0;
bool success = false;
while (!success && count < max_num_retry) {
success = LabelSubgraph(g, subgraph_selector, label, snid, simple_nodes, subgraph_nodes,
&excluded_nodes);
if (!success) {
CHECK(!excluded_nodes.empty());
if (excluded_nodes.size() == n_excluded_nodes) {
// no possible subgraph for the current node snid
break;
}
n_excluded_nodes = excluded_nodes.size();
std::string excluded_node_names;
for (auto node : excluded_nodes) {
excluded_node_names += node->node->attrs.name + ", ";
Expand Down

0 comments on commit 926f5a4

Please sign in to comment.