Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Support populating errors back to MXNet engine in callback #13922

Merged
merged 2 commits into from
Jan 18, 2019

Conversation

yuxihu
Copy link
Member

@yuxihu yuxihu commented Jan 17, 2019

This PR adds an optional dmlc::Error* argument in MXNet engine callback functions. The callers can leverage this argument to populate errors back to MXNet engine through callback such that the errors can be handled properly by MXNet engine. One such use case is to populate the errors detected in Horovod back to MXNet engine for Hovorod and MXNet integration. This change does not affect existing use cases.

@@ -74,15 +74,15 @@ class CallbackOnComplete {
public:
// use implicit copy and assign
/*! \brief involve the callback */
inline void operator()() const {
(*callback_)(engine_, param_);
inline void operator()(const char* error_msg = nullptr) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing in a const string of error message, would it make sense to pass in a error struct which contains error message and error code in the fields? This leaves more room for proper error handling based on error code.

Copy link
Member Author

Choose a reason for hiding this comment

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

The error code is not universally defined across different libraries. In the Horovod case, the error types are mostly Horovod specific. We convert all those to dmlc::Error which MXNet can catch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we define an error data structure and export it? So all libraries that consume libmxnet will use this error data structure to pass data back.

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds like a good idea to make it extendable in the future. We can use the error message for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

Use dmlc::Error instead of char*. We can change dmlc::Error if more information need to be passed.

@stu1130
Copy link
Contributor

stu1130 commented Jan 17, 2019

Nice work @yuxihu
@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Jan 17, 2019
@yuxihu
Copy link
Member Author

yuxihu commented Jan 18, 2019

@eric-haibin-lin please take a look.

Copy link
Contributor

@apeforest apeforest left a comment

Choose a reason for hiding this comment

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

LGTM

OprBlock *opr_block = static_cast<OprBlock*>(opr_block_);
ThreadedOpr *threaded_opr = opr_block->opr;
if (error != nullptr) {
auto ex_p = std::make_exception_ptr(*error);
threaded_opr->opr_exception = std::make_shared<std::exception_ptr>(ex_p);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't exception_ptr already reference counted? Do we need to wrap it again in make_shared?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I will change related sites by removing the redundant shared_ptr in a separate PR.

Copy link
Contributor

@larroy larroy left a comment

Choose a reason for hiding this comment

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

See previous question. Is there a test for this?

Copy link
Contributor

@larroy larroy left a comment

Choose a reason for hiding this comment

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

As discussed, LGTM would be nice to remove the shared ptr if it's redundant in a separate PR.

@marcoabreu marcoabreu merged commit 0c85665 into apache:master Jan 18, 2019
@yuxihu yuxihu deleted the hvd_mx_error branch January 18, 2019 18:20
jessr92 pushed a commit to jessr92/incubator-mxnet that referenced this pull request Jan 27, 2019
)

* add an optional error_msg in engine on_complete callbcak

* use dmlc::Error struct to make error population extendable
stephenrawls pushed a commit to stephenrawls/incubator-mxnet that referenced this pull request Feb 16, 2019
)

* add an optional error_msg in engine on_complete callbcak

* use dmlc::Error struct to make error population extendable
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
)

* add an optional error_msg in engine on_complete callbcak

* use dmlc::Error struct to make error population extendable
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants