ray.tune.Tuner.can_restore#

classmethod Tuner.can_restore(path: str | PathLike, storage_filesystem: pyarrow.fs.FileSystem | None = None) bool[source]#

Checks whether a given directory contains a restorable Tune experiment.

Usage Pattern:

Use this utility to switch between starting a new Tune experiment and restoring when possible. This is useful for experiment fault-tolerance when re-running a failed tuning script.

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

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

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

if Tuner.can_restore(exp_dir):
    tuner = Tuner.restore(exp_dir, trainable=train_fn, resume_errored=True)
else:
    tuner = Tuner(
        train_fn,
        run_config=RunConfig(name=name, storage_path=storage_path),
    )
tuner.fit()
Parameters:

path – The path to the experiment directory of the Tune experiment. This can be either a local directory or a remote URI (e.g. s3://bucket/exp_name).

Returns:

True if this path exists and contains the Tuner state to resume from

Return type:

bool