-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
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. |
src/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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary.
* 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.
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.
2a3cc59
to
7a370ea
Compare
src/relay/util/CPPLINT.cfg
Outdated
@@ -0,0 +1 @@ | |||
exclude_files=rang.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary anymore
include/tvm/relay/module.h
Outdated
* | ||
* \returns The entry point function, (i.e. main). | ||
*/ | ||
Expr EntryPoint(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Main
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
include/tvm/relay/error_reporter.h
Outdated
#include <vector> | ||
|
||
namespace tvm { | ||
namespace relay { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@tqchen No problem. I will do one tonight. |
include/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() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit Error(const std::string &msg) : dmlc::Error(msg), sp() {} | |
explicit Error(const std::string& msg) : dmlc::Error(msg), sp() {} |
src/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); |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
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.
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...?
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::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