pytorch_pfn_extras.handler.Handler#

class pytorch_pfn_extras.handler.Handler(logic, entry_runtime, options)#

Bases: BaseHandler

A set of callback functions to perform device-specific operations.

Parameters:
  • logic (Logic) – A logic.

  • entry_runtime (BaseRuntime) – A runtime object.

  • options (dict) –

    The configuration options.

    • 'eval_report_keys' (list of str):

      A list of names of outputs that are given as inputs of reporting.report after each evaluation step. Default is an empty list.

    • 'train_report_keys' (list of str):

      A list of names of outputs that are given as inputs of reporting.report after each training step. Default is an empty list.

Methods

__init__(logic, entry_runtime, options)

A set of callback functions to perform device-specific operations.

consume_options(options)

A method to update options of Handler.

eval_loop_begin(evaluator)

A method called before each evaluation step.

eval_loop_end(evaluator)

A method called after running all steps of the evaluation.

eval_post_step(evaluator, batch_idx, batch, ...)

A method called after each evaluation step.

eval_setup(evaluator, loader)

Called only once when starting a training run.

eval_step(evaluator, batch_idx, batch, ...)

Evaluation iteration.

train_cleanup(trainer)

A method called only once when compleing a training run.

train_epoch_begin(trainer, loader)

A method called when starting a new epoch.

train_epoch_end(trainer)

A method called when finishing an epoch.

train_post_step(trainer, batch_idx, batch, ...)

A method called after each training step.

train_setup(trainer, loader)

A method called only once when starting a training run.

train_step(trainer, batch_idx, batch, ...)

A training step.

train_validation_begin(trainer, evaluator)

A method called when starting a validation.

train_validation_end(trainer, evaluator)

A method called after validation.

__init__(logic, entry_runtime, options)#

A set of callback functions to perform device-specific operations.

Parameters:
  • logic (Logic) – A logic.

  • entry_runtime (BaseRuntime) – A runtime object.

  • options (dict) –

    The configuration options.

    • 'eval_report_keys' (list of str):

      A list of names of outputs that are given as inputs of reporting.report after each evaluation step. Default is an empty list.

    • 'train_report_keys' (list of str):

      A list of names of outputs that are given as inputs of reporting.report after each training step. Default is an empty list.

Return type:

None

consume_options(options)#

A method to update options of Handler.

Note that the given dict will be modified.

Parameters:

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

Return type:

None

eval_loop_end(evaluator)#

A method called after running all steps of the evaluation.

Parameters:

evaluator (Evaluator) – The evaluator.

Return type:

None

eval_post_step(evaluator, batch_idx, batch, outputs)#

A method called after each evaluation step.

Parameters:
  • evaluator (Evaluator) – The evaluator.

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

  • batch (dict of torch.Tensor) – Input tensors of this batch.

  • complete_fn (callable) – A callback function called after training step.

  • outputs (Any) –

Return type:

None

eval_setup(evaluator, loader)#

Called only once when starting a training run. When evaluator is not given, this method is not called.

Parameters:
  • evaluator (Evaluator) – The evaluator.

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

Return type:

None

eval_step(evaluator, batch_idx, batch, complete_fn)#

Evaluation iteration.

Parameters:
  • evaluator (Evaluator) – The evaluator.

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

  • batch (dict of torch.Tensor) – Input tensors of this batch.

  • complete_fn (callable) – A callback function called after training step.

Return type:

None

train_cleanup(trainer)#

A method called only once when compleing a training run.

Parameters:
  • trainer (Trainer) – The trainer that calls this method.

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

Return type:

None

train_epoch_begin(trainer, loader)#

A method called when starting a new epoch.

Parameters:
  • trainer (Trainer) – The trainer that calls this method.

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

Return type:

None

train_epoch_end(trainer)#

A method called when finishing an epoch.

Parameters:

trainer (Trainer) – The trainer that calls this method.

Return type:

None

train_post_step(trainer, batch_idx, batch, outputs)#

A method called after each training step.

Parameters:
  • trainer (Trainer) – The trainer that calls this method.

  • batch_idx (int) – Number of iterations

  • batch (dict of torch.Tensor) – Input tensors of this batch.

  • outputs (dict of torch.Tensor) – Output tensors of this batch.

Return type:

None

train_setup(trainer, loader)#

A method called only once when starting a training run.

Parameters:
  • trainer (Trainer) – The trainer that calls this method.

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

Return type:

None

train_step(trainer, batch_idx, batch, complete_fn)#

A training step.

Parameters:
  • trainer (Trainer) – A trainer.

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

  • batch (dict of torch.Tensor) – Input tensors of this batch.

  • complete_fn (callable) – A callback function called after training step.

Return type:

None

train_validation_begin(trainer, evaluator)#

A method called when starting a validation.

Parameters:
Return type:

None

train_validation_end(trainer, evaluator)#

A method called after validation.

Parameters:
  • trainer (Trainer) – The trainer that calls this method.

  • evaluator (Evaluator) – The evaluator used for validation.

Return type:

None