def run(self):
device = self.model_config.torch_device()<EOL>learner = api.Learner(device, self.model_factory.instantiate(), self.max_grad_norm)<EOL>optimizer = self.optimizer_factory.instantiate(learner.model)<EOL>callbacks = self.gather_callbacks(optimizer)<EOL>metrics = learner.metrics()<EOL>training_info = self.resume_training(learner, callbacks, metrics)<EOL>training_info.on_train_begin()<EOL>if training_info.optimizer_initial_state:<EOL><INDENT>optimizer.load_state_dict(training_info.optimizer_initial_state)<EOL><DEDENT>for global_epoch_idx in range(training_info.start_epoch_idx + <NUM_LIT:1>, self.epochs + <NUM_LIT:1>):<EOL><INDENT>epoch_info = api.EpochInfo(<EOL>training_info=training_info,<EOL>global_epoch_idx=global_epoch_idx,<EOL>batches_per_epoch=self.source.train_iterations_per_epoch(),<EOL>optimizer=optimizer<EOL>)<EOL>learner.run_epoch(epoch_info, self.source)<EOL>self.storage.checkpoint(epoch_info, learner.model)<EOL><DEDENT>training_info.on_train_end()<EOL>return training_info<EOL>
Run the command with supplied configuration