Skip to content

Better error message when trying to re-initialize CUDA in forked subprocess #14709

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

Merged
merged 11 commits into from
Sep 28, 2022

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Sep 14, 2022

What does this PR do?

Follow up to #14631
Follow up to #13405

We recently launched DDP Fork support in notebooks (ddp_notebook), and some users will soon report issues when seeing this error message in their notebooks: "Cannot re-initialize CUDA in forked subprocess".

The issue is mitigated by #14631 for our internal calls, and pytorch addresses torch.cuda utility function calls in pytorch/pytorch#84879 and pytorch/pytorch#85024. However, it can always happen that the user allocates CUDA memory accidentally without knowing that this is not supported with the fork start method. We point it out in our documentation, but that's not enough.

This PR introduces an error message that is more helpful than the default PyTorch one.

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

No

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 update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read 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?

I made sure I had fun coding 🙃

cc @Borda @carmocca @justusschock @awaelchli @akihironitta

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Sep 14, 2022
@awaelchli awaelchli added fabric lightning.fabric.Fabric accelerator: cuda Compute Unified Device Architecture GPU labels Sep 14, 2022
@awaelchli awaelchli added this to the pl:1.7.x milestone Sep 14, 2022
@awaelchli awaelchli self-assigned this Sep 14, 2022
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

I am subscribed to your PRs, reviewing them before you even mark them as ready 🐎

@awaelchli
Copy link
Contributor Author

I am subscribed to your PRs, reviewing them before you even mark them as ready 🐎

Thank you! Is that a horse?

Will mark it ready once I gave this a final check in Google Colab as well.

@awaelchli awaelchli marked this pull request as ready for review September 26, 2022 19:17
Copy link
Contributor

@akihironitta akihironitta left a comment

Choose a reason for hiding this comment

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

LGTM!

@mergify mergify bot added the ready PRs ready to be merged label Sep 28, 2022
@awaelchli awaelchli merged commit ea5e817 into master Sep 28, 2022
@awaelchli awaelchli deleted the feature/cuda-initialized-check branch September 28, 2022 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accelerator: cuda Compute Unified Device Architecture GPU fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package ready PRs ready to be merged
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants