avalanche.training.templates.BaseSGDTemplate

class avalanche.training.templates.BaseSGDTemplate(model: ~torch.nn.modules.module.Module, optimizer: ~torch.optim.optimizer.Optimizer, train_mb_size: int = 1, train_epochs: int = 1, eval_mb_size: ~typing.Optional[int] = 1, device='cpu', plugins: ~typing.Optional[~typing.List[~avalanche.core.SupervisedPlugin]] = None, evaluator: ~avalanche.training.plugins.evaluation.EvaluationPlugin = <avalanche.training.plugins.evaluation.EvaluationPlugin object>, eval_every=-1, peval_mode='epoch')[source]

Base class for continual learning skeletons.

Training loop The training loop is organized as follows:

train
    train_exp  # for each experience

Evaluation loop The evaluation loop is organized as follows:

eval
    eval_exp  # for each experience
__init__(model: ~torch.nn.modules.module.Module, optimizer: ~torch.optim.optimizer.Optimizer, train_mb_size: int = 1, train_epochs: int = 1, eval_mb_size: ~typing.Optional[int] = 1, device='cpu', plugins: ~typing.Optional[~typing.List[~avalanche.core.SupervisedPlugin]] = None, evaluator: ~avalanche.training.plugins.evaluation.EvaluationPlugin = <avalanche.training.plugins.evaluation.EvaluationPlugin object>, eval_every=-1, peval_mode='epoch')[source]

Init.

Parameters
  • model – PyTorch model.

  • optimizer – PyTorch optimizer.

  • train_mb_size – mini-batch size for training.

  • train_epochs – number of training epochs.

  • eval_mb_size – mini-batch size for eval.

  • evaluator – (optional) instance of EvaluationPlugin for logging and metric computations. None to remove logging.

  • eval_every – the frequency of the calls to eval inside the training loop. -1 disables the evaluation. 0 means eval is called only at the end of the learning experience. Values >0 mean that eval is called every eval_every epochs and at the end of the learning experience.

  • peval_mode – one of {‘epoch’, ‘iteration’}. Decides whether the periodic evaluation during training should execute every eval_every epochs or iterations (Default=’epoch’).

Methods

__init__(model, optimizer[, train_mb_size, ...])

Init.

backward()

Run the backward pass.

criterion()

Compute loss function.

eval(exp_list, **kwargs)

Evaluate the current model on a series of experiences and returns the last recorded value for each metric.

eval_epoch(**kwargs)

Evaluation loop over the current self.dataloader.

forward()

Compute the model's output given the current mini-batch.

make_eval_dataloader(**kwargs)

Assign dataloader to self.dataloader.

make_optimizer(**kwargs)

Optimizer initialization.

make_train_dataloader(**kwargs)

Assign dataloader to self.dataloader.

model_adaptation([model])

Adapts the model to the current experience.

optimizer_step()

Execute the optimizer step (weights update).

stop_training()

Signals to stop training at the next iteration.

train(experiences[, eval_streams])

Training loop.

training_epoch(**kwargs)

Training epoch.

Attributes

is_eval

True if the strategy is in evaluation mode.

optimizer

PyTorch optimizer.

train_epochs

Number of training epochs.

train_mb_size

Training mini-batch size.

eval_mb_size

Eval mini-batch size.

evaluator

EvaluationPlugin used for logging and metric computations.

clock

Incremental counters for strategy events.

dataloader

Dataloader.

mbatch

Current mini-batch.

mb_output

Model's output computed on the current mini-batch.

loss

Loss of the current mini-batch.