Skip to content

Commit

Permalink
refactored code to use metric,mode instead of reward_attr for schedul…
Browse files Browse the repository at this point in the history
  • Loading branch information
hershg committed May 25, 2019
1 parent 8f69bb1 commit c9740eb
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 27 deletions.
3 changes: 2 additions & 1 deletion ci/long_running_tests/workloads/pbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

pbt = PopulationBasedTraining(
time_attr="training_iteration",
reward_attr="episode_reward_mean",
metric="episode_reward_mean",
mode="max",
perturbation_interval=10,
hyperparam_mutations={
"lr": [0.1, 0.01, 0.001, 0.0001],
Expand Down
8 changes: 5 additions & 3 deletions doc/source/tune-schedulers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ By default, Tune schedules trials in serial order with the ``FIFOScheduler`` cla
tune.run( ... , scheduler=AsyncHyperBandScheduler())
Tune includes distributed implementations of early stopping algorithms such as `Median Stopping Rule <https://research.google.com/pubs/pub46180.html>`__, `HyperBand <https://arxiv.org/abs/1603.06560>`__, and an `asynchronous version of HyperBand <https://openreview.net/forum?id=S1Y7OOlRZ>`__. These algorithms are very resource efficient and can outperform Bayesian Optimization methods in `many cases <https://people.eecs.berkeley.edu/~kjamieson/hyperband.html>`__. Currently, all schedulers take in a ``reward_attr``, which is assumed to be maximized.
Tune includes distributed implementations of early stopping algorithms such as `Median Stopping Rule <https://research.google.com/pubs/pub46180.html>`__, `HyperBand <https://arxiv.org/abs/1603.06560>`__, and an `asynchronous version of HyperBand <https://openreview.net/forum?id=S1Y7OOlRZ>`__. These algorithms are very resource efficient and can outperform Bayesian Optimization methods in `many cases <https://people.eecs.berkeley.edu/~kjamieson/hyperband.html>`__. Currently, all schedulers take in a ``metric``, which is minimized or maximized according to ``mode``.

Current Available Trial Schedulers:

Expand All @@ -25,7 +25,8 @@ Tune includes a distributed implementation of `Population Based Training (PBT) <
pbt_scheduler = PopulationBasedTraining(
time_attr='time_total_s',
reward_attr='mean_accuracy',
metric='mean_accuracy',
mode='max',
perturbation_interval=600.0,
hyperparam_mutations={
"lr": [1e-3, 5e-4, 1e-4, 5e-5, 1e-5],
Expand All @@ -52,7 +53,8 @@ The `asynchronous version of HyperBand <https://openreview.net/forum?id=S1Y7OOlR
async_hb_scheduler = AsyncHyperBandScheduler(
time_attr='training_iteration',
reward_attr='episode_reward_mean',
metric='episode_reward_mean',
mode='max',
max_t=100,
grace_period=10,
reduction_factor=3,
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/async_hyperband_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def _restore(self, checkpoint_path):
# which is automatically filled by Tune.
ahb = AsyncHyperBandScheduler(
time_attr="training_iteration",
reward_attr="episode_reward_mean",
metric="episode_reward_mean",
mode="max",
grace_period=5,
max_t=100)

Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/ax_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ def easy_objective(config, reporter):
parameter_constraints=["x1 + x2 <= 2.0"], # Optional.
outcome_constraints=["l2norm <= 1.25"], # Optional.
)
scheduler = AsyncHyperBandScheduler(reward_attr="hartmann6")
scheduler = AsyncHyperBandScheduler(metric="hartmann6", mode="max")
run(easy_objective, name="ax", search_alg=algo, **config)
2 changes: 1 addition & 1 deletion python/ray/tune/examples/bayesopt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def easy_objective(config, reporter):
"kappa": 2.5,
"xi": 0.0
})
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective,
name="my_exp",
search_alg=algo,
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/genetic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def michalewicz_function(config, reporter):
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(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(michalewicz_function,
name="my_exp",
search_alg=algo,
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/hyperband_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def _restore(self, checkpoint_path):
# which is automatically filled by Tune.
hyperband = HyperBandScheduler(
time_attr="training_iteration",
reward_attr="episode_reward_mean",
metric="episode_reward_mean",
mode="max",
max_t=100)

exp = Experiment(
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/hyperopt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ def easy_objective(config, reporter):
max_concurrent=4,
reward_attr="neg_mean_loss",
points_to_evaluate=current_best_params)
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective, search_alg=algo, scheduler=scheduler, **config)
3 changes: 2 additions & 1 deletion python/ray/tune/examples/mnist_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def test():
ray.init()
sched = AsyncHyperBandScheduler(
time_attr="training_iteration",
reward_attr="neg_mean_loss",
metric="neg_mean_loss",
mode="max",
max_t=400,
grace_period=20)
tune.register_trainable(
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/mnist_pytorch_trainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _restore(self, checkpoint_path):

ray.init(redis_address=args.redis_address)
sched = HyperBandScheduler(
time_attr="training_iteration", reward_attr="neg_mean_loss")
time_attr="training_iteration", metric="neg_mean_loss", mode="max")
tune.run(
TrainMNIST,
scheduler=sched,
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/nevergrad_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def easy_objective(config, reporter):
parameter_names,
max_concurrent=4,
reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective,
name="nevergrad",
search_alg=algo,
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/pbt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def reset_config(self, new_config):

pbt = PopulationBasedTraining(
time_attr="training_iteration",
reward_attr="mean_accuracy",
metric="mean_accuracy",
mode="max",
perturbation_interval=20,
hyperparam_mutations={
# distribution for resampling
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/pbt_ppo_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def explore(config):

pbt = PopulationBasedTraining(
time_attr="time_total_s",
reward_attr="episode_reward_mean",
metric="episode_reward_mean",
mode="max",
perturbation_interval=120,
resample_probability=0.25,
# Specifies the mutations of these hyperparams
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/pbt_tune_cifar10_with_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def _stop(self):

pbt = PopulationBasedTraining(
time_attr="training_iteration",
reward_attr="mean_accuracy",
metric="mean_accuracy",
mode="max",
perturbation_interval=10,
hyperparam_mutations={
"dropout": lambda _: np.random.uniform(0, 1),
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/sigopt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def easy_objective(config, reporter):
name="SigOpt Example Experiment",
max_concurrent=1,
reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective,
name="my_exp",
search_alg=algo,
Expand Down
4 changes: 2 additions & 2 deletions python/ray/tune/examples/skopt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def easy_objective(config, reporter):
reward_attr="neg_mean_loss",
points_to_evaluate=previously_run_params,
evaluated_rewards=known_rewards)
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective,
name="skopt_exp_with_warmstart",
search_alg=algo,
Expand All @@ -65,7 +65,7 @@ def easy_objective(config, reporter):
max_concurrent=4,
reward_attr="neg_mean_loss",
points_to_evaluate=previously_run_params)
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
scheduler = AsyncHyperBandScheduler(metric="neg_mean_loss", mode="max")
run(easy_objective,
name="skopt_exp",
search_alg=algo,
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/tune_cifar10_gluon.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def test():
elif args.scheduler == "asynchyperband":
sched = AsyncHyperBandScheduler(
time_attr="training_iteration",
reward_attr="neg_mean_loss",
metric="neg_mean_loss",
mode="max",
max_t=400,
grace_period=60)
else:
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/examples/tune_mnist_async_hyperband.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def train(config={"activation": "relu"}, reporter=None):
name="tune_mnist_test",
scheduler=AsyncHyperBandScheduler(
time_attr="timesteps_total",
reward_attr="mean_accuracy",
metric="mean_accuracy",
mode="max",
max_t=600,
),
**mnist_spec)
3 changes: 2 additions & 1 deletion python/ray/tune/examples/tune_mnist_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def train_mnist(config, reporter):
ray.init()
sched = AsyncHyperBandScheduler(
time_attr="timesteps_total",
reward_attr="mean_accuracy",
metric="mean_accuracy",
mode="max",
max_t=400,
grace_period=20)

Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/tune_mnist_ray_hyperband.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _restore(self, ckpt_data):

ray.init()
hyperband = HyperBandScheduler(
time_attr="training_iteration", reward_attr="mean_accuracy", max_t=10)
time_attr="training_iteration", metric="mean_accuracy", mode="max", max_t=10)

tune.run(
TrainMNIST,
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/tests/test_experiment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def tearDown(self):
def run_test_exp(self):
ahb = AsyncHyperBandScheduler(
time_attr="training_iteration",
reward_attr=self.metric,
metric=self.metric,
mode="max",
grace_period=5,
max_t=100)

Expand Down
8 changes: 5 additions & 3 deletions python/ray/tune/tests/test_trial_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def result2(t, rew):
grace_period=0,
min_samples_required=1,
time_attr="training_iteration",
reward_attr="neg_mean_loss")
metric="neg_mean_loss",
mode="max")
t1 = Trial("PPO") # mean is 450, max 900, t_max=10
t2 = Trial("PPO") # mean is 450, max 450, t_max=5
for i in range(10):
Expand Down Expand Up @@ -502,7 +503,7 @@ def result2(t, rew):
return dict(time_total_s=t, neg_mean_loss=rew)

sched = HyperBandScheduler(
time_attr="time_total_s", reward_attr="neg_mean_loss")
time_attr="time_total_s", metric="neg_mean_loss", mode="max")
stats = self.default_statistics()

for i in range(stats["max_trials"]):
Expand Down Expand Up @@ -1022,7 +1023,8 @@ def result2(t, rew):
scheduler = AsyncHyperBandScheduler(
grace_period=1,
time_attr="training_iteration",
reward_attr="neg_mean_loss",
metric="neg_mean_loss",
mode="max",
brackets=1)
t1 = Trial("PPO") # mean is 450, max 900, t_max=10
t2 = Trial("PPO") # mean is 450, max 450, t_max=5
Expand Down

0 comments on commit c9740eb

Please sign in to comment.