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

Add Trainer.validate(…) method to run one validation epoch #4707

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
62bd29e
Add Trainer.validate(…) to run one validation epoch
EliaCereda Nov 17, 2020
055e1ba
Support val_progress_bar without main_progress_bar in ProgressBar
EliaCereda Nov 17, 2020
156b669
Fix PEP 8 issue
EliaCereda Nov 17, 2020
1429548
Use `main_progress_bar is not None` to test if the bar is present in …
EliaCereda Nov 17, 2020
50427e7
Simplify selection of dataloaders arg to be set
EliaCereda Nov 17, 2020
d1988e0
Call setup(…) with stage ‘validation’ when running Trainer.validate(…)
EliaCereda Nov 17, 2020
ae03c6b
Check self.trainer.evaluating instead of self.trainer.testing in Acce…
EliaCereda Nov 17, 2020
5493a5b
Set Trainer.evaluating to None by default
EliaCereda Nov 17, 2020
860fef5
Replace the remaining instances of self.evaluating = False with None
EliaCereda Nov 18, 2020
99a6161
Add a first batch of tests for Trainer.validate(…)
EliaCereda Nov 18, 2020
307c89a
Avoid an if/else in ProgressBar
EliaCereda Nov 18, 2020
9e59e6d
Modify ModelCheckpoint to never save a checkpoint automatically when …
EliaCereda Nov 18, 2020
a844f40
Update test_config_validator.py to match the messages of expected err…
EliaCereda Nov 18, 2020
3f9f927
Fix Trainer.validate(…, verbose=True)
EliaCereda Nov 19, 2020
db22f2b
Transform Trainer.testing to a read-only deprecated property, remove …
EliaCereda Nov 19, 2020
f8647c5
Update docs for Trainer.validate and Trainer.test
EliaCereda Nov 19, 2020
99281a0
Remove usages of deprecated Trainer.testing
EliaCereda Nov 20, 2020
58d1c36
Rename methods and attributes to reflect their new behavior
EliaCereda Nov 20, 2020
7330ad4
Rename Trainer.tested_ckpt_path to Trainer.evaluated_ckpt_path since …
EliaCereda Nov 20, 2020
7abc67d
Update CHANGELOG.md
EliaCereda Nov 20, 2020
14799da
Fix PEP 8 issues
EliaCereda Nov 20, 2020
f8f4d3b
Update documentation of .setup(stage) methods to mention the new ‘val…
EliaCereda Nov 20, 2020
1818f22
Added more tests for Trainer.validate
EliaCereda Nov 20, 2020
ab89faa
Merge remote-tracking branch 'upstream/master' into feature/trainer-v…
EliaCereda Nov 20, 2020
d0cd34a
Fix hook that tracks LightningDataModule.setup(‘validation’) calls, a…
EliaCereda Nov 20, 2020
0209cfc
Add a test for Trainer.validate on DataParallel
EliaCereda Nov 20, 2020
6a04280
Disable EarlyStopping in evaluation mode
EliaCereda Nov 21, 2020
2115350
Clean up LoggerConnector.get_evaluate_epoch_results
EliaCereda Nov 21, 2020
92acb12
Improve description of Trainer.validate in docs/source/trainer.rst
EliaCereda Nov 21, 2020
8090193
Clean up setup() methods in tests/base/datamodules.py
EliaCereda Nov 21, 2020
a098489
Update deprecation warnings
EliaCereda Nov 21, 2020
f8ab391
Update Trainer.{validate, test} docstrings
EliaCereda Nov 21, 2020
605e7b0
Fix PEP 8 issue
EliaCereda Nov 21, 2020
14a7767
Consistently use the serial comma in docstrings
EliaCereda Nov 23, 2020
e9a6956
Merge remote-tracking branch 'upstream/master' into feature/trainer-v…
EliaCereda Nov 23, 2020
873099e
Merge remote-tracking branch 'upstream/master' into feature/trainer-v…
EliaCereda Nov 25, 2020
6f2ce28
Fix PEP 8 issue
EliaCereda Nov 25, 2020
0f4e474
Merge remote-tracking branch 'upstream/master' into feature/trainer-v…
EliaCereda Dec 2, 2020
d4cb1b0
Rewrite assertions for Trainer.validate in test_callbacks.py using Ma…
EliaCereda Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Call setup(…) with stage ‘validation’ when running Trainer.validate(…)
  • Loading branch information
EliaCereda committed Nov 17, 2020
commit d1988e03ebefb65c049f6fc527627673c3955d6d
10 changes: 10 additions & 0 deletions pytorch_lightning/core/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def __init__(
# Private attrs to keep track of whether or not data hooks have been called yet
self._has_prepared_data = False
self._has_setup_fit = False
self._has_setup_validation = False
self._has_setup_test = False

@property
Expand Down Expand Up @@ -230,6 +231,15 @@ def has_setup_fit(self):
"""
return self._has_setup_fit

@property
def has_setup_validation(self):
"""Return bool letting you know if datamodule.setup('validation') has been called or not.

Returns:
bool: True if datamodule.setup('validation') has been called. False by default.
"""
return self._has_setup_validation

@property
def has_setup_test(self):
"""Return bool letting you know if datamodule.setup('test') has been called or not.
Expand Down
11 changes: 9 additions & 2 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,18 @@ def tune(

def call_setup_hook(self, model):
# call setup after the ddp process has connected
stage_name = 'test' if self.testing else 'fit'
stage_name = self.evaluating or 'fit'

if self.datamodule is not None:
called = self.datamodule.has_setup_test if self.testing else self.datamodule.has_setup_fit
called = {
False: self.datamodule.has_setup_fit,
'validation': self.datamodule.has_setup_validation,
'test': self.datamodule.has_setup_test,
}[self.evaluating]

if not called:
self.datamodule.setup(stage_name)

self.setup(model, stage_name)
model.setup(stage_name)

Expand Down