Skip to content

[Relay] Add generic & informative Relay error reporting - #2408

Merged
tqchen merged 13 commits into
apache:masterfrom
jroesch:relay-error-reporting
Jan 25, 2019
Merged

[Relay] Add generic & informative Relay error reporting#2408
tqchen merged 13 commits into
apache:masterfrom
jroesch:relay-error-reporting

Conversation

@jroesch

Copy link
Copy Markdown
Member

This PR adds the ability to generate informative error messages for Relay programs. This works irrespective of spans, and source programs.

The new error reporting works by collecting the set of errors generated by the program, then reporting them in two separate steps.

This design enables us to collect more than a single error when processing a program and report many at the same time. We can report errors on a module using the function mod->ReportError(...).

When can then choose to render the errors to the user as an error message using mod->RenderErrors(...). This will use the reported errors to annotated the program using the text printer.
The error messages will be marked in red on the line they occurred.

You can see an example of the error reporting in action below:

image

Currently I have only enabled this behavior in the type inferencer, but the machinery is generic and exposed by relay::Module ideally future passes can take advantage of it.

I plan to propose and implement a generic pass & pass manager interface soon. The pass manager should make it easy to opt-in to error reporting without much work from pass authors.

I just got a basic version of this working and am still in the process of polishing the PR.

cc @ZihengJiang@MarisaKirisame@joshpoll@weberlo@tqchen@zhiics @icemelon9

Comment threadsrc/relay/ir/module.cc Outdated
Comment threadinclude/tvm/relay/error.h Outdated
Comment threadinclude/tvm/relay/error.h
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
@jroeschjroesch changed the title [Relay][WIP] Add generic & informative Relay error reporting[Relay] Add generic & informative Relay error reportingJan 10, 2019
@jroesch

Copy link
Copy Markdown
MemberAuthor

This is ready for review, could everyone check it out?

Comment threadinclude/tvm/relay/error.h Outdated
Comment threadinclude/tvm/relay/error.h Outdated
Comment threadinclude/tvm/relay/error.h Outdated
Comment threadinclude/tvm/relay/error.h Outdated
Comment threadinclude/tvm/relay/module.h Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
@tqchen

Copy link
Copy Markdown
Member

I will do it tomorrow evening

Comment threadinclude/tvm/relay/module.h Outdated
Comment threadinclude/tvm/relay/module.h Outdated
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
@zhiics

Copy link
Copy Markdown
Member

@jroesch I briefly went through. I will do another pass later.

Comment threadtests/python/relay/test_error_reporting.py
Comment threadinclude/tvm/relay/module.h Outdated
Comment threadinclude/tvm/relay/module.h Outdated
Comment threadinclude/tvm/relay/module.h
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
// it may be good to instead report it to std::cout.
LOG(FATAL) << annotated_prog.str() << std::endl;

exit(1);

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.

not necessary.

Comment threadsrc/relay/util/rang.h Outdated
@tqchentqchen self-assigned this Jan 11, 2019
Comment threadinclude/tvm/relay/module.h Outdated
* expression, we will default to throwing an exception with a textual representation
* of the error and no indication of where it occured in the original program.
*
* The latter mode is not ideal, and the goal of the new error reporting machinery is

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 misread this doc comment initially, as only describing two modes. It should be "The final mode" here. My bad.

Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadsrc/relay/ir/module.cc Outdated
Comment threadinclude/tvm/relay/module.h Outdated
Comment threadinclude/tvm/relay/module.h Outdated
@jroesch
jroeschforce-pushed the relay-error-reporting branch 5 times, most recently from 2a3cc59 to 7a370eaCompareJanuary 16, 2019 23:45
Comment threadsrc/relay/util/CPPLINT.cfg Outdated
@@ -0,0 +1 @@
exclude_files=rang.h

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.

not necessary anymore

Comment threadinclude/tvm/relay/module.h Outdated
*
* \returns The entry point function, (i.e. main).
*/
Expr EntryPoint();

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.

This name could still use more discussions.

Given that this is an one-liner module[module->entry_func], maybe we don't need this function

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

What about Main?

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.

remove this

Comment threadinclude/tvm/relay/error_reporter.h Outdated
#include <vector>

namespace tvm {
namespace relay {

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.

can we put this into error.h? assuming this is part of error handling mechanism

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

There was a cyclic dependency issue that I was trying to avoid by splitting the files, a few places use relay::Error which ErrorReporter depends on.

Comment threadinclude/tvm/relay/error.h Outdated
Comment threadtests/python/relay/test_error_reporting.py
@tqchen

Copy link
Copy Markdown
Member

This is a very crucial feature for high-level IR, I would like to invite a few more reviewers, @zhiics @icemelon9 @nishi-t please comment, if you have time.

In particular, please see if the public error reporting API makes sense to you

@zhiics

Copy link
Copy Markdown
Member

@tqchen No problem. I will do one tonight.

Comment threadinclude/tvm/relay/error.h Outdated
struct Error : public dmlc::Error {
explicit Error(const std::string &msg) : dmlc::Error(msg) {}
Span sp;
explicit Error(const std::string &msg) : dmlc::Error(msg), sp() {}

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.

Suggested change
explicitError(conststd::string&msg) : dmlc::Error(msg), sp() {}
explicitError(conststd::string&msg) : dmlc::Error(msg), sp() {}

Comment threadsrc/relay/ir/error_reporter.cc Outdated
// it may be good to instead report it to std::cout.
LOG(FATAL) << annotated_prog.str() << std::endl;

exit(1);

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 have exit after LOG(FATAL)?

@jroeschjroeschJan 18, 2019

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

LOG(FATAL) doesn't tell the compiler that it is [noreturn] causing a warning to be triggered. We can choose to omit these but in general marking unreachable code and code that doesn't return allows the compiler to better optimize.

Comment threadsrc/relay/ir/module.cc
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadsrc/relay/pass/type_infer.cc Outdated
Comment threadtests/python/relay/test_error_reporting.py
@jroesch
jroeschforce-pushed the relay-error-reporting branch from 1add04c to e1ec636CompareJanuary 18, 2019 23:53
@jroesch
jroeschforce-pushed the relay-error-reporting branch from 4e32721 to c98bb22CompareJanuary 25, 2019 00:07
@tqchentqchen added the status: need update need update based on feedbacks label Jan 25, 2019
@tqchen
tqchen merged commit 02631f6 into apache:masterJan 25, 2019
@tqchen

Copy link
Copy Markdown
Member

Thank you, @jroesch@joshpoll@zhiics@MarisaKirisame ! this is now merged

@tqchentqchen added status: accepted and removed status: need review status: need update need update based on feedbacks labels Jan 25, 2019
Anthony-Mai pushed a commit to Anthony-Mai/tvm that referenced this pull request Jan 26, 2019
Anthony-Mai pushed a commit to Anthony-Mai/tvm that referenced this pull request Jan 28, 2019
Anthony-Mai pushed a commit to Anthony-Mai/tvm that referenced this pull request Jan 28, 2019
zhiics pushed a commit to zhiics/tvm that referenced this pull request Jan 30, 2019
@ZihengJiangZihengJiang mentioned this pull request Feb 1, 2019
@jroesch
jroesch deleted the relay-error-reporting branch February 11, 2019 00:01
merrymercy pushed a commit to merrymercy/tvm that referenced this pull request Feb 18, 2019
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
} else {
return func->body;
}
} else {

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.

@jroesch I guess we forgot to call TypeInferencer here...?

Sign up for freeto 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.

7 participants

@jroesch@tqchen@zhiics@MarisaKirisame@joshpoll@junrushao@weberlo