From 08c0a926fb700b473b6077897807fd7a32fc4ce9 Mon Sep 17 00:00:00 2001 From: Kai Fricke Date: Fri, 9 Sep 2022 10:11:42 +0100 Subject: [PATCH] [tune] Overwrite files on restore (replace instead of rename) Signed-off-by: Kai Fricke --- python/ray/tune/impl/tuner_internal.py | 2 +- python/ray/tune/tests/test_tuner_restore.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/python/ray/tune/impl/tuner_internal.py b/python/ray/tune/impl/tuner_internal.py index 6080e48b76d1..0c5cb15eb48a 100644 --- a/python/ray/tune/impl/tuner_internal.py +++ b/python/ray/tune/impl/tuner_internal.py @@ -215,7 +215,7 @@ def _restore_from_path_or_uri( self._setup_create_experiment_checkpoint_dir(self._run_config) ) for file_dir in experiment_checkpoint_path.glob("*"): - file_dir.rename(new_exp_path / file_dir.name) + file_dir.replace(new_exp_path / file_dir.name) shutil.rmtree(experiment_checkpoint_path) self._experiment_checkpoint_dir = str(new_exp_path) diff --git a/python/ray/tune/tests/test_tuner_restore.py b/python/ray/tune/tests/test_tuner_restore.py index 108331b650e4..8741a42cfdbd 100644 --- a/python/ray/tune/tests/test_tuner_restore.py +++ b/python/ray/tune/tests/test_tuner_restore.py @@ -347,6 +347,10 @@ def test_tuner_restore_from_cloud(ray_start_2_cpus, tmpdir): # Contents changed assert prev_lstat.st_size != after_lstat.st_size + # Overwriting should work + tuner3 = Tuner.restore("memory:///test/restore/exp_dir") + tuner3.fit() + if __name__ == "__main__": import sys