avalanche.core

The core module offers fundamental utilities (classes and data structures) that can be used by inner Avalanche modules. As for now, it contains only the Strategy Callbacks definition that can be used by the training module for defining new continual learning strategies and by the evaluation module for defining new evaluation plugin metrics.

Module Contents

Classes

StrategyCallbacks

Strategy callbacks provide access before/after each phase of the training

avalanche.core.CallbackResult
class avalanche.core.StrategyCallbacks[source]

Bases: Generic[CallbackResult], abc.ABC

Strategy callbacks provide access before/after each phase of the training and evaluation loops. Subclasses can override the desired callbacks to customize the loops. In Avalanche, callbacks are used by StrategyPlugin to implement continual strategies, and StrategyLogger for automatic logging.

For each method of the training and evaluation loops, StrategyCallbacks provide two functions before_{method} and after_{method}, called before and after the method, respectively.

As a reminder, BaseStrategy loops follow the structure shown below:

Training loop The training loop is organized as follows:

train
    train_exp  # for each experience
        adapt_train_dataset
        train_dataset_adaptation
        make_train_dataloader
        train_epoch  # for each epoch
            # forward
            # backward
            # model update

Evaluation loop The evaluation loop is organized as follows:

eval
    eval_exp  # for each experience
        adapt_eval_dataset
        eval_dataset_adaptation
        make_eval_dataloader
        eval_epoch  # for each epoch
            # forward
            # backward
            # model update

Initialize self. See help(type(self)) for accurate signature.

before_training(self, *args, **kwargs) CallbackResult[source]

Called before train by the BaseStrategy.

before_training_exp(self, *args, **kwargs) CallbackResult[source]

Called before train_exp by the BaseStrategy.

before_train_dataset_adaptation(self, *args, **kwargs) CallbackResult[source]

Called before train_dataset_adapatation by the BaseStrategy.

after_train_dataset_adaptation(self, *args, **kwargs) CallbackResult[source]

Called after train_dataset_adapatation by the BaseStrategy.

before_training_epoch(self, *args, **kwargs) CallbackResult[source]

Called before train_epoch by the BaseStrategy.

before_training_iteration(self, *args, **kwargs) CallbackResult[source]

Called before the start of a training iteration by the BaseStrategy.

before_forward(self, *args, **kwargs) CallbackResult[source]

Called before model.forward() by the BaseStrategy.

after_forward(self, *args, **kwargs) CallbackResult[source]

Called after model.forward() by the BaseStrategy.

before_backward(self, *args, **kwargs) CallbackResult[source]

Called before criterion.backward() by the BaseStrategy.

after_backward(self, *args, **kwargs) CallbackResult[source]

Called after criterion.backward() by the BaseStrategy.

after_training_iteration(self, *args, **kwargs) CallbackResult[source]

Called after the end of a training iteration by the BaseStrategy.

before_update(self, *args, **kwargs) CallbackResult[source]

Called before optimizer.update() by the BaseStrategy.

after_update(self, *args, **kwargs) CallbackResult[source]

Called after optimizer.update() by the BaseStrategy.

after_training_epoch(self, *args, **kwargs) CallbackResult[source]

Called after train_epoch by the BaseStrategy.

after_training_exp(self, *args, **kwargs) CallbackResult[source]

Called after train_exp by the BaseStrategy.

after_training(self, *args, **kwargs) CallbackResult[source]

Called after train by the BaseStrategy.

before_eval(self, *args, **kwargs) CallbackResult[source]

Called before eval by the BaseStrategy.

before_eval_dataset_adaptation(self, *args, **kwargs) CallbackResult[source]

Called before eval_dataset_adaptation by the BaseStrategy.

after_eval_dataset_adaptation(self, *args, **kwargs) CallbackResult[source]

Called after eval_dataset_adaptation by the BaseStrategy.

before_eval_exp(self, *args, **kwargs) CallbackResult[source]

Called before eval_exp by the BaseStrategy.

after_eval_exp(self, *args, **kwargs) CallbackResult[source]

Called after eval_exp by the BaseStrategy.

after_eval(self, *args, **kwargs) CallbackResult[source]

Called after eval by the BaseStrategy.

before_eval_iteration(self, *args, **kwargs) CallbackResult[source]

Called before the start of a training iteration by the BaseStrategy.

before_eval_forward(self, *args, **kwargs) CallbackResult[source]

Called before model.forward() by the BaseStrategy.

after_eval_forward(self, *args, **kwargs) CallbackResult[source]

Called after model.forward() by the BaseStrategy.

after_eval_iteration(self, *args, **kwargs) CallbackResult[source]

Called after the end of an iteration by the BaseStrategy.