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

Loop Refactor 3/N - Evaluation Loop #7990

Merged
merged 56 commits into from Jun 18, 2021

Conversation

awaelchli
Copy link
Member

@awaelchli awaelchli commented Jun 15, 2021

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 dataloaders
  • EvaluationDataLoaderLoop: A subclass of DataLoaderLoop 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 and PredictionEpochLoop.

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 update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

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

Did you have fun?

Make sure you had fun coding 🙃

awaelchli and others added 4 commits June 15, 2021 15:52
Co-authored-by: Justus Schock <justus.schock@rwth-aachen.de>
Co-authored-by: Justus Schock <justus.schock@posteo.de>
Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
@pep8speaks
Copy link

pep8speaks commented Jun 15, 2021

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

@codecov
Copy link

codecov bot commented Jun 15, 2021

Codecov Report

Merging #7990 (6545bc9) into master (3fece17) will decrease coverage by 0%.
The diff coverage is 96%.

@@          Coverage Diff           @@
##           master   #7990   +/-   ##
======================================
- Coverage      92%     91%   -0%     
======================================
  Files         207     210    +3     
  Lines       13479   13558   +79     
======================================
+ Hits        12346   12392   +46     
- Misses       1133    1166   +33     

@awaelchli awaelchli added this to the v1.4 milestone Jun 15, 2021
@awaelchli awaelchli marked this pull request as ready for review June 16, 2021 21:48
Copy link
Member

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

LGTM

@awaelchli awaelchli added the ready PRs ready to be merged label Jun 18, 2021
awaelchli and others added 2 commits June 18, 2021 10:02
Co-authored-by: Ethan Harris <ewah1g13@soton.ac.uk>
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.

Looks awesome !

@tchaton tchaton enabled auto-merge (squash) June 18, 2021 10:20
Comment on lines +142 to +149
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)

Comment on lines +250 to +260
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

awaelchli and others added 4 commits June 18, 2021 12:58
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
…eval' into refactor/loops/loops_everywhere_eval
@lexierule lexierule disabled auto-merge June 18, 2021 12:54
@lexierule lexierule merged commit 0d6dfd4 into master Jun 18, 2021
@lexierule lexierule deleted the refactor/loops/loops_everywhere_eval branch June 18, 2021 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants