pytorch_pfn_extras.handler.ClousureLogic#
- class pytorch_pfn_extras.handler.ClousureLogic(model_name='main', options=None)#
Bases:
LogicA set of methods that defines the training logic.
- Parameters:
model_name (str) – Name of the model. Default is
'main'.options (dict, optional) –
The configuration options.
'backward_outputs'(list of str):A list of names of outputs that require compution of the gradient.
'autocast'(bool or dict):If
True,torch.autocastis enabled, using{"enabled": True, "device_type": "cuda"}as autocast options. The default isFalsewhich corresponds to the following options{"enabled": False, "device_type": "cuda"}. If dict, options are passed totorch.autocast.
'grad_scaler'(torch.cuda.amp.GradScaler):A gradient scaler that outputs are applied to.
Methods
__init__([model_name, options])A set of methods that defines the training logic.
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 model forward and backward passes and performs an optimization step.
train_step_optimizers(models, optimizers, ...)In clousure mode, the stepping of the optimizer cannot be changed.
train_validation_begin(models)A method called when starting a validation.
train_validation_end(models)A method called when the validation completes.
- 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
- train_step(models, optimizers, batch_idx, batch)#
A method invokes the model forward and backward passes and performs an optimization step.
- 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:
- train_step_optimizers(models, optimizers, batch_idx)#
In clousure mode, the stepping of the optimizer cannot be changed.
If you want to change the stepping of the optimizer, please use the normal Logic class.
- Parameters:
optimizers (dict of torch.optim.Optimizer) – The optimizers.
batch_idx (int) – Number of steps already finished.
models (Mapping[str, Module]) –
- Return type:
None