Skip to content

Conversation

@markgoodhead
Copy link
Contributor

What do these changes do?

Allows users of the HyperOptSearch suggestion algorithm to specify initial experiment values to run (typically already known good baseline parameters within the domain specified)

Related issue number

Discussed in the ray dev forums

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11531/
Test PASSed.

@richardliaw richardliaw changed the title Mark/hyperopt pte2 [tune] Add Initial Parameter Suggestion for HyperOpt Feb 4, 2019
@richardliaw
Copy link
Contributor

Can you amend the tune/examples/hyperopt_example.py with this feature? That would ensure it runs in the CI.

Right now, I did a quick test of this and I got an error:

Traceback (most recent call last):
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/hyperopt/pyll/base.py", line 868, in rec_eval
    int(switch_i)
ValueError: invalid literal for int() with base 10: 'relu'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "hyperopt_example.py", line 65, in <module>
    run_experiments(config, search_alg=algo, scheduler=scheduler)
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/tune.py", line 171, in run_experiments
    runner.step()
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/trial_runner.py", line 224, in step
    next_trial = self._get_next_trial()
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/trial_runner.py", line 371, in _get_next_trial
    self._update_trial_queue(blocking=wait_for_trial)
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/trial_runner.py", line 483, in _update_trial_queue
    trials = self._search_alg.next_trials()
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/suggest/suggestion.py", line 65, in next_trials
    for trial in self._trial_generator:
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/suggest/suggestion.py", line 86, in _generate_trials
    suggested_config = self._suggest(trial_id)
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/ray/tune/suggest/hyperopt.py", line 123, in _suggest
    print_node_on_error=self.domain.rec_eval_print_node_on_error)
  File "/data/rliaw/miniconda3/envs/ray/lib/python3.6/site-packages/hyperopt/pyll/base.py", line 870, in rec_eval
    raise TypeError('switch argument was', switch_i)
TypeError: ('switch argument was', 'relu')

Code I ran:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import ray
from ray.tune import run_experiments, register_trainable
from ray.tune.schedulers import AsyncHyperBandScheduler
from ray.tune.suggest import HyperOptSearch


def easy_objective(config, reporter):
    import time
    time.sleep(0.2)
    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))
        time.sleep(0.02)


if __name__ == '__main__':
    import argparse
    from hyperopt import hp

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

    register_trainable("exp", easy_objective)

    space = {
        'width': hp.uniform('width', 0, 20),
        'height': hp.uniform('height', -100, 100),
        'activation': hp.choice("activation", ["relu", "tanh"])
    }

    current_best_params = [
        {"width": 1, "height": 2, "activation": "relu"},
        {"width": 4, "height": 2, "activation": "relu"}
    ]

    config = {
        "my_exp": {
            "run": "exp",
            "num_samples": 10 if args.smoke_test else 1000,
            "config": {
                "iterations": 100,
            },
            "stop": {
                "timesteps_total": 100
            },
        }
    }
    algo = HyperOptSearch(space, max_concurrent=4, reward_attr="neg_mean_loss", points_to_evaluate=current_best_params)
    scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
    run_experiments(config, search_alg=algo, scheduler=scheduler)

Is there something I did wrong?

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11533/
Test PASSed.

@markgoodhead
Copy link
Contributor Author

Ah almost certainly a bug on my end, I only tested it with non-choice params. Let me investigate and I'll fix it up and provide the example you suggest

@richardliaw richardliaw self-assigned this Feb 5, 2019
…cumentation for HyperOpt to fix a mistake and reflect a fix for using choice parameters
@markgoodhead
Copy link
Contributor Author

markgoodhead commented Feb 6, 2019

@richardliaw The issue was that generate_trials_to_evaluate wants the index of the choice rather than the choice value itself. I considered trying to keep the same interface and to work it out for the user but it'd be a bit messy, so just opted for explaining this in the example / documentation as it's not that complex (and will also be more of a 'drop in' for users of hyperopt who want to run their code on Tune).

I've fixed up the example and it runs fine for me now. Let me know your thoughts and if you've any further changes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11611/
Test PASSed.

@richardliaw richardliaw added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Feb 7, 2019
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11640/
Test FAILed.

@markgoodhead
Copy link
Contributor Author

jenkins retest this please

@markgoodhead
Copy link
Contributor Author

^ is that how you're meant to kick off new tests if the previous ones failed due to unrelated flakiness?

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11649/
Test PASSed.

Copy link
Contributor

@richardliaw richardliaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - looks good, thanks a bunch for this contribution!

@richardliaw richardliaw merged commit 5ce670c into ray-project:master Feb 7, 2019
@markgoodhead markgoodhead deleted the mark/hyperopt-pte2 branch February 8, 2019 10:14
richardliaw pushed a commit that referenced this pull request Mar 17, 2019
Similar to the recent change to HyperOpt (##3944) this implements both:
1. The ability to pass in initial parameter suggestion(s) to be run through Tune first, before using the Optimiser's suggestions. This is for when you already know good parameters and want the Optimiser to be aware of these when it makes future parameter suggestions.
2. The same as 1. but if you already know the reward value for those parameters you can pass these in as well to avoid having to re-run the experiments. In the future it would be nice for Tune to potentially support this functionality directly by loading previously run Tune experiments and initialising the Optimiser with these (kind of like a top level checkpointing functionality) but this feature allows users to do this manually for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests-ok The tagger certifies test failures are unrelated and assumes personal liability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants