-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Let RpcAgent::send() return JitFuture #49906
Conversation
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit baf267b (more details on the Dr. CI page):
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. This comment has been revised 75 times. |
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. ghstack-source-id: 49f0b3caaef1245efe1e2c7afa8dd61fac873caf Pull Request resolved: #49906
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.
Left a few comments on the internal diff.
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. ghstack-source-id: 58569c04274c229e5aca69b4abdce8312d4feb98 Pull Request resolved: #49906
torch/csrc/distributed/rpc/init.cpp
Outdated
// NB: need to call torch::class_ to register Message in the map returned by | ||
// c10::getCustomClassTypeMap(). Otherwise, Message cannot be wrapped within | ||
// an IValue. | ||
static const auto message = torch::class_<Message>("rpc", "_Message"); |
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.
Hey @wanchaol, are there plans to extract the custom type registration logic from torch::class_
to convert it into a utility function, so that c++ only IValue custom types no longer need to be bound here?
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.
Sorry for the late reply. is this still a valid ask? I think if this is only for C++ used, we don't need to register/bound the class into python or TorchScript, just make the C++ class inherit torch::CustomClassHolder
is enough
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.
Hey @wanchaol, thanks for the comments. Yep, this is still relevant. I found that if I don't call torch::class_
, IValue(c10::make_intrusive<Message>(std::move(msg)))
would crash. I traced the code and found that it hits this line:
pytorch/aten/src/ATen/core/ivalue.h
Line 963 in 71ca600
throw c10::Error("Can't find class id in custom class type map", ""); |
I did a quick search, and looks like torch::class_
is only place that inserts new types:
Lines 88 to 91 in 00a3add
c10::getCustomClassTypeMap().insert( | |
{std::type_index(typeid(c10::intrusive_ptr<CurClass>)), classTypePtr}); | |
c10::getCustomClassTypeMap().insert( | |
{std::type_index(typeid(c10::tagged_capsule<CurClass>)), classTypePtr}); |
Please let me know if there are better suggestions. Thanks!
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. ghstack-source-id: da01047db164bd38c277f47884c8d8bd54d6468a Pull Request resolved: pytorch#49906
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
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 PR has internal changes
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.
The OSS changes look good to me. Although I'm not qualified on the JIT custom classes, so let's get a review from someone else too.
@@ -157,7 +157,7 @@ class TORCH_API RpcAgent { | |||
// If ``message.isRequest()`` is true, the ``FutureMessage`` will be | |||
// completed when the response arrives. For other message types, the Future | |||
// should be ignored by the caller. | |||
virtual std::shared_ptr<FutureMessage> send( | |||
virtual std::shared_ptr<JitFuture> send( |
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've mostly seen JitFuture being passed around through an intrusive_ptr, rather than a shared_ptr. I guess that's somewhat more efficient (not sure how much). Should we consider it here too?
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.
@wanchaol @gmagogsfm is there any perf penalty if we use ivalue::Future
with std::shared_ptr
?
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 shouldn't be too much perf penalty, it's just that shared_ptr store the refcount in a separate memory space instead of embedded in the object, so from cache locality prospective intrusive_ptr should be a bit faster. We passed around JitFuture through intrusive_ptr also for the reason of making it to be able to held by IValue
so that it's easier to bind to TorchScript if needed.
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 see, thanks for the explanation!
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Differential Revision: [D25719518](https://our.internmc.facebook.com/intern/diff/D25719518) [ghstack-poisoned]
Summary: Pull Request resolved: pytorch#49906 This commit modifies RPC Message to inherit from `torch::CustomClassHolder`, and wraps a Message in an IValue in `RpcAgent::send()`. Test Plan: Imported from OSS Reviewed By: lw Differential Revision: D25719518 Pulled By: mrshenli fbshipit-source-id: 694e40021e49e396da1620a2f81226522341550b
Stack from ghstack:
This commit modifies RPC Message to inherit from
torch::CustomClassHolder
,and wraps a Message in an IValue in
RpcAgent::send()
.Differential Revision: D25719518