Conditionally saves a checkpoint. A checkpoint is saved if a `CheckpointManager` is available, and if the required number of steps has elapsed since the last checkpoint was saved (although this condition can be disabled by setting `check_interval=False`). Args: check_interval
(self, check_interval: bool = True)
| 541 | self.summary_manager.flush() |
| 542 | |
| 543 | def _maybe_save_checkpoint(self, check_interval: bool = True): |
| 544 | """Conditionally saves a checkpoint. |
| 545 | |
| 546 | A checkpoint is saved if a `CheckpointManager` is available, and if the |
| 547 | required number of steps has elapsed since the last checkpoint was saved |
| 548 | (although this condition can be disabled by setting `check_interval=False`). |
| 549 | |
| 550 | Args: |
| 551 | check_interval: Whether to check if the checkpoint interval has fully |
| 552 | elapsed. If `False`, a checkpoint is saved regardless of the elapsed |
| 553 | steps since the most recent checkpoint, unless no `checkpoint_manager` |
| 554 | was provided to `Controller.__init__`. |
| 555 | |
| 556 | Returns: |
| 557 | A boolean indicating whether a checkpoint was saved. |
| 558 | """ |
| 559 | if self.checkpoint_manager and self.checkpoint_manager.checkpoint_interval: |
| 560 | ckpt_path = self.checkpoint_manager.save( |
| 561 | checkpoint_number=self.global_step.numpy(), |
| 562 | check_interval=check_interval, |
| 563 | options=self._checkpoint_options) |
| 564 | if ckpt_path is not None: |
| 565 | _log(f"saved checkpoint to {ckpt_path}.") |
| 566 | return True |
| 567 | return False |
| 568 | |
| 569 | def _require(self, attribute, for_method): |
| 570 | """Utility method to raise an error if the given `attribute` is not set.""" |
no test coverage detected