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

Enable purely iteration-based training #5726

Merged

Conversation

ananthsub
Copy link
Contributor

@ananthsub ananthsub commented Jan 31, 2021

What does this PR do?

Fixes #3521

This preserves the existing default of min_epochs=1 if both min_steps and min_epochs aren't specified, and the default behavior of max_epochs=1000 if both max_steps and max_epochs aren't specified.

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
  • Check that target branch and milestone match!

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Jan 31, 2021

Codecov Report

Merging #5726 (0f2a0b2) into release/1.2-dev (9dd5639) will decrease coverage by 0%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##           release/1.2-dev   #5726   +/-   ##
===============================================
- Coverage               88%     88%   -0%     
===============================================
  Files                  181     181           
  Lines                12929   12932    +3     
===============================================
+ Hits                 11426   11428    +2     
- Misses                1503    1504    +1     

@ananthsub ananthsub added this to the 1.2 milestone Jan 31, 2021
@ananthsub ananthsub added the feature Is an improvement or enhancement label Jan 31, 2021
@ananthsub ananthsub marked this pull request as ready for review January 31, 2021 04:35
@Borda
Copy link
Member

Borda commented Jan 31, 2021

this is the same as #5686 #5687 correct?

Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

nice!

pytorch_lightning/trainer/training_loop.py Show resolved Hide resolved
tests/trainer/flags/test_min_max_epochs.py Outdated Show resolved Hide resolved
Comment on lines 7 to 10
# @pytest.mark.parametrize("min_epochs", [None, 2])
# @pytest.mark.parametrize("max_epochs", [None, 3])
# @pytest.mark.parametrize("min_steps", [None, 20])
# @pytest.mark.parametrize("max_steps", [None, 100])
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all of these 16 configurations valid?
Did you try what happens if we choose max_epochs = 1 and max_steps = 5 but the epoch only has 3 batches?
The number that leads to less training steps should terminate training, right? This could be a separate test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if both are specified, i think should exit out whenever the first condition is met. so for the example you provided, if the epoch has only 3 batches, i agree we should return after the epoch completes and before moving onto the remaining 2 steps. the same goes for min_steps

i think users can already exercise this functionality now, so i'll look to see if there are already test cases for it. if not i'll add them here

pytorch_lightning/trainer/trainer.py Show resolved Hide resolved
@ananthsub
Copy link
Contributor Author

this is the same as #5686 #5687 correct?

yes that's correct, i'm sorry about the noisy PRs. i made some n00b git errors and it was easier for me to create a new PR than fix the existing ones

@mergify mergify bot removed the has conflicts label Feb 2, 2021
@ananthsub
Copy link
Contributor Author

one thing i need to check is what happens to the progress bar

@mergify mergify bot added the has conflicts label Feb 5, 2021
@mergify mergify bot removed the has conflicts label Feb 9, 2021
@Borda Borda enabled auto-merge (squash) February 9, 2021 20:40
@Borda Borda added the ready PRs ready to be merged label Feb 9, 2021
tests/trainer/flags/test_min_max_epochs.py Outdated Show resolved Hide resolved
@kaushikb11 kaushikb11 enabled auto-merge (squash) February 10, 2021 05:11
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.

LGTM !

@kaushikb11 kaushikb11 merged commit d26702b into Lightning-AI:release/1.2-dev Feb 10, 2021
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 ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable training purely based on number of iterations instead of epochs
7 participants