instantiate_trainer#
- torchrl.trainers.algorithms.configs.instantiate_trainer(cfg: DictConfig, *, overrides: Sequence[str] | None = None) Trainer[source]#
Instantiate
cfg.trainer, resuming fromcfg.resumewhen it is set.Without
resumethis ishydra.utils.instantiate()oncfg.trainerplus registration of the composed configuration on the trainer checkpoint. Withresumeset to a checkpoint or aCheckpointRotationdirectory,resume_config()rebuilds the configuration from the saved one with the current command-line overrides on top; the saved logger run is reattached before the logger is constructed (W&B resumes the saved id withresume="must", CSV and TensorBoard keep the saved directory); checkpoints keep accumulating in the resumed rotation directory unlesscheckpoint_rotation.directoryis overridden; andload_from_file()restores the trainer state.- Parameters:
cfg (DictConfig) – the composed Hydra configuration. It must hold a
trainernode and may holdresume.overrides (Sequence[str], optional) – command-line overrides applied over the saved configuration. Defaults to the task overrides of the current Hydra run, or none outside a Hydra application.
- Returns:
The instantiated trainer, restored from the checkpoint when resuming.
Examples
>>> @hydra.main(config_path="config", config_name="config", version_base="1.3") ... def main(cfg): ... trainer = instantiate_trainer(cfg) ... with trainer.stop_on_signal(): ... trainer.train()