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][TypeSystem] Add support for populating type args #1962

Merged
merged 7 commits into from
Oct 24, 2018

Conversation

jroesch
Copy link
Member

@jroesch jroesch commented Oct 23, 2018

The RTS system PR #1954 requires that we correctly populate the type arguments field. This PR adds this behavior separately and is a prerequisite for #1954.

I also added support to the text printer which was tripping an assertion otherwise.

I added one test to show this works correctly for primitive operations.

@@ -267,7 +267,7 @@ class CallNode : public ExprNode {
*
* \endcode
*/
tvm::Array<Type> type_args;
mutable tvm::Array<Type> type_args;
Copy link
Member Author

Choose a reason for hiding this comment

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

It may be better to use const cast selectively in the implementation rather then marking this field as mutable.

Copy link
Member

Choose a reason for hiding this comment

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

I agree using const cast selectively is a better approach

@jroesch
Copy link
Member Author

jroesch commented Oct 23, 2018

cc @MarisaKirisame @tqchen

@jroesch jroesch changed the title Add support for populating type args [RELAY][TypeSystem] Add support for populating type args Oct 23, 2018
jroesch added a commit to jroesch/tvm that referenced this pull request Oct 23, 2018
jroesch added a commit to jroesch/tvm that referenced this pull request Oct 23, 2018
Add initial version of evaluator and tests

WIP

Work towards simple examples in the evaluator

Requires implementation of lowering ops and monomorph

Evaluator now works on simple cases

Restore Function case in Evaluator

WIP

Fix rebase issues

working towards working version

RTS is now working again

RTS can add numbers now

Fix some rebase issues

Fix up tests post rebase

WIP

Issue type checking MLP

Remove dead file

Clean up evaluator

Remove accidental change

Reset changes from apache#1962
jroesch added a commit to jroesch/tvm that referenced this pull request Oct 23, 2018
Add initial version of evaluator and tests

WIP

Work towards simple examples in the evaluator

Requires implementation of lowering ops and monomorph

Evaluator now works on simple cases

Restore Function case in Evaluator

WIP

Fix rebase issues

working towards working version

RTS is now working again

RTS can add numbers now

Fix some rebase issues

Fix up tests post rebase

WIP

Issue type checking MLP

Remove dead file

Clean up evaluator

Remove accidental change

Reset changes from apache#1962
@@ -267,7 +267,7 @@ class CallNode : public ExprNode {
*
* \endcode
*/
tvm::Array<Type> type_args;
mutable tvm::Array<Type> type_args;
Copy link
Member

Choose a reason for hiding this comment

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

I agree using const cast selectively is a better approach

src/relay/ir/text_printer.cc Show resolved Hide resolved
src/relay/pass/type_infer.cc Show resolved Hide resolved
auto call = GetRef<Call>(op);
auto it = tmap_.find(call);
if (it != tmap_.end()) {
Call new_op = Downcast<Call>(AttachCheckedType(op));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can change AttachCheckedType -> AttachTypeInfo, and directly attach type_args when it is defined


Type checked_type;
// Only allocated when the expression is a call.
Array<Type> type_args;
Copy link
Member

Choose a reason for hiding this comment

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

Array type_args(NodePtr(nullptr)) // specially initialize to undefined

@tqchen tqchen added the status: need update need update based on feedbacks label Oct 23, 2018
@tqchen
Copy link
Member

tqchen commented Oct 23, 2018

@@ -277,16 +277,30 @@ class TextPrinter :
TextValue VisitExpr_(const CallNode* op) final {
// TODO(tqchen, M.K.): support generic call
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the todo

void AddTypeArgs(const Expr& expr, Array<Type> type_args) {
auto type_info = type_map_.find(expr);
if (type_info == type_map_.end()) {
type_map_.insert({expr, ResolvedTypeInfo(type_args) });
Copy link
Contributor

Choose a reason for hiding this comment

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

remove extra space?

@jroesch
Copy link
Member Author

jroesch commented Oct 23, 2018

@tqchen Should be good to go modulo CI.

include/tvm/relay/op.h Show resolved Hide resolved
include/tvm/relay/op.h Outdated Show resolved Hide resolved
include/tvm/relay/op.h Outdated Show resolved Hide resolved
struct ResolvedTypeInfo {
explicit ResolvedTypeInfo(Type checked_type, Array<Type> type_args)
: checked_type(checked_type), type_args(type_args) {}
ResolvedTypeInfo(const ResolvedTypeInfo& rti)
Copy link
Member

Choose a reason for hiding this comment

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

likely you don't need this, as long as there are default constructor with no argument

: checked_type(checked_type), type_args(type_args) {}
ResolvedTypeInfo(const ResolvedTypeInfo& rti)
: checked_type(rti.checked_type), type_args(rti.type_args) {}
ResolvedTypeInfo() : checked_type() {}
Copy link
Member

Choose a reason for hiding this comment

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

no need to initalized checked_type, it will pick the default constructor

Copy link
Member Author

Choose a reason for hiding this comment

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

I added these constructors due to a template instantiation error earlier.

@tqchen tqchen merged commit 3bfa5fc into apache:master Oct 24, 2018
@tqchen tqchen added status: accepted and removed status: need update need update based on feedbacks labels Oct 24, 2018
jroesch added a commit to jroesch/tvm that referenced this pull request Oct 25, 2018
Add initial version of evaluator and tests

WIP

Work towards simple examples in the evaluator

Requires implementation of lowering ops and monomorph

Evaluator now works on simple cases

Restore Function case in Evaluator

WIP

Fix rebase issues

working towards working version

RTS is now working again

RTS can add numbers now

Fix some rebase issues

Fix up tests post rebase

WIP

Issue type checking MLP

Remove dead file

Clean up evaluator

Remove accidental change

Reset changes from apache#1962

Rename Evaluator

A little clean up

WIP

Clean up tests

WIP

WIP

Repair from rebase and refactor to not use MM

Remove testing code which is now in apache#1969

WIP
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
@jroesch jroesch deleted the type_args_fix branch February 4, 2021 04:36
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.

4 participants