Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing: make CSVLogger name optional str #19433

Closed
mwip opened this issue Feb 8, 2024 · 3 comments · Fixed by #19518
Closed

typing: make CSVLogger name optional str #19433

mwip opened this issue Feb 8, 2024 · 3 comments · Fixed by #19518
Labels
feature Is an improvement or enhancement logger: csv ver: 2.2.x

Comments

@mwip
Copy link
Contributor

mwip commented Feb 8, 2024

Bug description

Currently, lightning.pytorch.loggers.csv_logs.CSVLogger(name: str, ...) the parameter name of the CSVLogger ist typed as str.

name: str = "lightning_logs",

This contrasts other loggers, e.g. TensorBoardLogger or WandbLogger.

I suggest typing CSVLogger(name: Optional[str], ...) as it is ineed optional:

What version are you seeing the problem on?

master

How to reproduce the bug

import lightning

lightning.pytorch.loggers.csv_logs.CSVLogger("save_dir", name=None)
$ mypy test.py

Error messages and logs

test.py:3: error: Argument "name" to "CSVLogger" has incompatible type "None"; expected "str"  [arg-type]

cc @Borda

@mwip mwip added bug Something isn't working needs triage Waiting to be triaged by maintainers labels Feb 8, 2024
@awaelchli
Copy link
Contributor

@mwip Can you explain why the Optional annotation is needed?
Even if it was made optional, the logic would anyway require to set it to "lightning_logs":

if name is None:
    name = "lightning_logs"

So I would prefer to clearly indicate the default value and leave it as is.

@awaelchli awaelchli added logger: csv feature Is an improvement or enhancement and removed bug Something isn't working needs triage Waiting to be triaged by maintainers labels Feb 11, 2024
@mwip
Copy link
Contributor Author

mwip commented Feb 20, 2024

@awaelchli Forgive my confusion, but I'm not able to find the line you are referring to. Maybe you'd be able to link it?

Also, this seems to differ from the behavior of this minimal example:

import lightning

csv_logger1 = lightning.pytorch.loggers.csv_logs.CSVLogger(save_dir="save_dir")
csv_logger2 = lightning.pytorch.loggers.csv_logs.CSVLogger(save_dir="save_dir", name=None)
csv_logger3 = lightning.pytorch.loggers.csv_logs.CSVLogger(save_dir="save_dir", name="some_name")

print(f"{csv_logger1.name=}")
# csv_logger1.name='lightning_logs'
print(f"{csv_logger2.name=}")
# csv_logger2.name=''
print(f"{csv_logger3.name=}")
# csv_logger3.name='some_name'

print(f"{csv_logger1.log_dir=}")
# csv_logger1.log_dir='save_dir/lightning_logs/version_0'
print(f"{csv_logger2.log_dir=}")
# csv_logger2.log_dir='save_dir/version_0'

Or am I missing something?

@awaelchli
Copy link
Contributor

awaelchli commented Feb 23, 2024

Ok, I initially thought you wanted to make the argument optional in the literal sense (i.e. making the default None). But I should have read more carefully. I am ok with your proposed change if it's just about adding Optional[] around the type. Feel free to submit a PR if you're interested.

mwip added a commit to mwip/pytorch-lightning that referenced this issue Feb 23, 2024
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 Lightning-AI#19433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement logger: csv ver: 2.2.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants