Skip to content

[Relay] WithFields method for Call, Function, Var, TupleGetItem, If, Let, RefCreate, RefRead, RefWrite, Match, and Clause#9569

Merged
manupak merged 2 commits into
apache:mainfrom
electriclilies:with_fields
Nov 25, 2021
Merged

[Relay] WithFields method for Call, Function, Var, TupleGetItem, If, Let, RefCreate, RefRead, RefWrite, Match, and Clause#9569
manupak merged 2 commits into
apache:mainfrom
electriclilies:with_fields

Conversation

@electriclilies

Copy link
Copy Markdown
Contributor

In this PR, I implement the WithFields method for Call, Function, Var, TupleGetItem, If, Let, RefCreate, RefRead, RefWrite, Match and Clause. It is a continuation of work in #9533, where I implement WithFields for Tuples.
Additionally, I remove the explicit COW logic from the visitors in expr_functor.cc for these classes. In future work, I'll use these methods to replace most explicit reconstructions of these classes in visitors.
@mbs-octoml @mikepapadim PTAL! I would especially appreciate typo checks in the documentation, I did a lot of copy-pasting and probably missed some things there.
cc @tqchen in case you are interested -- I've kept the API consistent with what we discussed for WithFields for tuples

@mikepapadim mikepapadim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, maybe add a cpp tests for new Clause.

}
// Note: The partial evaluator seems to do some weird stuff with sharing. Changing Tuple(expr)
// to WithFields(op, expr) causes some strange failures.
return HasStatic(MkSTuple(value), ll->Push(Tuple(expr)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we get capture these failures with some unit-test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was seeing some failures in the partial evaluator tests, but also in other places. I'll update the comment to clarify, I don't think I need to add another unittest here though

Comment thread src/relay/ir/expr.cc Outdated
Expr tuple = opt_tuple.value_or(tuple_get_item->tuple);
int index =
opt_index.value_or(tuple_get_item->index)
->value; // Is it OK that this is an Integer instead of int? this lets me use Optional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think Integer is fine here. Still need this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nice catch, thanks!

@mbs-octoml mbs-octoml left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Look great, thank you.

For bonus points you could replace the explicit ctors in device_planner.cc with WithField.

Comment thread include/tvm/relay/expr.h Outdated
Optional<Array<Expr>> opt_args = Optional<Array<Expr>>(),
Optional<Attrs> opt_attrs = Optional<Attrs>(),
Optional<Array<Type>> opt_type_args = Optional<Array<Type>>(),
Optional<Span> opt_span = Optional<Span>(nullptr));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't need the nullptr arg apparently

@jroesch jroesch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look great, thanks Lily! Just minor question about moving const references.

return Clause(pat, VisitExpr(c->rhs));
Clause VisitClause(const Clause& clause) final {
Pattern lhs = VisitPattern(clause->lhs);
return WithFields(std::move(clause), std::move(lhs), VisitExpr(clause->rhs));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mbs-octoml I don't know if we actually need these moves, for const reference does this matter? I can't actually remember what the spec says about value vs move semantics for const &.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, didn't even notice it was const. I was just std::moving everything that was named that we were not using again

@electriclilies

electriclilies commented Nov 24, 2021

Copy link
Copy Markdown
Contributor Author

@mbs-octoml Changed the explicit constructions in the device planner to copy except for one Tuple, since I don't have WithFields for tuples in this PR (waiting on #9533).

@electriclilies

Copy link
Copy Markdown
Contributor Author

@Mousius or @manupa-arm could you merge? It’s a holiday weekend here and I’d like to get this in before there are any merge conflicts. Thanks!

@manupak manupak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Getting this in for now.
Lets follow up if needed

@manupak manupak merged commit 8ca8e38 into apache:main Nov 25, 2021
dchauhan-arm pushed a commit to dchauhan-arm/tvm that referenced this pull request Nov 29, 2021
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 12, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants