Skip to content

[Tune] Add Tuner.can_restore(path) utility for checking if an experiment exists at a path/uri - #32003

Merged
krfricke merged 15 commits into
ray-project:masterfrom
justinvyu:tune/can_restore_utility
Feb 1, 2023
Merged

[Tune] Add Tuner.can_restore(path) utility for checking if an experiment exists at a path/uri#32003
krfricke merged 15 commits into
ray-project:masterfrom
justinvyu:tune/can_restore_utility

Conversation

@justinvyu

Copy link
Copy Markdown
Contributor

Why are these changes needed?

This PR adds a utility to check if a given path (either local or remote) exists and can be restored from. It includes some simple validation that this is the root of the experiment directory (can't restore from the trial level directory).

Example workflow that this should be used in:

import os
from ray.tune import Tuner
from ray.air import RunConfig

def train_fn(config):
    # Make sure to implement checkpointing so that progress gets
    # saved on restore.
    pass

name = "exp_name"
local_dir = "~/ray_results"
exp_dir = os.path.join(local_dir, name)

if Tuner.can_restore(exp_dir):
    tuner = Tuner.restore(exp_dir, resume_errored=True)
else:
    tuner = Tuner(
        "PPO",
        run_config=RunConfig(name=name, local_dir=local_dir),
    )
tuner.fit()

Related issue number

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 :(

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>

Add missing sentence

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>

@Yard1 Yard1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread python/ray/tune/impl/tuner_internal.py Outdated
Comment thread python/ray/tune/tests/test_tuner_restore.py
justinvyu and others added 5 commits January 31, 2023 14:25
Co-authored-by: Antoni Baum <antoni.baum@protonmail.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>

@krfricke krfricke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment on lines +973 to +975
path = tmp_path / name
if upload_dir:
path = Path(upload_dir) / name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit for readability

Suggested change
path = tmp_path / name
if upload_dir:
path = Path(upload_dir) / name
if upload_dir:
path = Path(upload_dir) / name
else:
path = tmp_path / name

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>

Fix lint 2

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
…/can_restore_utility

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
@krfricke
krfricke merged commit d6de1ce into ray-project:master Feb 1, 2023
edoakes pushed a commit to edoakes/ray that referenced this pull request Mar 22, 2023
…iment exists at a path/uri (ray-project#32003)

This PR adds a utility to check if a given path (either local or remote) exists and can be restored from. It includes some simple validation that this is the root of the experiment directory (can't restore from the trial level directory).

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Co-authored-by: Antoni Baum <antoni.baum@protonmail.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
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.

3 participants