    def maybe_save_checkpoint(
        self,
        trainer: Trainer,
        num_epochs_completed: int,
        num_batches_in_epoch_completed: int,
    ) -> bool:
        """
        Figures out whether we need to save a checkpoint, and does so if necessary.
        """
        end_of_epoch = num_batches_in_epoch_completed == 0
        if num_epochs_completed == self._last_save_num_epochs_completed:
            last_save_num_batches_in_epoch_completed = (
                self._last_save_num_batches_in_epoch_completed
            )
        else:
            last_save_num_batches_in_epoch_completed = 0

        should_save = (
            (end_of_epoch and self._save_completed_epochs)
            or (
                self._save_every_num_seconds is not None
                and (time.time() - self._last_save_time >= self._save_every_num_seconds)
            )
            or (
                self._save_every_num_batches is not None
                and (
                    num_batches_in_epoch_completed - last_save_num_batches_in_epoch_completed
                    >= self._save_every_num_batches
                )
            )
        )

        if should_save:
            self.save_checkpoint(trainer)
            return True
        return False
Figures out whether we need to save a checkpoint, and does so if necessary.
allennlp/training/checkpointer.py