Skip to content

2/n Simplify spawn plugins: Spawn immediately #10896

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 119 commits into from
Dec 9, 2021
Merged

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Dec 2, 2021

What does this PR do?

Fixes #10059 (step 4 & 5)

Moves the spawning of process right at the beginning of Trianer.fit/validate/test/predict.

  • Greatly improve readability due to simplified code path
  • Aligns the code path of DDPSpawn with other plugins like DDP
  • Hooks like setup() and teardown() now consistently run inside the worker processes and process group initialized
  • Significantly decreases the chance that the root_device gets accessed in a hook that runs outside the spawned processes in TPU spawn. This today would cause the process to exit with a cryptic message.

The core change of is that the spawning happens a level higher up in the trainer. Here is a simplified illustration using functions for before vs. after:

Before:

def _run(model, ...):
    setup()
    other()
    # <-- processes spawn here
    mp.spawn(train_fn, args=model)
    # <-- processes join here

    teardown()

After:

def _run(model):
    setup()
    other()
    train_fn(model)
    teardown()

# <-- processes spawn here
mp.spawn(_run, args=model)
# <-- processes join here

Possible issues that this PR might fix or help fix (need to check):

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 🙃

Part of #1 (it's a lie, this is just here to avoid noisy GitHub bot)

cc @Borda @justusschock @kaushikb11 @awaelchli @ninginthecloud

@awaelchli awaelchli mentioned this pull request Dec 9, 2021
11 tasks
@awaelchli
Copy link
Contributor Author

I have addressed all major questions and reviews. Thanks for the input and positive response so far!

Copy link
Contributor

@ananthsub ananthsub left a comment

Choose a reason for hiding this comment

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

excellent! super exciting to see this simplification along with all of the followup opportunities this surfaced!

@mergify mergify bot added the ready PRs ready to be merged label Dec 9, 2021
@four4fish
Copy link
Contributor

Looks great to me! I don't have permission to accept, but super happy to see this 💯 A big milestone for Accelerator stable version!!

Copy link
Contributor

@kaushikb11 kaushikb11 left a comment

Choose a reason for hiding this comment

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

Woohoo!

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

Awesome work !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Includes a breaking change ready PRs ready to be merged strategy: ddp DistributedDataParallel trainer: fit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify multiprocessing logic in DDPSpawn plugins
6 participants