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

Let RpcAgent::send() return JitFuture #49906

Closed
wants to merge 12 commits into from

Conversation

mrshenli
Copy link
Contributor

@mrshenli mrshenli commented Dec 28, 2020

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

This commit modifies RPC Message to inherit from `torch::CustomClassHolder`,
and wraps a Message in an IValue in `RpcAgent::send()`.

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Dec 28, 2020

💊 CI failures summary and remediations

As of commit baf267b (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This 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]
mrshenli added a commit that referenced this pull request Dec 28, 2020
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
Copy link
Contributor

@pritamdamania87 pritamdamania87 left a 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]
mrshenli added a commit that referenced this pull request Dec 29, 2020
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
// 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");
Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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:

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:

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]
mrshenli added a commit to mrshenli/pytorch that referenced this pull request Dec 30, 2020
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]
Copy link
Contributor Author

@mrshenli mrshenli left a 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

Copy link
Contributor

@lw lw left a 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(
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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!

torch/csrc/distributed/rpc/message.cpp Outdated Show resolved Hide resolved
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]
@facebook-github-bot
Copy link
Contributor

@mrshenli merged this pull request in 84e3237.

@facebook-github-bot facebook-github-bot deleted the gh/mrshenli/268/head branch January 11, 2021 15:17
hwangdeyu pushed a commit to hwangdeyu/pytorch that referenced this pull request Jan 14, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Merged oncall: distributed Add this issue/PR to distributed oncall triage queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants