def on_epoch_end(self, state: _State) -> None: if state.stage_name.startswith("infer"): return score = state.valid_metrics[self.metric] if self.best_score is None: self.best_score = score if self.is_better(score, self.best_score): self.num_bad_epochs = 0 self.best_score = score else: self.num_bad_epochs += 1 if self.num_bad_epochs >= self.patience: print(f"Early stop at {state.epoch} epoch") state.need_early_stop = True
def on_batch_end(self, state: _State): if state.loader_step >= self.num_batch_steps: state.need_early_stop = True
def on_epoch_end(self, state: _State): if state.epoch >= self.num_epoch_steps: state.need_early_stop = True