Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix recursive let for well formed check #5780

Merged
merged 2 commits into from Jun 17, 2020

Conversation

icemelon
Copy link
Member

Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.

cc @lixiaoquan @jroesch

@icemelon
Copy link
Member Author

@lixiaoquan Could you check if the pr fixes your issue?

@lixiaoquan
Copy link
Contributor

Thanks for fixing this, I found other passes also have similar issue. This is VarVisitor used in FreeVars().

diff --git a/src/relay/analysis/util.cc b/src/relay/analysis/util.cc
index 0885a35df..633c3b065 100644
--- a/src/relay/analysis/util.cc
+++ b/src/relay/analysis/util.cc
@@ -214,9 +214,13 @@ class VarVisitor : protected ExprVisitor, protected PatternVisitor {
   }
 
   void VisitExpr_(const LetNode* op) final {
-    MarkBounded(op->var);
-    VisitExpr(op->value);
-    VisitExpr(op->body);
+    Expr let = GetRef<Let>(op);
+    while (auto let_node = let.as<LetNode>()) {
+      MarkBounded(let_node->var);
+      VisitExpr(let_node->value);
+      let = let_node->body;
+    }
+    VisitExpr(let);
   }
 
   void VisitPattern(const Pattern& p) final { PatternVisitor::VisitPattern(p); }

I also run into stack overflow in DeDup() and ConstantFold(), but I'm not sure whether they are similar issue.

@zhiics
Copy link
Member

zhiics commented Jun 12, 2020

We probably need to port the passes to the non-recursive form.

@icemelon
Copy link
Member Author

Thanks @lixiaoquan. I've applied your patch. For other passes, I agree with @zhiics that we should rewrite them to non-recursive form.

@jroesch
Copy link
Member

jroesch commented Jun 16, 2020

@MarisaKirisame can you check this out.

@MarisaKirisame
Copy link
Contributor

@icemelon9 @lixiaoquan I am missing context. what is this patch trying to solve?

@tqchen tqchen added the status: need test case need test cases to cover the change label Jun 16, 2020
@icemelon
Copy link
Member Author

@MarisaKirisame This is to fix too many recursive visits into the let list that causes the stack overflow.
@tqchen It's not easy to add a test case for this PR unless we want to create a large graph that will cause stack overflow before this PR.

}
CheckWellFormed(let);
while (!scopes.empty()) {
delete scopes.back();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use unique_ptr?

@tqchen tqchen merged commit def496d into apache:master Jun 17, 2020
@tqchen tqchen added status: accepted and removed status: need review status: need test case need test cases to cover the change labels Jun 17, 2020
@icemelon icemelon deleted the well-form-let branch June 17, 2020 20:14
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 30, 2020
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants