From fb11c5fa79f6ec661eb584b2bc59dcc43041548d Mon Sep 17 00:00:00 2001 From: mwip Date: Fri, 23 Feb 2024 10:39:23 +0100 Subject: [PATCH 1/2] Make `CSVLogger(name: ...)` optional `str` This patch adds `Optional` typing to the `name` parameter in `CSVLogger` reflecting the actual behavior. This increases coherence with other loggers and helps with type checking. Additionally documentation is improved. This patch does NOT change the underlying behavior. Hence no additional tests were added. Tests already can be found in tests/tests_pytorch/loggers/test_csv.py#L85-L90 Closes https://github.com/Lightning-AI/pytorch-lightning/issues/19433 --- src/lightning/pytorch/loggers/csv_logs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lightning/pytorch/loggers/csv_logs.py b/src/lightning/pytorch/loggers/csv_logs.py index d86249bd9ff6f..d771af91e8d25 100644 --- a/src/lightning/pytorch/loggers/csv_logs.py +++ b/src/lightning/pytorch/loggers/csv_logs.py @@ -82,7 +82,8 @@ class CSVLogger(Logger, FabricCSVLogger): Args: save_dir: Save directory - name: Experiment name. Defaults to ``'lightning_logs'``. + name: Experiment name, optional. Defaults to ``'lightning_logs'``. If name is `None`, log + (versions) stored to the save dir directly. version: Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. prefix: A string to put at the beginning of metric keys. @@ -95,7 +96,7 @@ class CSVLogger(Logger, FabricCSVLogger): def __init__( self, save_dir: _PATH, - name: str = "lightning_logs", + name: Optional[str] = "lightning_logs", version: Optional[Union[int, str]] = None, prefix: str = "", flush_logs_every_n_steps: int = 100, From 45280259ccb1b8087c749e444140e01613d910f6 Mon Sep 17 00:00:00 2001 From: mwip Date: Fri, 23 Feb 2024 14:42:12 +0100 Subject: [PATCH 2/2] Apply `name: Optional[str]` in fabric; fix typos --- src/lightning/fabric/loggers/csv_logs.py | 5 +++-- src/lightning/pytorch/loggers/csv_logs.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lightning/fabric/loggers/csv_logs.py b/src/lightning/fabric/loggers/csv_logs.py index 6079c61d29cd2..9e82041b528c1 100644 --- a/src/lightning/fabric/loggers/csv_logs.py +++ b/src/lightning/fabric/loggers/csv_logs.py @@ -37,7 +37,8 @@ class CSVLogger(Logger): Args: root_dir: The root directory in which all your experiments with different names and versions will be stored. - name: Experiment name. Defaults to ``'lightning_logs'``. + name: Experiment name. Defaults to ``'lightning_logs'``. If name is ``None``, logs + (versions) will be stored to the save dir directly. version: Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. If the version is specified, and the directory already contains a metrics file for that version, it will be @@ -60,7 +61,7 @@ class CSVLogger(Logger): def __init__( self, root_dir: _PATH, - name: str = "lightning_logs", + name: Optional[str] = "lightning_logs", version: Optional[Union[int, str]] = None, prefix: str = "", flush_logs_every_n_steps: int = 100, diff --git a/src/lightning/pytorch/loggers/csv_logs.py b/src/lightning/pytorch/loggers/csv_logs.py index d771af91e8d25..fdaeb18e9199f 100644 --- a/src/lightning/pytorch/loggers/csv_logs.py +++ b/src/lightning/pytorch/loggers/csv_logs.py @@ -82,8 +82,8 @@ class CSVLogger(Logger, FabricCSVLogger): Args: save_dir: Save directory - name: Experiment name, optional. Defaults to ``'lightning_logs'``. If name is `None`, log - (versions) stored to the save dir directly. + name: Experiment name, optional. Defaults to ``'lightning_logs'``. If name is ``None``, logs + (versions) will be stored to the save dir directly. version: Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. prefix: A string to put at the beginning of metric keys.