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

Default value for ModelCheckpoint filepath #1548

Conversation

SkafteNicki
Copy link
Member

@SkafteNicki SkafteNicki commented Apr 21, 2020

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

What does this PR do?

Fixes #1535.
As the issue outlines, it is not easy for the user to change some of the argument in ModelCheckpoint (like save_top_k) and still keep the default filepath because it is determined at runtime. This PR implements the option to pass in filepath=None which will be detected at runtime, and then filepath will be set to the default location.

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@mergify mergify bot requested a review from a team April 21, 2020 13:50
@ematvey
Copy link

ematvey commented Apr 23, 2020

Just an idea, it would be even better to allow user to specify save path and checkpoint filename template separately. I might want to override the template also to include useful metrics, etc, but I still wouldn't want to mess with default save path.

Would be a bit harder to do that while respecting backwards compatibility.

@SkafteNicki
Copy link
Member Author

I agree that it would be nice to split filepath into two arguments, a dirpath and a filename. I do not think it is possible to do with complete backward compatibility. Such a change would need confirmation from the core contributors.

@Borda Borda added the feature Is an improvement or enhancement label Apr 23, 2020
@ematvey
Copy link

ematvey commented Apr 23, 2020

We could add savedir and filename (None defaults) and use them when filename is defined, otherwise fallback to filepath, then gradually deprecate filepath.

@SkafteNicki
Copy link
Member Author

Nice idea, let me try to implement it. From what future version should filepath be deprecated?

@Borda
Copy link
Member

Borda commented Apr 23, 2020

We could add savedir and filename (None defaults) and use them when filename is defined, otherwise fallback to filepath, then gradually deprecate filepath.

Nice idea, let me try to implement it. From what future version should filepath be deprecated?

sounds good to me...
cc: @PyTorchLightning/core-contributors

@williamFalcon williamFalcon merged commit e977d1c into Lightning-AI:master Apr 23, 2020
@Borda Borda added this to the 0.7.4 milestone Apr 23, 2020
@@ -90,12 +94,14 @@ def __init__(self, filepath: str, monitor: str = 'val_loss', verbose: bool = Fal

self.monitor = monitor
self.verbose = verbose
if os.path.isdir(filepath):
self.dirpath, self.filename = filepath, '{epoch}'
if filepath is None: # will be determined by trainer at runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is will be deprecated there shall be warning...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SkafteNicki mind add deprecation warning?

@mergify mergify bot requested a review from a team April 23, 2020 19:59
@SkafteNicki
Copy link
Member Author

@Borda the changes have already been merged, before I had time to do the change we discussed. Should I go ahead and make a new PR?

@Borda
Copy link
Member

Borda commented Apr 27, 2020

@Borda the changes have already been merged, before I had time to do the change we discussed. Should I go ahead and make a new PR?

Yes please

@SkafteNicki SkafteNicki deleted the feature/runtime_modelcheckpoint_dirpath branch May 25, 2020 08:18
@Borda Borda modified the milestones: 0.7.4, v0.7.x Apr 18, 2021
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow keeping default save_dir in ModelCheckpointer
4 participants