-
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
Loop Refactor 3/N - Evaluation Loop #7990
Conversation
Co-authored-by: Justus Schock <[email protected]> Co-authored-by: Justus Schock <[email protected]> Co-authored-by: Justus Schock <[email protected]>
Hello @awaelchli! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-06-18 11:00:30 UTC |
for more information, see https://pre-commit.ci
Codecov Report
@@ Coverage Diff @@
## master #7990 +/- ##
======================================
- Coverage 92% 91% -0%
======================================
Files 207 210 +3
Lines 13479 13558 +79
======================================
+ Hits 12346 12392 +46
- Misses 1133 1166 +33 |
…eval' into refactor/loops/loops_everywhere_eval
for more information, see https://pre-commit.ci
…eval' into refactor/loops/loops_everywhere_eval
pytorch_lightning/loops/dataloader/evaluation_dataloader_loop.py
Outdated
Show resolved
Hide resolved
pytorch_lightning/loops/dataloader/evaluation_dataloader_loop.py
Outdated
Show resolved
Hide resolved
pytorch_lightning/loops/dataloader/evaluation_dataloader_loop.py
Outdated
Show resolved
Hide resolved
pytorch_lightning/loops/dataloader/evaluation_dataloader_loop.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Carlos Mocholí <[email protected]>
…eval' into refactor/loops/loops_everywhere_eval
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
pytorch_lightning/loops/dataloader/evaluation_dataloader_loop.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Ethan Harris <[email protected]>
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.
Looks awesome !
if self.trainer.testing: | ||
self.trainer.lightning_module._current_fx_name = "test_step" | ||
with self.trainer.profiler.profile("test_step"): | ||
output = self.trainer.accelerator.test_step(step_kwargs) | ||
else: | ||
self.trainer.lightning_module._current_fx_name = "validation_step" | ||
with self.trainer.profiler.profile("validation_step"): | ||
output = self.trainer.accelerator.validation_step(step_kwargs) |
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.
if self.trainer.testing: | |
self.trainer.lightning_module._current_fx_name = "test_step" | |
with self.trainer.profiler.profile("test_step"): | |
output = self.trainer.accelerator.test_step(step_kwargs) | |
else: | |
self.trainer.lightning_module._current_fx_name = "validation_step" | |
with self.trainer.profiler.profile("validation_step"): | |
output = self.trainer.accelerator.validation_step(step_kwargs) | |
name_step = "test_step" if self.trainer.testing else "validation_step" | |
self.trainer.lightning_module._current_fx_name =name_step | |
with self.trainer.profiler.profile(name_step): | |
if self.trainer.testing: | |
output = self.trainer.accelerator.test_step(step_kwargs) | |
else: | |
output = self.trainer.accelerator.validation_step(step_kwargs) |
if output is not None: | ||
if isinstance(output, ResultCollection): | ||
output = output.detach() | ||
if self.trainer.move_metrics_to_cpu: | ||
output = output.cpu() | ||
elif isinstance(output, dict): | ||
output = recursive_detach(output, to_cpu=self.trainer.move_metrics_to_cpu) | ||
elif isinstance(output, Tensor) and output.is_cuda and self.trainer.move_metrics_to_cpu: | ||
output = output.cpu() | ||
outputs.append(output) | ||
return outputs |
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.
if output is not None: | |
if isinstance(output, ResultCollection): | |
output = output.detach() | |
if self.trainer.move_metrics_to_cpu: | |
output = output.cpu() | |
elif isinstance(output, dict): | |
output = recursive_detach(output, to_cpu=self.trainer.move_metrics_to_cpu) | |
elif isinstance(output, Tensor) and output.is_cuda and self.trainer.move_metrics_to_cpu: | |
output = output.cpu() | |
outputs.append(output) | |
return outputs | |
if output is None: | |
return outputs | |
if isinstance(output, ResultCollection): | |
output = output.detach() | |
if self.trainer.move_metrics_to_cpu: | |
output = output.cpu() | |
elif isinstance(output, dict): | |
output = recursive_detach(output, to_cpu=self.trainer.move_metrics_to_cpu) | |
elif isinstance(output, Tensor) and output.is_cuda and self.trainer.move_metrics_to_cpu: | |
output = output.cpu() | |
outputs.append(output) | |
return outputs |
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
…eval' into refactor/loops/loops_everywhere_eval
What does this PR do?
Introduces the evaluation loop under the new interface introduced in #7871
Three new classes:
DataLoaderLoop
: This loop runs over a list of dataloadersEvaluationDataLoaderLoop
: A subclass ofDataLoaderLoop
running over a list of evaluation dataloaders (can be test or validation)EvaluationEpochLoop
: Runs a single epoch of validation or test.In the next PR, we will introduce also the
PredictionDataLoaderLoop
andPredictionEpochLoop
.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 short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃