def _adjust_learning_rate(self, has_improved: bool, lr_decay_param_reset: bool, lr_decay_opt_states_reset: str):
        """
        Adjusts the optimizer learning rate if required.
        """
        if self.optimizer_config.lr_scheduler is not None:
            if issubclass(type(self.optimizer_config.lr_scheduler), lr_scheduler.AdaptiveLearningRateScheduler):
                lr_adjusted = self.optimizer_config.lr_scheduler.new_evaluation_result(has_improved)  # type: ignore
            else:
                lr_adjusted = False
            if lr_adjusted and not has_improved:
                if lr_decay_param_reset:
                    logger.info("Loading parameters from last best checkpoint: %d",
                                self.state.best_checkpoint)
                    self.model.load_params_from_file(self.best_params_fname)
                if lr_decay_opt_states_reset == C.LR_DECAY_OPT_STATES_RESET_INITIAL:
                    logger.info("Loading initial optimizer states")
                    self.model.load_optimizer_states(os.path.join(self.model.output_dir, C.OPT_STATES_INITIAL))
                elif lr_decay_opt_states_reset == C.LR_DECAY_OPT_STATES_RESET_BEST:
                    logger.info("Loading optimizer states from best checkpoint: %d",
                                self.state.best_checkpoint)
                    self.model.load_optimizer_states(os.path.join(self.model.output_dir, C.OPT_STATES_BEST))
def _adjust_learning_rate ( self , has_improved : bool , lr_decay_param_reset : bool , lr_decay_opt_states_reset : str ) : if self . optimizer_config . lr_scheduler is not None : if issubclass ( type ( self . optimizer_config . lr_scheduler ) , lr_scheduler . AdaptiveLearningRateScheduler ) : lr_adjusted = self . optimizer_config . lr_scheduler . new_evaluation_result ( has_improved ) else : lr_adjusted = False if lr_adjusted and not has_improved : if lr_decay_param_reset : logger . info ( "Loading parameters from last best checkpoint: %d" , self . state . best_checkpoint ) self . model . load_params_from_file ( self . best_params_fname ) if lr_decay_opt_states_reset == C . LR_DECAY_OPT_STATES_RESET_INITIAL : logger . info ( "Loading initial optimizer states" ) self . model . load_optimizer_states ( os . path . join ( self . model . output_dir , C . OPT_STATES_INITIAL ) ) elif lr_decay_opt_states_reset == C . LR_DECAY_OPT_STATES_RESET_BEST : logger . info ( "Loading optimizer states from best checkpoint: %d" , self . state . best_checkpoint ) self . model . load_optimizer_states ( os . path . join ( self . model . output_dir , C . OPT_STATES_BEST ) )
Adjusts the optimizer learning rate if required.