pytorch_pfn_extras.handler.BaseLogic#

class pytorch_pfn_extras.handler.BaseLogic(options=None)#

Bases: object

Methods

__init__([options])

consume_options(options)

A method to update options of Logic.

eval_step(models, batch_idx, batch)

A method for an evaluation step.

train_epoch_begin(models, epoch, loader)

A method called when starting a new epoch of training.

train_epoch_end(models, epoch)

A method called when completing an epoch of training.

train_step(models, optimizers, batch_idx, batch)

A method invokes the models forward and backward passes.

train_step_optimizers(models, optimizers, ...)

A method in charge of stepping the provided optimizers.

train_validation_begin(models)

A method called when starting a validation.

train_validation_end(models)

A method called when the validation completes.

Parameters:

options (Optional[Dict[str, Any]]) –

__init__(options=None)#
Parameters:

options (Optional[Dict[str, Any]]) –

consume_options(options)#

A method to update options of Logic.

Note that the given dict will be modified.

Parameters:

options (dict) – Option key-values to be set.

Return type:

None

eval_step(models, batch_idx, batch)#

A method for an evaluation step.

Parameters:
  • models (dict of torch.nn.Module) – The models.

  • batch_idx (int) – Number of steps already finished.

  • batch (torch.Tensor, list of torch.Tensor, dict of torch.Tensor) – Input tensors feeded to the model of the current step.

Return type:

Any

train_epoch_begin(models, epoch, loader)#

A method called when starting a new epoch of training.

Parameters:
  • epoch (int) – Number of epochs already finished.

  • models (dict of torch.nn.Module) – The models.

  • loader (torch.utils.data.DataLoader) – The data loder.

Return type:

None

train_epoch_end(models, epoch)#

A method called when completing an epoch of training.

Parameters:
  • epoch (int) – Number of epochs already finished.

  • models (dict of torch.nn.Module) – The models.

Return type:

None

train_step(models, optimizers, batch_idx, batch)#

A method invokes the models forward and backward passes.

Optimizing is left to train_step_optimizers since maybe the user would like to aggregate the gradients of several iterations.

Parameters:
  • models (dict of torch.nn.Module) – The models.

  • optimizers (dict of torch.optim.Optimizer) – The optimizers.

  • batch_idx (int) – Number of training steps already finished.

  • batch (torch.Tensor, list of torch.Tensor, dict of torch.Tensor) – Input tensors feeded to the model of the current step.

Return type:

Any

train_step_optimizers(models, optimizers, batch_idx)#

A method in charge of stepping the provided optimizers.

Parameters:
  • optimizers (dict of torch.optim.Optimizer) – The optimizers.

  • batch_idx (int) – Number of steps already finished.

  • models (Mapping[str, Module]) –

Return type:

None

train_validation_begin(models)#

A method called when starting a validation.

Parameters:

models (dict of torch.nn.Module) – The models.

Return type:

None

train_validation_end(models)#

A method called when the validation completes.

Parameters:

models (dict of torch.nn.Module) – The models.

Return type:

None