clarena.callbacks.pylogger

The submodule in callbacks for PyloggerCallback.

 1r"""
 2The submodule in `callbacks` for `PyloggerCallback`.
 3"""
 4
 5__all__ = ["PyloggerCallback"]
 6
 7import logging
 8
 9from lightning import Callback, Trainer
10
11from clarena.cl_algorithms import CLAlgorithm
12
13# always get logger for built-in logging in each module
14pylogger = logging.getLogger(__name__)
15
16
17class PyloggerCallback(Callback):
18    r"""Pylogger Callback provides additional logging for during continual learning progress.
19
20    Put logging messages here if you don't want to mess up the `CLAlgorithm` (`LightningModule`) with a huge amount of logging codes.
21    """
22
23    def on_fit_start(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
24        r"""Log messages for the start of training task."""
25        pylogger.info("Start training task %s!", pl_module.task_id)
26
27    def on_train_end(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
28        r"""Log messages for the end of training task."""
29        pylogger.info("Finish training task %s!", pl_module.task_id)
30
31    def on_test_start(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
32        r"""Log messages for the start of testing task."""
33        pylogger.info(
34            "Start testing task %s on all previous and current tasks!",
35            pl_module.task_id,
36        )
37
38    def on_test_end(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
39        r"""Log messages for the end of testing task."""
40        pylogger.info(
41            "Finish testing task %s on all previous and current tasks!",
42            pl_module.task_id,
43        )
class PyloggerCallback(lightning.pytorch.callbacks.callback.Callback):
18class PyloggerCallback(Callback):
19    r"""Pylogger Callback provides additional logging for during continual learning progress.
20
21    Put logging messages here if you don't want to mess up the `CLAlgorithm` (`LightningModule`) with a huge amount of logging codes.
22    """
23
24    def on_fit_start(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
25        r"""Log messages for the start of training task."""
26        pylogger.info("Start training task %s!", pl_module.task_id)
27
28    def on_train_end(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
29        r"""Log messages for the end of training task."""
30        pylogger.info("Finish training task %s!", pl_module.task_id)
31
32    def on_test_start(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
33        r"""Log messages for the start of testing task."""
34        pylogger.info(
35            "Start testing task %s on all previous and current tasks!",
36            pl_module.task_id,
37        )
38
39    def on_test_end(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
40        r"""Log messages for the end of testing task."""
41        pylogger.info(
42            "Finish testing task %s on all previous and current tasks!",
43            pl_module.task_id,
44        )

Pylogger Callback provides additional logging for during continual learning progress.

Put logging messages here if you don't want to mess up the CLAlgorithm (LightningModule) with a huge amount of logging codes.

def on_fit_start( self, trainer: lightning.pytorch.trainer.trainer.Trainer, pl_module: clarena.cl_algorithms.CLAlgorithm) -> None:
24    def on_fit_start(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
25        r"""Log messages for the start of training task."""
26        pylogger.info("Start training task %s!", pl_module.task_id)

Log messages for the start of training task.

def on_train_end( self, trainer: lightning.pytorch.trainer.trainer.Trainer, pl_module: clarena.cl_algorithms.CLAlgorithm) -> None:
28    def on_train_end(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
29        r"""Log messages for the end of training task."""
30        pylogger.info("Finish training task %s!", pl_module.task_id)

Log messages for the end of training task.

def on_test_start( self, trainer: lightning.pytorch.trainer.trainer.Trainer, pl_module: clarena.cl_algorithms.CLAlgorithm) -> None:
32    def on_test_start(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
33        r"""Log messages for the start of testing task."""
34        pylogger.info(
35            "Start testing task %s on all previous and current tasks!",
36            pl_module.task_id,
37        )

Log messages for the start of testing task.

def on_test_end( self, trainer: lightning.pytorch.trainer.trainer.Trainer, pl_module: clarena.cl_algorithms.CLAlgorithm) -> None:
39    def on_test_end(self, trainer: Trainer, pl_module: CLAlgorithm) -> None:
40        r"""Log messages for the end of testing task."""
41        pylogger.info(
42            "Finish testing task %s on all previous and current tasks!",
43            pl_module.task_id,
44        )

Log messages for the end of testing task.