Fix root rank output handling bug in MXNet out-of-place broadcast. #1740
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recent testing has shown that there is an issue with the existing MXNet out-of-place broadcast implementation in setting the output result on the root rank. The existing implementation has a race condition that can return zero tensor instead of the expected output if it is queried quickly after the
hvd.broadcast
call. For instance, in this example here:we see that
result
on the root rank can sometimes be0
instead of the expected value42
.The issue is due to this special handling for root rank and the call to
TensorUtil::Copy
here: https://github.com/horovod/horovod/blob/master/horovod/mxnet/mpi_ops.cc#L101The problem arises because
TensorUtil::Copy
launches an MXNet op (CopyFromTo
) within the Horovod op to copy the root rank input to output. This creates a race condition because ifoutput.asscalar()
is scheduled on the Python main thread beforeCopyFromTo
is scheduled by the engine worker thread, it will return the output tensor before the copy is carried out, yielding an incorrect zero tensor.This is fixed by moving the input to output tensor copy on the root rank to the
hvd.broadcast
function in Python.cc @ptrendx