def METHOD_NAME(self, script_globals):
    from lightning.pytorch import Trainer
    from lightning.pytorch.cli import LightningCLI
    for v in script_globals.values():
        if isinstance(v, LightningCLI):
            trainer = v.trainer
            break
        if isinstance(v, Trainer):
            trainer = v
            break
    else:
        raise RuntimeError("No trainer instance found.")
    self.monitor = trainer.checkpoint_callback.monitor
    if trainer.checkpoint_callback.best_model_score:
        self.best_model_path = Path(trainer.checkpoint_callback.best_model_path)
        self.best_model_score = float(trainer.checkpoint_callback.best_model_score)
    else:
        self.best_model_path = Path(trainer.checkpoint_callback.last_model_path)
    self.has_finished = True