Skip to content

Commit

Permalink
Fixes a bug that causes CSVLogger to overwrite version_0 when `ro…
Browse files Browse the repository at this point in the history
…ot_dir` is a relative path. (#17139)

Co-authored-by: Adrian Wälchli <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>

(cherry picked from commit a36af3f)
  • Loading branch information
water-vapor authored and Borda committed Jun 1, 2023
1 parent 877769a commit 7219482
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/lightning/fabric/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

-
- Fixed computing the next version folder in `CSVLogger` ([#17139](https://github.com/Lightning-AI/lightning/pull/17139))




## [2.0.2] - 2023-04-24
Expand Down
7 changes: 4 additions & 3 deletions src/lightning/fabric/loggers/csv_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ def _get_next_version(self) -> int:
return 0

existing_versions = []
for d in self._fs.listdir(root_dir, detail=False):
name = d[len(root_dir) + 1 :] # removes parent directories
if self._fs.isdir(d) and name.startswith("version_"):
for d in self._fs.listdir(root_dir):
full_path = d["name"]
name = os.path.basename(full_path)
if self._fs.isdir(full_path) and name.startswith("version_"):
existing_versions.append(int(name.split("_")[1]))

if len(existing_versions) == 0:
Expand Down
2 changes: 2 additions & 0 deletions src/lightning/pytorch/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- The `WandbLogger` no longer flattens dictionaries in the hyperparameters logged to the dashboard ([#17574](https://github.com/Lightning-AI/lightning/pull/17574))


- Fixed computing the next version folder in `CSVLogger` ([#17139](https://github.com/Lightning-AI/lightning/pull/17139))


## [2.0.2] - 2023-04-24

Expand Down
11 changes: 11 additions & 0 deletions tests/tests_fabric/loggers/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def test_file_logger_automatic_versioning(tmpdir):
assert logger.version == 2


def test_file_logger_automatic_versioning_relative_root_dir(tmpdir, monkeypatch):
"""Verify that automatic versioning works, when root_dir is given a relative path."""
root_dir = tmpdir.mkdir("exp")
logs_dir = root_dir.mkdir("logs")
logs_dir.mkdir("version_0")
logs_dir.mkdir("version_1")
monkeypatch.chdir(tmpdir)
logger = CSVLogger(root_dir="exp/logs", name="logs")
assert logger.version == 2


def test_file_logger_manual_versioning(tmpdir):
"""Verify that manual versioning works."""
root_dir = tmpdir.mkdir("exp")
Expand Down

0 comments on commit 7219482

Please sign in to comment.