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

Enhance reduce_boolean_decision to accommodate any-analogous semantics expected by EarlyStopping Callback #15253

Merged

Conversation

speediedan
Copy link
Contributor

@speediedan speediedan commented Oct 22, 2022

What does this PR do?

Fixes #15252

When EarlyStopping is used in a distributed context, early stopping conditions may be met in some processes before others (especially when the divergence_threshold is sufficiently low).

Per the described intended behavior of EarlyStopping:
https://github.com/Lightning-AI/lightning/blob/be1eb5e86d07fe22b53a59184089aac569875117/src/pytorch_lightning/callbacks/early_stopping.py#L204-L205
, all training processes should be stopped when an EarlyStopping threshold is reached in any process. The current behavior of reduce_boolean_decision is to only return True when all input process decisions are True:
https://github.com/Lightning-AI/lightning/blob/be1eb5e86d07fe22b53a59184089aac569875117/src/lightning_lite/strategies/parallel.py#L88-L92

Though this issue can be avoided when logging the monitored metric with sync_dist=True, since that configuration is not mandatory, reduce_boolean_decision should be adapted to behave as the EarlyStopping callback expects.

This PR maintains the current reduce_boolean_decision behavior by default, but enhances the function to accommodate any-analogous semantics as expected by the EarlyStopping callback. This PR also includes an additional test to validate the aforementioned new behavior resolves the issue described.

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

None

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 🙃

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Oct 22, 2022
@speediedan speediedan marked this pull request as ready for review October 22, 2022 20:31
@codecov
Copy link

codecov bot commented Oct 22, 2022

Codecov Report

Merging #15253 (0aed7c8) into master (be1eb5e) will increase coverage by 2%.
The diff coverage is 88%.

❗ Current head 0aed7c8 differs from pull request most recent head d2b61b2. Consider uploading reports for the commit d2b61b2 to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #15253     +/-   ##
=========================================
+ Coverage      82%      84%     +2%     
=========================================
  Files         413      288    -125     
  Lines       30463    22002   -8461     
=========================================
- Hits        24938    18387   -6551     
+ Misses       5525     3615   -1910     

src/pytorch_lightning/strategies/parallel.py Outdated Show resolved Hide resolved
src/pytorch_lightning/strategies/parallel.py Show resolved Hide resolved
src/lightning_lite/strategies/parallel.py Outdated Show resolved Hide resolved
@awaelchli awaelchli added community This PR is from the community callback: early stopping bug Something isn't working labels Oct 24, 2022
@awaelchli awaelchli added this to the v1.9 milestone Oct 24, 2022
@awaelchli awaelchli mentioned this pull request Oct 30, 2022
12 tasks
src/lightning_lite/strategies/parallel.py Outdated Show resolved Hide resolved
@mergify mergify bot added the ready PRs ready to be merged label Nov 9, 2022
@awaelchli awaelchli enabled auto-merge (squash) November 9, 2022 19:35
@awaelchli awaelchli merged commit 9a4e8a8 into Lightning-AI:master Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working callback: early stopping community This PR is from the community 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.

reduce_boolean_decision behavior diverges from EarlyStopping callback's intended usage of it
3 participants