[Relay] Add generic & informative Relay error reporting#2408
[Relay] Add generic & informative Relay error reporting#2408tqchen merged 13 commits intoapache:masterfrom
Conversation
|
This is ready for review, could everyone check it out? |
|
I will do it tomorrow evening |
|
@jroesch I briefly went through. I will do another pass later. |
| // it may be good to instead report it to std::cout. | ||
| LOG(FATAL) << annotated_prog.str() << std::endl; | ||
|
|
||
| exit(1); |
| * 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 |
There was a problem hiding this comment.
I misread this doc comment initially, as only describing two modes. It should be "The final mode" here. My bad.
2a3cc59 to
7a370ea
Compare
| @@ -0,0 +1 @@ | |||
| exclude_files=rang.h | |||
| * | ||
| * \returns The entry point function, (i.e. main). | ||
| */ | ||
| Expr EntryPoint(); |
There was a problem hiding this comment.
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
| #include <vector> | ||
|
|
||
| namespace tvm { | ||
| namespace relay { |
There was a problem hiding this comment.
can we put this into error.h? assuming this is part of error handling mechanism
There was a problem hiding this comment.
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.
|
@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() {} |
There was a problem hiding this comment.
| 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); |
There was a problem hiding this comment.
no need to have exit after LOG(FATAL)?
There was a problem hiding this comment.
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.
1add04c to
e1ec636
Compare
4e32721 to
c98bb22
Compare
|
Thank you, @jroesch @joshpoll @zhiics @MarisaKirisame ! this is now merged |
| } else { | ||
| return func->body; | ||
| } | ||
| } else { |
There was a problem hiding this comment.
@jroesch I guess we forgot to call TypeInferencer here...?
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:
Currently I have only enabled this behavior in the type inferencer, but the machinery is generic and exposed by
relay::Moduleideally 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