Skip to content

Conversation

@rohitgr7
Copy link
Contributor

@rohitgr7 rohitgr7 commented Dec 20, 2020

What does this PR do?

Fixes #4603
Fixes #4655
Fixes #4797
Fixes #5156

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • 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? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

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; Bugfixes should be including in bug-fix release milestones (m.f.X) and features should be included in (m.X.b) releases.

Did you have fun?

Make sure you had fun coding 🙃

@pep8speaks
Copy link

pep8speaks commented Dec 20, 2020

Hello @rohitgr7! Thanks for updating this PR.

Line 234:13: W503 line break before binary operator

Line 592:17: W503 line break before binary operator
Line 593:17: W503 line break before binary operator
Line 895:13: W503 line break before binary operator
Line 896:13: W503 line break before binary operator
Line 899:13: W503 line break before binary operator

Comment last updated at 2021-02-08 08:00:12 UTC

@codecov
Copy link

codecov bot commented Dec 20, 2020

Codecov Report

Merging #5208 (b0608b0) into master (3b7afb9) will decrease coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #5208    +/-   ##
=======================================
- Coverage      93%     89%    -4%     
=======================================
  Files         134     134            
  Lines       10053   10051     -2     
=======================================
- Hits         9399    8980   -419     
- Misses        654    1071   +417     

@rohitgr7 rohitgr7 changed the title Separate epoch validation from step validation [skip ci] Separate epoch validation from step validation Jan 25, 2021
@rohitgr7 rohitgr7 added bug Something isn't working callback checkpointing Related to checkpointing and removed has conflicts labels Jan 25, 2021
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.

Minor comments. Overall awesome!

@mergify mergify bot added the has conflicts label Feb 3, 2021
@mergify mergify bot removed the has conflicts label Feb 5, 2021
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.

Great PR ! Small question.

# reset stage to train
self.trainer.logger_connector.set_stage("train")

should_skip_eval = self.trainer.evaluation_loop.should_skip_evaluation(self.trainer.num_val_batches)
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly confused about this part. Can you explain why we check val and then decide if we should skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just to check whether there is any validation datasets available or not. If there isn't then we should run train_only_check else not. There are two cases for no validation, one when there is no validation_step other one when there is a validation_step but no validation_batches. Since even if we have a validation_step but no validation_batches, it used to skip the train_only_check, but ideally it should not.
Resolves: #4603 issue

Copy link
Contributor

Choose a reason for hiding this comment

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

@rohitgr7 I'm debugging an issue right now related to this.

pytorch_lightning/trainer/training_loop.py:753: Input params: batch_idx=1, is_last_batch=True, on_epoch=True
pytorch_lightning/trainer/training_loop.py:755: batch_idx+1=2, trainer.val_check_batch=2, is_val_check_batch=True
pytorch_lightning/trainer/training_loop.py:758: current_epoch+1=1, trainer.check_val_every_n_epoch=1, is_val_check_epoch=True
pytorch_lightning/trainer/training_loop.py:761: enable_validation=True, is_val_check_epoch=True, can_check_val=True
pytorch_lightning/trainer/training_loop.py:765: is_last_batch=True, trainer.val_check_batch=2, is_last_batch_for_infinite_dataset=False
pytorch_lightning/trainer/training_loop.py:768: batch_idx + 1=2, trainer.num_training_batches=2, epoch_end_val_check=True
pytorch_lightning/trainer/training_loop.py:774: is_val_check_batch=True, is_val_check_epoch=True, can_check_val=True, is_last_batch_for_infinite_dataset=False, epoch_end_val_check=True, should_check_val=True
pytorch_lightning/trainer/training_loop.py:775: should_check_val=True, can_check_val=True
pytorch_lightning/trainer/training_loop.py:487: should_check_val=True
pytorch_lightning/trainer/training_loop.py:489: should_skip_eval=True, trainer.num_val_batches=[]

this check for should_skip_eval is forcing the should_train_only to be True, which causes the checkpoint callback to run before validation. The checkpoint is configured for a metric that appears only in validation, which leads to a failure. I don't get why should_skip_eval affects the should_train_only - shouldn't that be decided entirely by self.trainer.disable_validation ?

this could also be pointing to a bug in how self.trainer.num_val_batches is set

Borda
Borda previously requested changes Feb 5, 2021
Comment on lines +89 to +90
call.on_epoch_end(trainer, model),
call.on_train_epoch_end(trainer, model, ANY),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that @williamFalcon had a point some time ago about training shall be till validation, and the example was with validation multiple times over long training...
cc: @tchaton @PyTorchLightning/core-contributors

Copy link
Contributor Author

@rohitgr7 rohitgr7 Feb 5, 2021

Choose a reason for hiding this comment

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

yes it still works like that only if val_check_interval < 1.0 or it an int where val_check_interval % num_training_batches != 0. But if it is set to 1.0 then validation here happens after training_epoch because we create checkpoints in on_validation_end and epoch level learning rates are updated once training is done since in case of ReduceLROnPlateau we need to have the monitor metrics and they are only available after complete training is done in case monitor is training specific.

@Borda Borda added the ready PRs ready to be merged label Feb 5, 2021
@rohitgr7 rohitgr7 requested review from Borda and kaushikb11 February 7, 2021 09:21
@Borda Borda enabled auto-merge (squash) February 8, 2021 07:51
@Borda Borda self-requested a review February 8, 2021 08:00
@Borda Borda merged commit e429f97 into master Feb 8, 2021
@Borda Borda deleted the bugfix/ep_end_ckpt branch February 8, 2021 08:35
Borda pushed a commit that referenced this pull request Feb 8, 2021
* Seperate epoch validaton from step validation

* update system

* test

* baked logic in callbacks

* unbake logic in callbacks

* fix the call for scheduler

* use property

* pep

* correct rebase

* gitignore

* ref

* add tests

* fix

* add early stopping test

* trigger

* chlog

* rev

* 1.3

* log

* Apply suggestions from code review

Co-authored-by: Carlos Mocholí <[email protected]>

* Update pytorch_lightning/trainer/training_loop.py

* Update CHANGELOG.md

* Apply suggestions from code review

Co-authored-by: chaton <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>

(cherry picked from commit e429f97)
Borda pushed a commit that referenced this pull request Feb 8, 2021
* Seperate epoch validaton from step validation

* update system

* test

* baked logic in callbacks

* unbake logic in callbacks

* fix the call for scheduler

* use property

* pep

* correct rebase

* gitignore

* ref

* add tests

* fix

* add early stopping test

* trigger

* chlog

* rev

* 1.3

* log

* Apply suggestions from code review

Co-authored-by: Carlos Mocholí <[email protected]>

* Update pytorch_lightning/trainer/training_loop.py

* Update CHANGELOG.md

* Apply suggestions from code review

Co-authored-by: chaton <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>

(cherry picked from commit e429f97)
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 checkpointing Related to checkpointing priority: 0 High priority task ready PRs ready to be merged

Projects

None yet

7 participants