def test_name(tmpdir):
    """Verify names of loggers are concatenated properly."""
    logger1 = CSVLogger(tmpdir, name="foo")
    logger2 = CSVLogger(tmpdir, name="bar")
    logger3 = CSVLogger(tmpdir, name="foo")
    logger4 = CSVLogger(tmpdir, name="baz")
    loggers = [logger1, logger2, logger3, logger4]
    name = _name([])
    assert name == ""
    name = _name([logger3])
    assert name == "foo"
    name = _name(loggers)
    assert name == "foo_bar_baz"
    name = _name(loggers, "-")
    assert name == "foo-bar-baz"
Exemple #2
0
    def __resolve_ckpt_dir(self, trainer: "pl.Trainer") -> None:
        """Determines model checkpoint save directory at runtime. Reference attributes from the trainer's logger to
        determine where to save checkpoints. The path for saving weights is set in this priority:

        1.  The ``ModelCheckpoint``'s ``dirpath`` if passed in
        2.  The ``Trainer``'s ``weights_saved_path`` if passed in (deprecated)
        3.  The ``Logger``'s ``log_dir`` if the trainer has loggers
        4.  The ``Trainer``'s ``default_root_dir`` if the trainer has no loggers

        The path gets extended with subdirectory "checkpoints".
        """
        if self.dirpath is not None:
            # short circuit if dirpath was passed to ModelCheckpoint
            return

        # TODO: Remove weights_save_path logic here in v1.8
        if trainer._weights_save_path_internal != trainer.default_root_dir:
            # the user has changed weights_save_path
            ckpt_path = os.path.join(trainer._weights_save_path_internal,
                                     "checkpoints")
        elif trainer.loggers:
            if len(trainer.loggers) == 1:
                assert trainer.logger is not None
                save_dir = trainer.logger.save_dir or trainer.default_root_dir
            else:
                save_dir = trainer.default_root_dir

            name = _name(trainer.loggers)
            version = _version(trainer.loggers)
            version = version if isinstance(version,
                                            str) else f"version_{version}"

            ckpt_path = os.path.join(save_dir, str(name), version,
                                     "checkpoints")
        else:
            # if no loggers, use default_root_dir
            ckpt_path = os.path.join(trainer.default_root_dir, "checkpoints")

        ckpt_path = trainer.strategy.broadcast(ckpt_path)

        self.dirpath = ckpt_path
Exemple #3
0
    def __resolve_ckpt_dir(self, trainer: "pl.Trainer") -> None:
        """Determines model checkpoint save directory at runtime. References attributes from the trainer's logger
        to determine where to save checkpoints. The base path for saving weights is set in this priority:

        1.  Checkpoint callback's path (if passed in)
        2.  The default_root_dir from trainer if trainer has no logger
        3.  The weights_save_path from trainer, if user provides it (deprecated)
        4.  User provided weights_saved_path

        The base path gets extended with logger name and version (if these are available)
        and subfolder "checkpoints".
        """
        if self.dirpath is not None:
            return  # short circuit

        # TODO: Remove weights_save_path logic here in v1.8
        if trainer.loggers:
            if trainer._weights_save_path_internal != trainer.default_root_dir:
                # the user has changed weights_save_path, it overrides anything
                save_dir = trainer._weights_save_path_internal
            elif len(trainer.loggers) == 1:
                save_dir = trainer.logger.save_dir or trainer.default_root_dir
            else:
                save_dir = trainer.default_root_dir

            name = _name(trainer.loggers)
            version = _version(trainer.loggers)
            version = version if isinstance(version,
                                            str) else f"version_{version}"

            ckpt_path = os.path.join(save_dir, str(name), version,
                                     "checkpoints")
        else:
            ckpt_path = os.path.join(trainer._weights_save_path_internal,
                                     "checkpoints")

        ckpt_path = trainer.strategy.broadcast(ckpt_path)

        self.dirpath = ckpt_path