pytorch_pfn_extras.engine.create_trainer

pytorch_pfn_extras.engine.create_trainer(models, optimizers, max_epochs, *, extensions=None, out_dir='result', stop_trigger=None, writer=None, evaluator=None, device='cpu', logic=None, transform_model=<function default_transform_model>, handler_class=None, options=None, runtime_options=None)

Creates a trainer object.

Parameters
  • models (Union[torch.nn.modules.module.Module, Mapping[str, torch.nn.modules.module.Module]]) – Map of string to Module or an actual Module.

  • optimizers (Union[torch.optim.optimizer.Optimizer, Mapping[str, torch.optim.optimizer.Optimizer]]) – Map of string to Optimizer or an actual Optimizer.

  • max_epochs (int) – Number of epochs in the whole training loop. Ignored if stop_trigger is passed as a kwarg.

  • extensions (Optional[Sequence[training.Extension]]) – List of extensions to be registered to the trainer.

  • out_dir (str) – Output directory (default: result).

  • stop_trigger (trigger, optional) – Trigger that can be consulted to determine wether training has concluded. The default is an interval trigger set to max_epochs

  • writer (Optional[writing.Writer]) – Writer that can be used by extensions to write data to custom filesystems.

  • evaluator (Optional[Union[Evaluator, Tuple[Evaluator, TriggerLike], Mapping[str, Union[Evaluator, Tuple[Evaluator, TriggerLike]]]]]) – Evaluator that is used in evaluation phase. If None is given, the evaluation is skipped. Evaluators can be created with pytorch_pfn_extras.engine.create_evaluator().

  • device (str or torch.device) – Device name used for selecting a corresponding runtime class.

  • logic (Optional[pytorch_pfn_extras.handler._logic.Logic]) – A logic object. If None is given, an logic object is instantiated from the default logic class.

  • transform_model (Callable[[str, torch.nn.modules.module.Module], torch.nn.modules.module.Module]) – A function to transform a model structure, often used to unwrap the a module from DDP module.

  • handler_class (Optional[Type[pytorch_pfn_extras.handler._handler.Handler]]) – A handler class that instantiates a handler object. If None is given, ppe.handler.Handler is used as a default handler class.

  • options (Optional[Dict[str, Any]]) – Options that are set to the handler and logic object. See the documentation of ppe.handler.Handler and ppe.handler.Logic for details.

  • runtime_options (Optional[Mapping[str, Any]]) – Options that are set to the runtime object. See the documentation of ppe.runtime.PyTorchRuntime for details.

Return type

Trainer