Skip to content

[RELAY][TypeSystem] Add support for populating type args#1962

Merged
tqchen merged 7 commits intoapache:masterfrom
jroesch:type_args_fix
Oct 24, 2018
Merged

[RELAY][TypeSystem] Add support for populating type args#1962
tqchen merged 7 commits intoapache:masterfrom
jroesch:type_args_fix

Conversation

@jroesch
Copy link
Copy Markdown
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.

Comment thread include/tvm/relay/expr.h Outdated
* \endcode
*/
tvm::Array<Type> type_args;
mutable tvm::Array<Type> type_args;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread include/tvm/relay/expr.h Outdated
* \endcode
*/
tvm::Array<Type> type_args;
mutable tvm::Array<Type> type_args;
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.

I agree using const cast selectively is a better approach

Comment thread src/relay/ir/text_printer.cc
Comment thread src/relay/pass/type_infer.cc
Comment thread src/relay/pass/type_infer.cc Outdated
auto call = GetRef<Call>(op);
auto it = tmap_.find(call);
if (it != tmap_.end()) {
Call new_op = Downcast<Call>(AttachCheckedType(op));
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.

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

Comment thread src/relay/pass/type_infer.cc Outdated

Type checked_type;
// Only allocated when the expression is a call.
Array<Type> type_args;
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.

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

Comment thread src/relay/pass/type_infer.cc
@tqchen tqchen added the status: need update need update based on feedbacks label Oct 23, 2018
@tqchen
Copy link
Copy Markdown
Member

tqchen commented Oct 23, 2018

Comment thread src/relay/ir/text_printer.cc Outdated
@@ -277,16 +277,30 @@ class TextPrinter :
TextValue VisitExpr_(const CallNode* op) final {
// TODO(tqchen, M.K.): support generic call
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.

remove the todo

Comment thread src/relay/pass/type_infer.cc Outdated
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
Copy Markdown
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
Copy Markdown
Member Author

jroesch commented Oct 23, 2018

@tqchen Should be good to go modulo CI.

Comment thread include/tvm/relay/op.h
Comment thread include/tvm/relay/op.h Outdated
Comment thread include/tvm/relay/op.h Outdated
Comment thread src/relay/pass/type_infer.cc Outdated
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
Copy Markdown
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

Comment thread src/relay/pass/type_infer.cc Outdated
: 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
Copy Markdown
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
Copy Markdown
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