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, profile=None, **kwargs)#

Creates a trainer object.

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

  • optimizers (Union[Optimizer, Mapping[str, 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[Union[extension.ExtensionLike, extension.ExtensionEntry]]]) – 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[BaseLogic]) – A logic object. If None is given, an logic object is instantiated from the default logic class.

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

  • handler_class (Optional[Type[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.

  • profile (Optional[profile]) – A torch.profiler.profile object to collect the performance metrics.

  • kwargs (Any) –

Return type:

Trainer