Skip to content

Add then(callback)->Future API to ivalue::Future#37311

Closed
mrshenli wants to merge 24 commits intogh/mrshenli/157/basefrom
gh/mrshenli/157/head
Closed

Add then(callback)->Future API to ivalue::Future#37311
mrshenli wants to merge 24 commits intogh/mrshenli/157/basefrom
gh/mrshenli/157/head

Conversation

@mrshenli
Copy link
Copy Markdown
Contributor

@mrshenli mrshenli commented Apr 26, 2020

Stack from ghstack:

Differential Revision: D21247827

mrshenli pushed a commit that referenced this pull request Apr 26, 2020
ghstack-source-id: 4971722
Pull Request resolved: #37311
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Apr 26, 2020

💊 CI failures summary and remediations

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



🚧 4 fixed upstream failures:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

Since your merge base is older than viable/strict, run these commands:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

Check out the recency history of this "viable master" tracking branch.


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 on the GitHub issue tracker.

See how this bot performed.

This comment has been revised 60 times.

mrshenli pushed a commit that referenced this pull request Apr 26, 2020
ghstack-source-id: 4d2a39f
Pull Request resolved: #37311
@mrshenli mrshenli linked an issue Apr 29, 2020 that may be closed by this pull request
Comment thread torch/csrc/distributed/rpc/init.cpp Outdated
Comment on lines +2370 to +2371
@dist_init
def test_callback(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a few more test cases:

  1. Test that the callback can be a torchscript function.
  2. Attach python callback to future returned by:
    i) rpc_async within torchscript.
    ii) rpc_async calling torchscript function.
  3. Add tests to validate that we receive appropriate exceptions if callback doesn't have appropriate signature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cannot test calling _then in a TorchScript function yet, as that would require making _then torchscrptable.

Comment thread torch/csrc/distributed/rpc/init.cpp Outdated
@mrshenli mrshenli changed the title Let rpc.Future expose an add_done_callback API Add then(callback)->Future API to utils/Future.h May 6, 2020
Comment thread torch/csrc/utils/future.h Outdated
}

template<typename R>
std::shared_ptr<Future<R>> then(std::function<R(const Future<T>& future)> cb) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if this is the appropriate API. Since the returned Future represents the completion of the callback, it should also hold the returned value of the callback?

Copy link
Copy Markdown
Contributor

@rohan-varma rohan-varma May 6, 2020

Choose a reason for hiding this comment

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

The signature LGTM, though one question - what's the reason for the CB taking in a future instead of the completed value of the future? Is it so that we can access errors on the future when running the callback (if so see above comment)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

what's the reason for the CB taking in a future instead of the completed value of the future? Is it so that we can access errors on the future when running the callback (if so see above comment)?

Yep, the return value T might not be available if the callback crashed.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mrshenli merged this pull request in dad5526.

rohan-varma added a commit that referenced this pull request May 12, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 12, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 12, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 12, 2020
Pull Request resolved: #38352

Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix
ghstack-source-id: 103957346

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)
rohan-varma added a commit that referenced this pull request May 12, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 12, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 13, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 13, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 13, 2020
Pull Request resolved: #38352

Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix
ghstack-source-id: 103983281

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)
rohan-varma added a commit that referenced this pull request May 13, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 13, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 13, 2020
Pull Request resolved: #38352

Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix
ghstack-source-id: 104042479

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)
rohan-varma added a commit that referenced this pull request May 14, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 14, 2020
Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)

[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request May 14, 2020
Pull Request resolved: #38352

Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix
ghstack-source-id: 104086114

Differential Revision: [D21506940](https://our.internmc.facebook.com/intern/diff/D21506940/)
facebook-github-bot pushed a commit that referenced this pull request May 14, 2020
Summary:
Pull Request resolved: #38352

Fixes the RPC profiling by using the `then()` API added in #37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix
ghstack-source-id: 104086114

Test Plan: Re-enabled profiling tests

Differential Revision: D21506940

fbshipit-source-id: 35cde22f0551c825c9bc98ddc24cca412878a63a
@facebook-github-bot facebook-github-bot deleted the gh/mrshenli/157/head branch May 15, 2020 14:18
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#38045

We are working on fixing these (e.g.
pytorch#37311) but a few PRs still need to land
before these tests are fixed. Disable them for now to avoid noise
ghstack-source-id: 103701518

Test Plan: CI

Differential Revision: D21461340

fbshipit-source-id: fbb029a19a93d439c9fce8424be0fb6409b52ff3
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary: Pull Request resolved: pytorch#37311

Test Plan: Imported from OSS

Differential Revision: D21247827

Pulled By: mrshenli

fbshipit-source-id: f8fe0617ccb957aa747a78554a000ce2c4a58495
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#38352

Fixes the RPC profiling by using the `then()` API added in pytorch#37311. Instead of adding a regular callback, we return a new future that completes when the profiling callback is finished. This is transparent to the user as the future still completes with the value of the original future (i.e. the RPC's return value)

To make this work for RRef, we add a `_set_profiling_future` to set the profiling future, and `_get_profiling_future` to retrieve this future and wait on it in the tests.

Re-enabled profiling tests and stress tested them 1000 times to verify the fix
ghstack-source-id: 104086114

Test Plan: Re-enabled profiling tests

Differential Revision: D21506940

fbshipit-source-id: 35cde22f0551c825c9bc98ddc24cca412878a63a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Async User Function for RPC

6 participants