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] Add generic & informative Relay error reporting #2408

Merged
merged 13 commits into from
Jan 25, 2019

Conversation

jroesch
Copy link
Member

@jroesch jroesch commented Jan 9, 2019

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

src/relay/ir/module.cc Outdated Show resolved Hide resolved
include/tvm/relay/error.h Outdated Show resolved Hide resolved
include/tvm/relay/error.h Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
@jroesch jroesch changed the title [Relay][WIP] Add generic & informative Relay error reporting [Relay] Add generic & informative Relay error reporting Jan 10, 2019
@jroesch
Copy link
Member Author

jroesch commented Jan 10, 2019

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

include/tvm/relay/error.h Outdated Show resolved Hide resolved
include/tvm/relay/error.h Outdated Show resolved Hide resolved
include/tvm/relay/error.h Outdated Show resolved Hide resolved
include/tvm/relay/error.h Outdated Show resolved Hide resolved
include/tvm/relay/module.h Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Jan 10, 2019

I will do it tomorrow evening

include/tvm/relay/module.h Outdated Show resolved Hide resolved
include/tvm/relay/module.h Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
@zhiics
Copy link
Member

zhiics commented Jan 10, 2019

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

include/tvm/relay/module.h Outdated Show resolved Hide resolved
include/tvm/relay/module.h Outdated Show resolved Hide resolved
include/tvm/relay/module.h Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
// it may be good to instead report it to std::cout.
LOG(FATAL) << annotated_prog.str() << std::endl;

exit(1);
Copy link
Member

Choose a reason for hiding this comment

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

not necessary.

src/relay/util/rang.h Outdated Show resolved Hide resolved
@tqchen tqchen self-assigned this Jan 11, 2019
include/tvm/relay/module.h Outdated Show resolved Hide resolved
* 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
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.

src/relay/ir/module.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
src/relay/ir/module.cc Outdated Show resolved Hide resolved
include/tvm/relay/module.h Outdated Show resolved Hide resolved
include/tvm/relay/module.h Outdated Show resolved Hide resolved
@jroesch jroesch force-pushed the relay-error-reporting branch 5 times, most recently from 2a3cc59 to 7a370ea Compare January 16, 2019 23:45
@@ -0,0 +1 @@
exclude_files=rang.h
Copy link
Member

Choose a reason for hiding this comment

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

not necessary anymore

*
* \returns The entry point function, (i.e. main).
*/
Expr EntryPoint();
Copy link
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
Member Author

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
Member

Choose a reason for hiding this comment

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

remove this

#include <vector>

namespace tvm {
namespace relay {
Copy link
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
Member Author

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.

include/tvm/relay/error.h Outdated Show resolved Hide resolved
tests/python/relay/test_error_reporting.py Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Jan 18, 2019

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
Member

zhiics commented Jan 18, 2019

@tqchen No problem. I will do one tonight.

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
Member

Choose a reason for hiding this comment

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

Suggested change
explicit Error(const std::string &msg) : dmlc::Error(msg), sp() {}
explicit Error(const std::string& msg) : dmlc::Error(msg), sp() {}

// it may be good to instead report it to std::cout.
LOG(FATAL) << annotated_prog.str() << std::endl;

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

Copy link
Member Author

@jroesch jroesch Jan 18, 2019

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.

src/relay/ir/module.cc Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
src/relay/pass/type_infer.cc Outdated Show resolved Hide resolved
tests/python/relay/test_error_reporting.py Show resolved Hide resolved
@tqchen tqchen added the status: need update need update based on feedbacks label Jan 25, 2019
@tqchen tqchen merged commit 02631f6 into apache:master Jan 25, 2019
@tqchen
Copy link
Member

tqchen commented Jan 25, 2019

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

@tqchen tqchen 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
@ZihengJiang ZihengJiang 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
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 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.

7 participants