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] Fix checkpoint directory assignment for new checkpoints created after restoring a function trainable #31231

Merged
merged 6 commits into from
Dec 22, 2022

Conversation

justinvyu
Copy link
Contributor

@justinvyu justinvyu commented Dec 20, 2022

This PR fixes checkpoint directory creation for restored function trainables to use the restored iteration instead of starting over from checkpoint_000000.

Why are these changes needed?

The _StatusReporter that handles checkpoint directory creation for function trainables keeps track of an _iter that closely follows the Trainable training_iteration, and it's used to create checkpoint directories (ex: checkpoint_000000).

Upon restoring a trial, this iteration is not restored properly and starts from 0, which results in a new checkpoint possibly overwriting an old one at the checkpoint_000000 path.

The ticket below has more details, but the basic failure case:

  • 1st checkpoint comes in, saved under checkpoint_000000
  • Experiment is interrupted and gets restored
  • 2nd checkpoint comes in, but still saved under checkpoint_000000
  • 1st checkpoint is now overwritten

Solution

Don't keep track of an _iter separately in the session - use the trainable's current training_iteration instead.

Open Questions

  1. Class trainables and function trainables have different indexing: Class trainables are 1-indexed with checkpoints matching the training_iteration, so the first checkpoint is saved as checkpoint_000001. Function trainables are 0-indexed. This PR could change it to make this consistent, and I think that the class trainable indexing makes more sense rather than always being 1-off with respect to the iteration number. Decision: This would break backwards compatibility when restoring experiments that have 0 indexed checkpoints, so this will be left for a future PR.

Related issue number

Closes #29947

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • 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 :(

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.

Looks good, only one clarification

Comment on lines +130 to +138
result_queue: queue.Queue,
continue_semaphore: threading.Semaphore,
end_event: threading.Event,
training_iteration_func: Callable[[], int],
experiment_name: Optional[str] = None,
trial_name: Optional[str] = None,
trial_id: Optional[str] = None,
logdir: Optional[str] = None,
trial_resources: Optional[Union[Resources, PlacementGroupFactory]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

python/ray/tune/trainable/function_trainable.py Outdated Show resolved Hide resolved
@krfricke krfricke merged commit 77b94ab into ray-project:master Dec 22, 2022
krfricke pushed a commit that referenced this pull request Jan 4, 2023
…31423)

This PR is a follow-up to #31231 to save checkpoints to the correctly indexed directory upon restore. The "latest checkpoint ID" that's used to generate the next checkpoint directory (`checkpoint_0000<latest_checkpoint_id>`) is off by one when restoring an AIR trainer.

Signed-off-by: Justin Yu <[email protected]>
AmeerHajAli pushed a commit that referenced this pull request Jan 12, 2023
…d after restoring a function trainable (#31231)

This PR fixes checkpoint directory creation for restored function trainables to use the restored iteration instead of starting over from `checkpoint_000000`.

Signed-off-by: Justin Yu <[email protected]>
AmeerHajAli pushed a commit that referenced this pull request Jan 12, 2023
…31423)

This PR is a follow-up to #31231 to save checkpoints to the correctly indexed directory upon restore. The "latest checkpoint ID" that's used to generate the next checkpoint directory (`checkpoint_0000<latest_checkpoint_id>`) is off by one when restoring an AIR trainer.

Signed-off-by: Justin Yu <[email protected]>
tamohannes pushed a commit to ju2ez/ray that referenced this pull request Jan 25, 2023
…d after restoring a function trainable (ray-project#31231)

This PR fixes checkpoint directory creation for restored function trainables to use the restored iteration instead of starting over from `checkpoint_000000`.

Signed-off-by: Justin Yu <[email protected]>
Signed-off-by: tmynn <[email protected]>
tamohannes pushed a commit to ju2ez/ray that referenced this pull request Jan 25, 2023
…ay-project#31423)

This PR is a follow-up to ray-project#31231 to save checkpoints to the correctly indexed directory upon restore. The "latest checkpoint ID" that's used to generate the next checkpoint directory (`checkpoint_0000<latest_checkpoint_id>`) is off by one when restoring an AIR trainer.

Signed-off-by: Justin Yu <[email protected]>
Signed-off-by: tmynn <[email protected]>
@justinvyu justinvyu deleted the restored_checkpoint_idx branch April 10, 2023 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[air] when restoring a session, new checkpoints saved seem to overwrite the old ones
3 participants