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

[Tune] use epoch for ptl checkpoint dir name #14392

Merged

Conversation

amogkam
Copy link
Contributor

@amogkam amogkam commented Feb 26, 2021

Why are these changes needed?

Related issue number

If using epoch level callbacks (on_epoch_start or on_epoch_end), then use trainer.current_epoch as the checkpoint directory name instead of trainer.global_step.

Closes #13971

Checks

  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@amogkam amogkam changed the title [Tune] use epoch for checkpoint dir name [Tune] use epoch for ptl checkpoint dir name Feb 26, 2021
Comment on lines 229 to 230
step = trainer.current_epoch if is_epoch else trainer.global_step
with tune.checkpoint_dir(step=step) as checkpoint_dir:
Copy link
Contributor

Choose a reason for hiding this comment

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

will it be possible that you can have global_step and current_epoch override each other in the same training loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I don’t think that’s possible as long as you’re using 1 callback since it’ll checkpoint at either the epoch frequency or batch frequency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But maybe I’m misunderstanding what you are asking

Copy link
Contributor

Choose a reason for hiding this comment

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

ok cool

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, actually we do allow passing multiple on values to a single callback. So in that case it might interfere.
I'm not sure this is a common use case (mixing on-step and on-epoch checkpointing) but we might want to ensure we don't run into conflicts.

Things we could do: First, use a formatted string instead of an int to pass to tune.checkpoint_dir(step) (which is actually supported). Second, set self._epoch = True if any of the on indicate per-epoch checkpointing and always use epochs for checkpointing (potentially overwriting existing checkpoints at the end of an epoch). Third, disallow multiple on values for checkpoints

Copy link
Contributor

Choose a reason for hiding this comment

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

Fourth, like thirds but throw a warning instead. I'd be fine with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, passing in multiple values to on would be pretty uncommon but is still possible. I'll change it to option 1- the default PTL callbacks do the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the change @krfricke- please take another look.

Copy link
Contributor

@richardliaw richardliaw left a comment

Choose a reason for hiding this comment

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

thanks!

@amogkam amogkam added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Feb 26, 2021
Copy link
Contributor

@krfricke krfricke left a comment

Choose a reason for hiding this comment

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

Fine with me! Thanks!

@amogkam
Copy link
Contributor Author

amogkam commented Mar 1, 2021

@richardliaw can you merge this please

@richardliaw richardliaw merged commit ca11b18 into ray-project:master Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests-ok The tagger certifies test failures are unrelated and assumes personal liability.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

why is trainer.current_epoch used for model checkpoint callback for Pytorch Lightning
3 participants