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

Fix CUDA RPC Stream Synchronization #50949

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 12 additions & 19 deletions torch/csrc/distributed/rpc/python_functions.cpp
Expand Up @@ -138,36 +138,29 @@ c10::intrusive_ptr<JitFuture> toPyJitFuture(
const std::shared_ptr<JitFuture>& messageJitFuture,
bool hasValue) {
if (hasValue) {
c10::intrusive_ptr<JitFuture> pyJitFuture =
c10::make_intrusive<JitFuture>(PyObjectType::get());
std::weak_ptr<JitFuture> wp = messageJitFuture;
messageJitFuture->addCallback(
at::wrapPropagateTLSState<void>([pyJitFuture, wp]() {
return messageJitFuture->then(
at::wrapPropagateTLSState<IValue>([wp]() {
auto future = wp.lock();
if (future->hasError()) {
pyJitFuture->setError(future->exception_ptr());
std::rethrow_exception(future->exception_ptr());
} else {
pyJitFuture->markCompleted(
toPyIValue(*future->value().toCustomClass<Message>()));
return toPyIValue(*future->value().toCustomClass<Message>());
}
}));

return pyJitFuture;
}),
PyObjectType::get());
Comment on lines 141 to +151
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, it would be nice to add some unit tests that would consistently fail without this patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's hard to make it consistently fail, but #50839 fails pretty frequently without this fix. I am not sure if this is the only bug, but I tried a few tens of times locally, and the error didn't occur.

} else {
c10::intrusive_ptr<JitFuture> pyJitFuture =
c10::make_intrusive<JitFuture>(NoneType::get());
std::weak_ptr<JitFuture> wp = messageJitFuture;
messageJitFuture->addCallback(
at::wrapPropagateTLSState<void>([wp, pyJitFuture]() {
return messageJitFuture->then(
at::wrapPropagateTLSState<IValue>([wp]() {
auto future = wp.lock();
if (future->hasError()) {
pyJitFuture->setError(future->exception_ptr());
std::rethrow_exception(future->exception_ptr());
} else {
pyJitFuture->markCompleted(IValue());
return IValue();
}
}));

return pyJitFuture;
}),
NoneType::get());
}
}

Expand Down