-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add Trainer.validate(…) method to run one validation epoch #4707
Conversation
`Trainer.validate` follows the same semantics as `Trainer.test` and shares part of the implementation
Hello @EliaCereda! Thanks for updating this PR.
Comment last updated at 2020-12-02 10:53:05 UTC |
…ProgressBar It seems that tqdm doesn’t support `__bool__` on its instances, so it was raising an exception.
Codecov Report
@@ Coverage Diff @@
## master #4707 +/- ##
=======================================
Coverage 93% 93%
=======================================
Files 124 124
Lines 9203 9349 +146
=======================================
+ Hits 8524 8668 +144
- Misses 679 681 +2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so far. Can you add some tests?
Co-authored-by: Rohit Gupta <[email protected]>
Yes, I'll also prepare some tests, I was thinking of using the test cases for |
3b5ae9b
to
99a6161
Compare
It's not clear to me why these tests are failing. I think CircleCI just had a transient error and might go away if we re-run. This is the other failing test, the 'specific' variant. It fails at line 212 because the checkpoint file doesn't exist anymore, but it did exist at line 201 when |
@carmocca, regarding your other three comments, I based my tests directly on those for the |
Co-authored-by: Carlos Mocholí <[email protected]>
I have an idea as to why this might be: the default Still wondering why this is a problem only in some CI runs and not in others. Let's see if 9e59e6d fixes this. |
…evaluating Without this, ModelCheckpoint might delete the very checkpoint being evaluated. Furthermore, the model will not change during evaluation anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR is big. Just a high-level review.
pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py
Outdated
Show resolved
Hide resolved
* Remove unused test_mode parameter * Differentiate validation/test results in the printed message
Co-authored-by: Rohit Gupta <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
…alidate # Conflicts: # CHANGELOG.md # pytorch_lightning/callbacks/progress.py
I'll have some more time to dedicate to this over the coming week and I'd ask you if there is something I can do to bring this closer to a mergeable state. The biggest concern is that it's quite a big PR right now. To address this, I went through to the changes that are included and I'd say they can be divided in 7 groups:
Do you think I missed anything? Of these, I think 1. and 2. could definitely make sense on their own and might be pushed forward in their own PR. On the other hand, I'm having a hard time finding a way to further separate the rest. Do you have any suggestion in this sense? Thanks! |
I personally would keep it to this PR. It's definitely not the largest we've merged recently and the changes have cohesion. What do others prefer? |
I'd suggest separate PRs, just to minimize any future bugs and better review, the way suggested here: #4707 (comment)
|
# We do this so __attach_datamodule in trainer.py doesn't mistakenly call setup('test') on trainer.test() | ||
stage = args[1] if len(args) > 1 else kwargs.get("stage", None) | ||
|
||
if stage == "fit" or stage is None: | ||
obj._has_setup_fit = True | ||
|
||
if stage == "validation" or stage is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make all references in datamodule "validate" (instead of "validation) to keep it consistent with fit and test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fit and test can be nouns or verbs, however, we are talking about stages which means they should be nouns.
So if I am not mistaken (English is not my first language), using validation is more consistent.
The validation stage vs the validate stage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think grammar should be a consideration here since we're only talking about variables in code... and that variable name consistency is more important. Thoughts on this? @justusschock @rohitgr7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both of you have a point here and once could certainly use both. However, I feel that validation stage is more intuitive and personally I would go with it since it sounds 'more correct' to me, but this is just a personal opinion. Also I think, that this should definitely not be a blocker here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is a good point. I was also ambivalent about it while I was writing the code.
There is another occurrence of this issue: the Trainer.evaluating
attribute, which can be either test
or validation
. Here validation
is the right choice in my opinion, reading it as "currently evaluating over the test/validation set".
It was not so clear cut in the data module: I'd say that 'validation' sounds better for me too, but I would not be opposed to using 'validate' either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, it does have a better ring to it :]
def train_or_test(self): | ||
if self.trainer.testing: | ||
results = self.trainer.run_test() | ||
def train_or_evaluate(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name here is a bit misleading as this also runs test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used evaluate
here to refer to either test
or validate
. I think it was inspired by the pre-existing Trainer.run_evaluation
method, which is used to run either the test or validation loop depending on the value of the test_mode
parameter.
Let me know if you have a better idea for the name!
…alidate # Conflicts: # CHANGELOG.md # pytorch_lightning/trainer/evaluation_loop.py # pytorch_lightning/trainer/trainer.py # tests/callbacks/test_callbacks.py
What does this PR do?
Adds a
Trainer.validate(...)
method to perform one evaluation epoch over the validation set, with the same semantics asTrainer.test(...)
.Resolves #4634
I'd say that the PR is now in a good enough shape to remove the draft tag and request a proper review.
Before submitting
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 in short, see following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃