2020-08-20 02:03:22 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2020-03-03 16:39:43 +00:00
|
|
|
r"""
|
2020-08-13 13:58:05 +00:00
|
|
|
Subclass this class and override any of the relevant hooks
|
2020-04-05 09:38:52 +00:00
|
|
|
|
2020-02-23 02:45:34 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import abc
|
|
|
|
|
|
|
|
|
|
|
|
class Callback(abc.ABC):
|
2020-03-03 16:39:43 +00:00
|
|
|
r"""
|
|
|
|
Abstract base class used to build new callbacks.
|
|
|
|
"""
|
2020-02-23 02:45:34 +00:00
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def setup(self, trainer, pl_module, stage: str):
|
2020-06-17 23:49:58 +00:00
|
|
|
"""Called when fit or test begins"""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def teardown(self, trainer, pl_module, stage: str):
|
2020-06-17 23:49:58 +00:00
|
|
|
"""Called when fit or test ends"""
|
|
|
|
pass
|
|
|
|
|
2020-02-27 22:21:51 +00:00
|
|
|
def on_init_start(self, trainer):
|
2020-03-03 04:51:32 +00:00
|
|
|
"""Called when the trainer initialization begins, model has not yet been set."""
|
2020-02-27 22:21:51 +00:00
|
|
|
pass
|
2020-02-26 04:17:27 +00:00
|
|
|
|
2020-02-27 22:21:51 +00:00
|
|
|
def on_init_end(self, trainer):
|
2020-03-03 04:51:32 +00:00
|
|
|
"""Called when the trainer initialization ends, model has not yet been set."""
|
2020-02-26 04:17:27 +00:00
|
|
|
pass
|
2020-02-23 02:45:34 +00:00
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_fit_start(self, trainer, pl_module):
|
2020-06-17 11:37:16 +00:00
|
|
|
"""Called when fit begins"""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_fit_end(self, trainer, pl_module):
|
2020-06-17 11:37:16 +00:00
|
|
|
"""Called when fit ends"""
|
|
|
|
pass
|
|
|
|
|
2020-04-24 00:46:18 +00:00
|
|
|
def on_sanity_check_start(self, trainer, pl_module):
|
|
|
|
"""Called when the validation sanity check starts."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_sanity_check_end(self, trainer, pl_module):
|
|
|
|
"""Called when the validation sanity check ends."""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_train_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
|
2020-08-08 11:58:18 +00:00
|
|
|
"""Called when the train batch begins."""
|
2020-08-06 00:01:30 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_train_batch_end(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
|
2020-08-08 11:58:18 +00:00
|
|
|
"""Called when the train batch ends."""
|
2020-08-06 00:01:30 +00:00
|
|
|
pass
|
|
|
|
|
2020-07-20 23:00:20 +00:00
|
|
|
def on_train_epoch_start(self, trainer, pl_module):
|
|
|
|
"""Called when the train epoch begins."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_train_epoch_end(self, trainer, pl_module):
|
|
|
|
"""Called when the train epoch ends."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_validation_epoch_start(self, trainer, pl_module):
|
|
|
|
"""Called when the val epoch begins."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_validation_epoch_end(self, trainer, pl_module):
|
|
|
|
"""Called when the val epoch ends."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_test_epoch_start(self, trainer, pl_module):
|
|
|
|
"""Called when the test epoch begins."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_test_epoch_end(self, trainer, pl_module):
|
|
|
|
"""Called when the test epoch ends."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_epoch_start(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the epoch begins."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_epoch_end(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the epoch ends."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_batch_start(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the training batch begins."""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_validation_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
|
2020-04-24 00:46:18 +00:00
|
|
|
"""Called when the validation batch begins."""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_validation_batch_end(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
|
2020-04-24 00:46:18 +00:00
|
|
|
"""Called when the validation batch ends."""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_test_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
|
2020-04-24 00:46:18 +00:00
|
|
|
"""Called when the test batch begins."""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_test_batch_end(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
|
2020-04-24 00:46:18 +00:00
|
|
|
"""Called when the test batch ends."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_batch_end(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the training batch ends."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_train_start(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the train begins."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_train_end(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the train ends."""
|
|
|
|
pass
|
|
|
|
|
2020-08-07 13:29:57 +00:00
|
|
|
def on_pretrain_routine_start(self, trainer, pl_module):
|
|
|
|
"""Called when the pretrain routine begins."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_pretrain_routine_end(self, trainer, pl_module):
|
|
|
|
"""Called when the pretrain routine ends."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_validation_end(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the validation loop ends."""
|
|
|
|
pass
|
|
|
|
|
2020-02-26 04:17:27 +00:00
|
|
|
def on_test_end(self, trainer, pl_module):
|
2020-02-23 02:45:34 +00:00
|
|
|
"""Called when the test ends."""
|
|
|
|
pass
|
2020-06-15 10:35:26 +00:00
|
|
|
|
|
|
|
def on_keyboard_interrupt(self, trainer, pl_module):
|
|
|
|
"""Called when the training is interrupted by KeyboardInterrupt."""
|