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] Reference #2489

Merged
merged 3 commits into from
Feb 15, 2019
Merged

[Relay] Reference #2489

merged 3 commits into from
Feb 15, 2019

Conversation

MarisaKirisame
Copy link
Contributor

See #2483

@MarisaKirisame MarisaKirisame changed the title [Relay][WIP] Reference [Relay] Reference Jan 23, 2019
@MarisaKirisame
Copy link
Contributor Author

@ZihengJiang @junrushao1994 @zhiics can you guys review this? Thx!

Type VisitExpr_(const RefReadNode* op) final {
Type it = IncompleteTypeNode::make(TypeVarNode::Kind::kType);
this->Unify(GetType(op->ref), RefTypeNode::make(it), op->span);
return it;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why unify with a fresh incomplete type? You could just return GetType(op->ref)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this propagate the constraint backward (it unify op->ref with a reftype

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I misread the second line. Thanks for clarifying

@slyubomirsky
Copy link
Contributor

Unit tests for new alpha equality and type inference cases would be helpful for pinpointing bugs/regression.

@tqchen tqchen added the status: need RFC need RFC discussion label Jan 24, 2019
@MarisaKirisame
Copy link
Contributor Author

MarisaKirisame commented Jan 24, 2019

@tqchen the RFC is #2483

@ZihengJiang ZihengJiang self-assigned this Jan 28, 2019
@ZihengJiang ZihengJiang removed the status: need RFC need RFC discussion label Feb 1, 2019

TVM_REGISTER_API("relay._expr.TempExprRealize")
TVM_REGISTER_API("relay._make.RefNew").set_body([](TVMArgs args, TVMRetValue* ret) {
Copy link
Contributor

Choose a reason for hiding this comment

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

another line for .set_body

class RefWrite(Expr):
"""
Update the value inside the reference.
The whole expression will evaluate to an empty tuple.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why choose empty tuple

@zhiics
Copy link
Member

zhiics commented Feb 6, 2019

I only have some minor comments about the PR.

But I do have one concern about adding AST nodes/types because it would affect most relay passes. I see that some passes are modified correspondingly, but how about others such as memory planning and forward rewriting, etc?


RELAY_DEFINE_NODE_REF(RefRead, RefReadNode, Expr);

/*! \brief Set value of Reference. The whole expression evaluate to an Empty Tuple. */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/*! \brief Set value of Reference. The whole expression evaluate to an Empty Tuple. */
/*! \brief Set value of Reference. The whole expression evaluates to an Empty Tuple. */

TVM_DECLARE_NODE_TYPE_INFO(TupleGetItemNode, ExprNode);
};

RELAY_DEFINE_NODE_REF(TupleGetItem, TupleGetItemNode, Expr);

/*! \brief Create a new Reference out of initial value. */
class RefNew;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe RefNew to RefCreate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sgtm

Value r = Eval(op->ref);
if (const RefValueNode* rv = r.as<RefValueNode>()) {
rv->value = Eval(op->value);
return TupleValueNode::make({});
Copy link
Member

Choose a reason for hiding this comment

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

Could you please explain why empty tuple? Is it because the value is already updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. there is nothing needed to be return, so an empty tuple will do the job.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is also the convention in most ML-like languages.

@MarisaKirisame
Copy link
Contributor Author

@zhiics how do you do memory planning on control flow? i imagine planning for reference will be similar.
irregardless, i dont think it is much of a big deal - it is only used for higher order ad, and will be removed by a pass that try to fuse reference. if it cannot be fused it is pytorch style nlp model, and since tvm does not support them by now any improvement is good.

fix test

fix lint

fix test

add more code

fix lint

better type infer ability
@ZihengJiang ZihengJiang merged commit d05fed2 into apache:master Feb 15, 2019
libing4752 pushed a commit to libing4752/tvm that referenced this pull request Feb 18, 2019
* move

fix test

fix lint

fix test

add more code

fix lint

better type infer ability

* fix build

* address comment
@MarisaKirisame MarisaKirisame deleted the ref branch February 20, 2019 06:59
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
* move

fix test

fix lint

fix test

add more code

fix lint

better type infer ability

* fix build

* address comment
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
* move

fix test

fix lint

fix test

add more code

fix lint

better type infer ability

* fix build

* address comment
@yzhliu yzhliu mentioned this pull request Mar 2, 2019
28 tasks
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