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

[Relay] Add a non-recursive LetNode VisitExpr_ for LabelOps Pass to avoid stack overflow #8917

Merged
merged 5 commits into from
Sep 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/relay/transforms/label_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ class LabelOpsMutator : public MixedModeMutator {
}
return std::move(f);
}
Expr VisitExpr_(const LetNode* op) final {
auto pre_visit = [this](const LetNode* op) {
this->Mutate(op->var);
this->Mutate(op->value);
};
auto post_visit = [this](const LetNode* op) {
Var var = Downcast<Var>(this->Mutate(op->var));
auto value = this->Mutate(op->value);
auto body = this->Mutate(op->body);
auto expr = GetRef<Expr>(op);
if (var.same_as(op->var) && value.same_as(op->value) && body.same_as(op->body)) {
this->memo_[expr] = expr;
} else {
this->memo_[expr] = Let(var, value, body);
}
};
ExpandANormalForm(op, pre_visit, post_visit);
return memo_[GetRef<Expr>(op)];
}

Expr Rewrite_(const CallNode* op, const Expr& post) final {
auto updated = MixedModeMutator::Rewrite_(op, post);
Expand Down