From 91d6a3652fb221232866674b02e001bc839c8590 Mon Sep 17 00:00:00 2001 From: ananthsub Date: Wed, 5 May 2021 12:36:41 -0700 Subject: [PATCH 1/3] Docs follow up to 7338/7339 --- pytorch_lightning/callbacks/base.py | 7 ++++++- pytorch_lightning/core/hooks.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/base.py b/pytorch_lightning/callbacks/base.py index 3e8a77cbfdb0a..2f3314fdb51c6 100644 --- a/pytorch_lightning/callbacks/base.py +++ b/pytorch_lightning/callbacks/base.py @@ -101,7 +101,12 @@ def on_train_epoch_start(self, trainer: 'pl.Trainer', pl_module: 'pl.LightningMo def on_train_epoch_end( self, trainer: 'pl.Trainer', pl_module: 'pl.LightningModule', unused: Optional = None ) -> None: - """Called when the train epoch ends.""" + """Called when the train epoch ends. + + To access all batch outputs at the end of the epoch, either: + 1. Implement `training_epoch_end` in the LightningModule and access outputs via the module OR + 2. Cache data across train batch hooks inside the callback implementation to post-process in this hook. + """ pass def on_validation_epoch_start(self, trainer: 'pl.Trainer', pl_module: 'pl.LightningModule') -> None: diff --git a/pytorch_lightning/core/hooks.py b/pytorch_lightning/core/hooks.py index bebd1edd8e685..eed196a6dba55 100644 --- a/pytorch_lightning/core/hooks.py +++ b/pytorch_lightning/core/hooks.py @@ -238,6 +238,11 @@ def on_train_epoch_start(self) -> None: def on_train_epoch_end(self, unused: Optional = None) -> None: """ Called in the training loop at the very end of the epoch. + + To access all batch outputs at the end of the epoch, either: + 1. Implement `training_epoch_end` in the LightningModule OR + 2. Cache data across steps on attribute(s) of the LightningModule + and access them in this hook """ def on_validation_epoch_start(self) -> None: From 9888e03eaf9eee9ce64ec0f811e8db1c0ecf14fc Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Wed, 5 May 2021 21:54:39 +0200 Subject: [PATCH 2/3] Apply suggestions from code review --- pytorch_lightning/callbacks/base.py | 2 +- pytorch_lightning/core/hooks.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pytorch_lightning/callbacks/base.py b/pytorch_lightning/callbacks/base.py index 2f3314fdb51c6..67efec6e0b1fe 100644 --- a/pytorch_lightning/callbacks/base.py +++ b/pytorch_lightning/callbacks/base.py @@ -104,7 +104,7 @@ def on_train_epoch_end( """Called when the train epoch ends. To access all batch outputs at the end of the epoch, either: - 1. Implement `training_epoch_end` in the LightningModule and access outputs via the module OR + 1. Implement `training_epoch_end` in the `LightningModule` and access outputs via the module OR 2. Cache data across train batch hooks inside the callback implementation to post-process in this hook. """ pass diff --git a/pytorch_lightning/core/hooks.py b/pytorch_lightning/core/hooks.py index eed196a6dba55..2ec4d4990e9b6 100644 --- a/pytorch_lightning/core/hooks.py +++ b/pytorch_lightning/core/hooks.py @@ -241,8 +241,7 @@ def on_train_epoch_end(self, unused: Optional = None) -> None: To access all batch outputs at the end of the epoch, either: 1. Implement `training_epoch_end` in the LightningModule OR - 2. Cache data across steps on attribute(s) of the LightningModule - and access them in this hook + 2. Cache data across steps on the attribute(s) of the `LightningModule` and access them in this hook """ def on_validation_epoch_start(self) -> None: From 59842470d01cbdec93d1ec4ca5054dd501ee8ccb Mon Sep 17 00:00:00 2001 From: ananthsub Date: Wed, 5 May 2021 14:07:37 -0700 Subject: [PATCH 3/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adrian Wälchli --- pytorch_lightning/callbacks/base.py | 1 + pytorch_lightning/core/hooks.py | 1 + 2 files changed, 2 insertions(+) diff --git a/pytorch_lightning/callbacks/base.py b/pytorch_lightning/callbacks/base.py index 67efec6e0b1fe..f2647fc8c8d54 100644 --- a/pytorch_lightning/callbacks/base.py +++ b/pytorch_lightning/callbacks/base.py @@ -104,6 +104,7 @@ def on_train_epoch_end( """Called when the train epoch ends. To access all batch outputs at the end of the epoch, either: + 1. Implement `training_epoch_end` in the `LightningModule` and access outputs via the module OR 2. Cache data across train batch hooks inside the callback implementation to post-process in this hook. """ diff --git a/pytorch_lightning/core/hooks.py b/pytorch_lightning/core/hooks.py index 2ec4d4990e9b6..f45df178a24ca 100644 --- a/pytorch_lightning/core/hooks.py +++ b/pytorch_lightning/core/hooks.py @@ -240,6 +240,7 @@ def on_train_epoch_end(self, unused: Optional = None) -> None: Called in the training loop at the very end of the epoch. To access all batch outputs at the end of the epoch, either: + 1. Implement `training_epoch_end` in the LightningModule OR 2. Cache data across steps on the attribute(s) of the `LightningModule` and access them in this hook """