Skip to content

Commit

Permalink
[Relay] Add a non-recursive LetNode VisitExpr_ for LabelOps Pass to a…
Browse files Browse the repository at this point in the history
…void stack overflow (apache#8917)

* Add a non-recursive Let VisitExpr_ for LabelOps

* fake commit to retrigger CI

* fake commit to retrigger the CI

* fix CI issue

* fix CI issue
  • Loading branch information
FrankYzy authored and ylc committed Sep 29, 2021
1 parent 584d054 commit 3b193b7
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit 3b193b7

Please sign in to comment.