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 support for DDP fork #13405

Merged
merged 69 commits into from
Jul 22, 2022
Merged

Add support for DDP fork #13405

merged 69 commits into from
Jul 22, 2022

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Jun 24, 2022

What does this PR do?

Fixes #7550
Fixes #8230

Adds support for DDP Fork. This version of ddp can be used in Jupyter notebooks with GPU unlike ddp_spawn!!!
Usage:

trainer = Trainer(
    accelerator="gpu",
    devices=2,
    strategy="ddp_fork",
)

See the added docs for a comparison of ddp_spawn vs. ddp_fork

Remarks:

  • Thanks for the advice and support by @justusschock
  • DDP fork should be faster to launch the processes. We could consider replacing ddp_spawn with ddp_fork in some tests to speed up CI, but one should be careful as process forking is considered unsafe in general.

Q: Why did we need to replace almost all instances of torch.cuda.device_count() and torch.cuda.is_available()?
A: These function calls unfortunately create a CUDA context, i.e., they init the CUDA memory and tie it to the current process. Once this happens, we won't be able to re-initialize the CUDA anymore in the forked processes. This is a limitation of torch + forking.

Q: Now that we support two different start methods in DDPSpawnStrategy, shouldn't we rename the strategy?
A: Yes technically we should. Especially since TPUSpawnStrategy is also using the fork start method and does not even support spawn. However, renaming everything here is too premature, considering that in the longterm the strategies DDPSpawn and DDP will get merged eventually anyway. What we can do in a follow up is renaming the internal launcher classes _SpawnLauncher and _XLASpawnLauncher, and associated terminology in docs, comments, etc.

Open questions

  • Should DDP fork become the default when strategy=None and devices>1 in a Jupyter notebook?
    • Result: Can be done in follow up by modifying acc connector
  • Investigate forkserver.
    • Result: Can't be supported in Jupyter. But user can select it if they want in the launcher.

Follow-up work

Does your PR introduce any breaking changes? If yes, please list them.

No known ones.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

cc @Borda @tchaton @rohitgr7 @justusschock @kaushikb11 @awaelchli @akihironitta

@awaelchli awaelchli force-pushed the feature/ddp-fork2 branch from b059f73 to 9cea979 Compare June 25, 2022 03:09
@mergify mergify bot added ready PRs ready to be merged and removed has conflicts ready PRs ready to be merged labels Jul 20, 2022
@mergify mergify bot added has conflicts and removed ready PRs ready to be merged labels Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement pl Generic label for PyTorch Lightning package priority: 0 High priority task ready PRs ready to be merged strategy: ddp DistributedDataParallel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Support forking for DDP DDP spawn no longer works in Jupyter environment
10 participants