[tune] refactor and add examples (#11931)

This commit is contained in:
Richard Liaw
2020-11-14 20:43:28 -08:00
committed by GitHub
parent 5891759a3e
commit 8b3f79f307
57 changed files with 587 additions and 503 deletions
@@ -2,7 +2,7 @@ import os
import argparse
from ray.tune import run
from ray.tune.examples.async_hyperband_example import MyTrainableClass
from ray.tune.utils._mock_trainable import MyTrainableClass
from ray.tune.suggest.hyperopt import HyperOptSearch
from ray.tune.suggest.suggestion import ConcurrencyLimiter
+5 -1
View File
@@ -25,6 +25,7 @@ from ray.tune.syncer import CloudSyncer, SyncerCallback, get_node_syncer
from ray.tune.utils.trainable import TrainableUtil
from ray.tune.trial import Trial
from ray.tune.trial_runner import TrialRunner
from ray.tune.utils._mock_trainable import MyTrainableClass
from ray.tune.utils.mock import (MockDurableTrainer, MockRemoteTrainer,
MockNodeSyncer, mock_storage_client,
MOCK_REMOTE_DIR)
@@ -746,7 +747,6 @@ def test_cluster_interrupt_searcher(start_connected_cluster, tmpdir):
cluster = start_connected_cluster
dirpath = str(tmpdir)
local_checkpoint_dir = os.path.join(dirpath, "experiment")
from ray.tune.examples.async_hyperband_example import MyTrainableClass
from ray.tune import register_trainable
register_trainable("trainable", MyTrainableClass)
@@ -770,6 +770,8 @@ def test_cluster_interrupt_searcher(start_connected_cluster, tmpdir):
if trials and len(trials) >= 10:
break
time.sleep(.5)
else:
raise ValueError(f"Didn't generate enough trials: {len(trials)}")
if not TrialRunner.checkpoint_exists(local_checkpoint_dir):
raise RuntimeError(
@@ -792,8 +794,10 @@ def test_cluster_interrupt_searcher(start_connected_cluster, tmpdir):
runner = TrialRunner(
resume="LOCAL", local_checkpoint_dir=local_checkpoint_dir)
trials = runner.get_trials()
if len(trials) == 0:
continue # nonblocking script hasn't resumed yet, wait
reached = True
assert len(trials) >= 10
assert len(trials) <= 20
@@ -8,7 +8,7 @@ from numpy import nan
import ray
from ray import tune
from ray.tune.examples.async_hyperband_example import MyTrainableClass
from ray.tune.utils.mock import MyTrainableClass
class ExperimentAnalysisSuite(unittest.TestCase):
@@ -11,7 +11,7 @@ import numpy as np
import ray
from ray.tune import (run, Trainable, sample_from, Analysis,
ExperimentAnalysis, grid_search)
from ray.tune.examples.async_hyperband_example import MyTrainableClass
from ray.tune.utils.mock import MyTrainableClass
class ExperimentAnalysisInMemorySuite(unittest.TestCase):
+1 -1
View File
@@ -116,7 +116,7 @@ class TuneExampleTest(unittest.TestCase):
validate_save_restore(MyTrainableClass, use_object_store=True)
def testAsyncHyperbandExample(self):
from ray.tune.examples.async_hyperband_example import MyTrainableClass
from ray.tune.utils.mock import MyTrainableClass
validate_save_restore(MyTrainableClass)
validate_save_restore(MyTrainableClass, use_object_store=True)