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

Support val_check_interval values higher than number of training batches #11993

Merged
merged 18 commits into from
Apr 21, 2022

Conversation

nikvaessen
Copy link
Contributor

@nikvaessen nikvaessen commented Feb 18, 2022

What does this PR do?

Fixes #8135
Fixes #4406
Fixes #5413.

It enables using val_check_interval with a value higher than the amount of batches in one training data loader iteration. This is very useful when you use a cyclic learning rate, and want to validate on the extreme values of a cycle, without having to worry about the amount of samples in your dataset.

I chose to implement the following option as provided by @carmocca in #8135 (comment)

check every n batches across epochs: Not implemented. What this issue is requesting. Potentially val_check_interval=n, check_val_every_n_epoch=None? Also requested in:

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

I'm not sure as I'm not very familiar with the code base. Some people might rely on the fact that val_check_interval does not cause a validation loop to happen when the value is higher than the amount of training batches, but I doubt it as I don't see a reason for intentionally skipping a validation epoch.

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 internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
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?

Make sure you had fun coding 🙃

@nikvaessen
Copy link
Contributor Author

It seems that the only tests which are failing are due to ModuleNotFoundError: No module named 'pygame', so I would say this PR is ready for review.

@mergify mergify bot removed the has conflicts label Feb 20, 2022
@awaelchli awaelchli added feature Is an improvement or enhancement loops Related to the Loop API trainer labels Feb 21, 2022
@awaelchli awaelchli added this to the 1.7 milestone Feb 21, 2022
@mergify mergify bot removed the has conflicts label Feb 22, 2022
…erval

# Conflicts:
#	CHANGELOG.md
#	pytorch_lightning/callbacks/progress/base.py
#	pytorch_lightning/loops/epoch/training_epoch_loop.py
#	pytorch_lightning/trainer/connectors/data_connector.py
#	pytorch_lightning/trainer/trainer.py
…_val_check_interval

# Conflicts:
#	pytorch_lightning/trainer/trainer.py
@mergify mergify bot removed the has conflicts label Apr 6, 2022
@nikvaessen
Copy link
Contributor Author

I've updated the PR so that merge conflicts with changes from the 1.6 release are resolved. Hopefully, the PR won't go stale again :)

@carmocca carmocca added the priority: 0 High priority task label Apr 7, 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.

Good job on the PR!

pytorch_lightning/loops/epoch/training_epoch_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/loops/epoch/training_epoch_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/connectors/data_connector.py Outdated Show resolved Hide resolved
@nikvaessen
Copy link
Contributor Author

nikvaessen commented Apr 8, 2022

I've resolved your comments, and also added a test case for an iterable dataset without a defined length.

use more sensible value to approx inf
@nikvaessen nikvaessen requested a review from carmocca April 19, 2022 12:30
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.

LGTM!

tests/trainer/flags/test_check_val_every_n_epoch.py Outdated Show resolved Hide resolved
tests/trainer/flags/test_val_check_interval.py Outdated Show resolved Hide resolved
Copy link
Contributor

@rohitgr7 rohitgr7 left a comment

Choose a reason for hiding this comment

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

Great work @nikvaessen !! 🚀

@mergify mergify bot added the ready PRs ready to be merged label Apr 20, 2022
tests/trainer/flags/test_check_val_every_n_epoch.py Outdated Show resolved Hide resolved
tests/trainer/flags/test_val_check_interval.py Outdated Show resolved Hide resolved
tests/trainer/flags/test_val_check_interval.py Outdated Show resolved Hide resolved
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 loops Related to the Loop API priority: 0 High priority task ready PRs ready to be merged trainer
Projects
None yet
4 participants