コード例 #1
0
ファイル: checkpoint.py プロジェクト: yubozuzu123/catalyst
    def on_exception(self, runner: "IRunner"):
        """
        Expection handler.

        Args:
            runner: current runner

        """
        exception = runner.exception
        if not is_exception(exception):
            return

        if runner.device.type == "xla":
            from torch_xla.core.xla_model import save
        else:
            from torch import save

        try:
            checkpoint = _pack_runner(runner)
            suffix = self._get_checkpoint_suffix(checkpoint)
            suffix = f"{suffix}.exception_{exception.__class__.__name__}"
            save_checkpoint(
                logdir=Path(f"{runner.logdir}/checkpoints/"),
                checkpoint=checkpoint,
                suffix=suffix,
                is_best=False,
                is_last=False,
                saver_fn=save,
            )
            metrics = self.metrics
            metrics[suffix] = runner.valid_metrics
            self._save_metric(runner.logdir, metrics)
        except Exception:  # noqa: S110
            pass
コード例 #2
0
    def on_exception(self, runner: "IRunner"):
        """Notify about raised ``Exception``."""
        if self.log_on_exception:
            exception = runner.exception
            if is_exception(exception) and not isinstance(
                    exception, KeyboardInterrupt):
                text = (f"`{type(exception).__name__}` exception was raised:\n"
                        f"{exception}")

                self._send_text(text)
コード例 #3
0
ファイル: logging.py プロジェクト: hakanaku1234/catalyst-1
    def on_exception(self, runner: "IRunner"):
        """Called if an Exception was raised."""
        exception = runner.exception
        if not is_exception(exception):
            return

        if isinstance(exception, KeyboardInterrupt):
            if self.tqdm is not None:
                self.tqdm.write("Early exiting")
            runner.need_exception_reraise = False
コード例 #4
0
    def on_exception(self, runner: "IRunner"):
        """Called if an Exception was raised."""
        exception = runner.exception
        if not is_exception(exception):
            return

        if isinstance(exception, KeyboardInterrupt):
            if self.tqdm is not None:
                self.tqdm.write("Keyboard Interrupt")
                self.tqdm.clear()
                self.tqdm.close()
                self.tqdm = None