Skip to content

Commit

Permalink
tests confirmed, fixed bugs+style (ray-project#4120)
Browse files Browse the repository at this point in the history
  • Loading branch information
hershg committed May 27, 2019
1 parent 8645185 commit 298ee9e
Show file tree
Hide file tree
Showing 30 changed files with 714 additions and 742 deletions.
30 changes: 14 additions & 16 deletions ci/long_running_tests/workloads/pbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,24 @@

cluster = Cluster()
for i in range(num_nodes):
cluster.add_node(
redis_port=6379 if i == 0 else None,
num_redis_shards=num_redis_shards if i == 0 else None,
num_cpus=10,
num_gpus=0,
resources={str(i): 2},
object_store_memory=object_store_memory,
redis_max_memory=redis_max_memory)
cluster.add_node(redis_port=6379 if i == 0 else None,
num_redis_shards=num_redis_shards if i == 0 else None,
num_cpus=10,
num_gpus=0,
resources={str(i): 2},
object_store_memory=object_store_memory,
redis_max_memory=redis_max_memory)
ray.init(redis_address=cluster.redis_address)

# Run the workload.

pbt = PopulationBasedTraining(
time_attr="training_iteration",
metric="episode_reward_mean",
mode="max",
perturbation_interval=10,
hyperparam_mutations={
"lr": [0.1, 0.01, 0.001, 0.0001],
})
pbt = PopulationBasedTraining(time_attr="training_iteration",
metric="episode_reward_mean",
mode="max",
perturbation_interval=10,
hyperparam_mutations={
"lr": [0.1, 0.01, 0.001, 0.0001],
})

run_experiments(
{
Expand Down
20 changes: 10 additions & 10 deletions python/ray/tune/examples/async_hyperband_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ def _restore(self, checkpoint_path):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing")
parser.add_argument("--smoke-test",
action="store_true",
help="Finish quickly for testing")
args, _ = parser.parse_known_args()
ray.init()

# asynchronous hyperband early stopping, configured with
# `episode_reward_mean` as the
# objective and `training_iteration` as the time unit,
# which is automatically filled by Tune.
ahb = AsyncHyperBandScheduler(
time_attr="training_iteration",
metric="episode_reward_mean",
mode="max",
grace_period=5,
max_t=100)
ahb = AsyncHyperBandScheduler(time_attr="training_iteration",
metric="episode_reward_mean",
mode="max",
grace_period=5,
max_t=100)

run(MyTrainableClass,
name="asynchyperband_test",
Expand All @@ -77,8 +77,8 @@ def _restore(self, checkpoint_path):
"gpu": 0
},
"config": {
"width": sample_from(
lambda spec: 10 + int(90 * random.random())),
"width": sample_from(lambda spec: 10 + int(90 * random.random(
))),
"height": sample_from(lambda spec: int(100 * random.random())),
},
})
12 changes: 6 additions & 6 deletions python/ray/tune/examples/ax_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def easy_objective(config, reporter):
time.sleep(0.2)
for i in range(config["iterations"]):
x = np.array([config.get(f"x{i+1}") for i in range(6)])
reporter(
timesteps_total=i,
hartmann6=hartmann6(x),
l2norm=np.sqrt((x**2).sum()))
reporter(timesteps_total=i,
hartmann6=hartmann6(x),
l2norm=np.sqrt((x**2).sum()))
time.sleep(0.02)


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing")
parser.add_argument("--smoke-test",
action="store_true",
help="Finish quickly for testing")
args, _ = parser.parse_known_args()
ray.init()

Expand Down
31 changes: 15 additions & 16 deletions python/ray/tune/examples/bayesopt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ def easy_objective(config, reporter):
import time
time.sleep(0.2)
for i in range(config["iterations"]):
reporter(
timesteps_total=i,
neg_mean_loss=-(config["height"] - 14)**2 +
abs(config["width"] - 3))
reporter(timesteps_total=i,
neg_mean_loss=-(config["height"] - 14)**2 +
abs(config["width"] - 3))
time.sleep(0.02)


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing")
parser.add_argument("--smoke-test",
action="store_true",
help="Finish quickly for testing")
args, _ = parser.parse_known_args()
ray.init()

Expand All @@ -43,16 +43,15 @@ def easy_objective(config, reporter):
"timesteps_total": 100
}
}
algo = BayesOptSearch(
space,
max_concurrent=4,
metric="neg_mean_loss",
mode="max",
utility_kwargs={
"kind": "ucb",
"kappa": 2.5,
"xi": 0.0
})
algo = BayesOptSearch(space,
max_concurrent=4,
metric="neg_mean_loss",
mode="max",
utility_kwargs={
"kind": "ucb",
"kappa": 2.5,
"xi": 0.0
})
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective,
name="my_exp",
Expand Down
14 changes: 7 additions & 7 deletions python/ray/tune/examples/genetic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def michalewicz_function(config, reporter):
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing")
parser.add_argument("--smoke-test",
action="store_true",
help="Finish quickly for testing")
args, _ = parser.parse_known_args()
ray.init()

Expand All @@ -45,11 +46,10 @@ def michalewicz_function(config, reporter):
})

config = {"stop": {"training_iteration": 100}}
algo = GeneticSearch(
space,
reward_attr="neg_mean_loss",
max_generation=2 if args.smoke_test else 10,
population_size=10 if args.smoke_test else 50)
algo = GeneticSearch(space,
reward_attr="neg_mean_loss",
max_generation=2 if args.smoke_test else 10,
population_size=10 if args.smoke_test else 50)
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(michalewicz_function,
name="my_exp",
Expand Down
14 changes: 7 additions & 7 deletions python/ray/tune/examples/hyperband_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ def _restore(self, checkpoint_path):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing")
parser.add_argument("--smoke-test",
action="store_true",
help="Finish quickly for testing")
args, _ = parser.parse_known_args()
ray.init()

# Hyperband early stopping, configured with `episode_reward_mean` as the
# objective and `training_iteration` as the time unit,
# which is automatically filled by Tune.
hyperband = HyperBandScheduler(
time_attr="training_iteration",
metric="episode_reward_mean",
mode="max",
max_t=100)
hyperband = HyperBandScheduler(time_attr="training_iteration",
metric="episode_reward_mean",
mode="max",
max_t=100)

exp = Experiment(
name="hyperband_test",
Expand Down
23 changes: 11 additions & 12 deletions python/ray/tune/examples/hyperopt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def easy_objective(config, reporter):
assert type(config["activation"]) == str, \
"Config is incorrect: {}".format(type(config["activation"]))
for i in range(config["iterations"]):
reporter(
timesteps_total=i,
neg_mean_loss=-(config["height"] - 14)**2 +
abs(config["width"] - 3))
reporter(timesteps_total=i,
neg_mean_loss=-(config["height"] - 14)**2 +
abs(config["width"] - 3))
time.sleep(0.02)


Expand All @@ -30,8 +29,9 @@ def easy_objective(config, reporter):
from hyperopt import hp

parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing")
parser.add_argument("--smoke-test",
action="store_true",
help="Finish quickly for testing")
args, _ = parser.parse_known_args()
ray.init()

Expand Down Expand Up @@ -63,11 +63,10 @@ def easy_objective(config, reporter):
"timesteps_total": 100
},
}
algo = HyperOptSearch(
space,
max_concurrent=4,
metric="neg_mean_loss",
mode="min",
points_to_evaluate=current_best_params)
algo = HyperOptSearch(space,
max_concurrent=4,
metric="neg_mean_loss",
mode="min",
points_to_evaluate=current_best_params)
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective, search_alg=algo, scheduler=scheduler, **config)
Loading

0 comments on commit 298ee9e

Please sign in to comment.