def run(self):
device = self.model_config.torch_device()<EOL>learner = Learner(device, self.model.instantiate())<EOL>lr_schedule = interp.interpolate_series(self.start_lr, self.end_lr, self.num_it, self.interpolation)<EOL>if self.freeze:<EOL><INDENT>learner.model.freeze()<EOL><DEDENT>optimizer = self.optimizer_factory.instantiate(learner.model)<EOL>iterator = iter(self.source.train_loader())<EOL>metrics = learner.metrics() + [AveragingNamedMetric("<STR_LIT>")]<EOL>learner.train()<EOL>best_value = None<EOL>training_info = TrainingInfo(start_epoch_idx=<NUM_LIT:0>, metrics=metrics)<EOL>epoch_info = EpochInfo(<EOL>training_info, global_epoch_idx=<NUM_LIT:1>, batches_per_epoch=<NUM_LIT:1>, optimizer=optimizer<EOL>)<EOL>for iteration_idx, lr in enumerate(tqdm.tqdm(lr_schedule)):<EOL><INDENT>batch_info = BatchInfo(epoch_info, iteration_idx)<EOL>for param_group in optimizer.param_groups:<EOL><INDENT>param_group['<STR_LIT>'] = lr<EOL><DEDENT>try:<EOL><INDENT>data, target = next(iterator)<EOL><DEDENT>except StopIteration:<EOL><INDENT>iterator = iter(self.source.train_loader())<EOL>data, target = next(iterator)<EOL><DEDENT>learner.train_batch(batch_info, data, target)<EOL>batch_info['<STR_LIT>'] = lr<EOL>epoch_info.result_accumulator.calculate(batch_info)<EOL>current_value = epoch_info.result_accumulator.intermediate_value(self.metric)<EOL>final_metrics = {'<STR_LIT>': iteration_idx, self.metric: current_value, '<STR_LIT>': lr}<EOL>if best_value is None or current_value < best_value:<EOL><INDENT>best_value = current_value<EOL><DEDENT>if self.stop_dv and (np.isnan(current_value) or current_value > best_value * self.divergence_threshold):<EOL><INDENT>break<EOL><DEDENT>training_info.history.add(final_metrics)<EOL><DEDENT>frame = training_info.history.frame()<EOL>fig, ax = plt.subplots(<NUM_LIT:1>, <NUM_LIT:2>)<EOL>ax[<NUM_LIT:0>].plot(frame.index, frame.lr)<EOL>ax[<NUM_LIT:0>].set_title("<STR_LIT>")<EOL>ax[<NUM_LIT:0>].set_xlabel("<STR_LIT>")<EOL>ax[<NUM_LIT:0>].set_ylabel("<STR_LIT>")<EOL>if self.interpolation == '<STR_LIT>':<EOL><INDENT>ax[<NUM_LIT:0>].set_yscale("<STR_LIT>", nonposy='<STR_LIT>')<EOL><DEDENT>ax[<NUM_LIT:1>].plot(frame.lr, frame[self.metric], label=self.metric)<EOL>ax[<NUM_LIT:1>].set_title(self.metric)<EOL>ax[<NUM_LIT:1>].set_xlabel("<STR_LIT>")<EOL>ax[<NUM_LIT:1>].set_ylabel(self.metric)<EOL>if self.interpolation == '<STR_LIT>':<EOL><INDENT>ax[<NUM_LIT:1>].set_xscale("<STR_LIT>", nonposx='<STR_LIT>')<EOL><DEDENT>plt.show()<EOL>
Run the command with supplied configuration