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

Add torchrun launcher plugin #2119

Merged

Conversation

jbaczek
Copy link
Contributor

@jbaczek jbaczek commented Mar 31, 2022

Motivation

PyTorch distributed apps is a common use case for hydra (according to many github issues). Currently implementation of torchrun interferes with hydra in a way, that causes hydra to initialize multiple times, leading to many race conditions.
This PR contains a launcher plugin that fixes the issue, forking the process after hydra is initialized.

Have you read the Contributing Guidelines on pull requests?

Yes
This MR is submitted on behalf of NVIDIA.

Test Plan

Use machine with multiple GPUs.
Use pytorch docker conrainer or install PyTorch in any other way.
Install plugin with pip.
How to run torch distributed without plugin:

torchrun --nproc_per_node=8 my_app.py

How to run with plugin:

python my_app.py -m hydra/launcher=torchrun hydra.launcher.nproc_per_node=8

Related Issues and PRs

Resolves #2038

@facebook-github-bot
Copy link
Contributor

Hi @jbaczek!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@Jasha10
Copy link
Collaborator

Jasha10 commented Mar 31, 2022

Thanks @jbaczek.
This idea of wrapping the task function is an interesting approach to solving the problem of launching multiple processes for a single hydra run (context: #2038 comment).

@pixelb
Copy link
Contributor

pixelb commented Apr 14, 2022

We're considering having a contrib/ dir to serve as a staging area for various new launchers / sweepers.
Re failing tests, it looks like you just need to run black over the new sources.
We'll do the necessary to merge it to contrib/.

Thank you for your contribution!

@jbaczek
Copy link
Contributor Author

jbaczek commented Apr 15, 2022

Should I lint it? Or will you do this on your side?

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 20, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@jieru-hu
Copy link
Contributor

hi @jbaczek - thanks very much for your contribution!

We've created contrib here for plugin contributions. We've also included a README there.
Could you update this PR and move this plugin to the contrib folder and add integration tests?

pls let us know if you have any question on this. thanks again.

@jbaczek
Copy link
Contributor Author

jbaczek commented Apr 29, 2022

I'll update it as soon as I'll have some time for it. Probably mid-may

@jbaczek
Copy link
Contributor Author

jbaczek commented May 11, 2022

@jieru-hu I've moved the plugin to the contrib dir and added the tests. Do you need me to do something more?

@jieru-hu
Copy link
Contributor

thanks @jbaczek and sorry for the late response. I will take a look at this

@jieru-hu
Copy link
Contributor

looks great, thanks for your contribution @jbaczek !

@jieru-hu jieru-hu merged commit 6ed3af0 into facebookresearch:main May 26, 2022
siemdejong pushed a commit to siemdejong/hydra-torchrun-launcher that referenced this pull request Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] hydra with torch.distributed.launch
5 participants