ray-project / ray

Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
https://ray.io
Apache License 2.0
33.28k stars 5.63k forks source link

[tune] utility function for converting dicts to hparam search spaces #10742

Closed sumanthratna closed 2 years ago

sumanthratna commented 4 years ago

Describe your feature request

I'm writing a framework that allows users to tune hparams, where the users would provide a config file describing the search space. A function for converting Python dicts to the Ray hparam config would be a very useful addition to the 1.0 API.

the function should be:

Pros:


CC @richardliaw

sumanthratna commented 4 years ago

e.g., if the "bonus" conversions are implemented,

hparams:
  losses:
    type: categorical
    sample_size: rand  # choose the sample size randomly; randrange(1, len(values)+1)
    values:
      - mse
      - l1
      - n11
  dropout:
    type: boolean

would become:

config = {
    "_losses__all": ["mse", "l1", "n11"],
    "_losses__sample_size": tune.sample_from(
        lambda spec: random.randrange(
            1, 
            len(spec.config._losses__all)+1,
        ),
    ),
    "losses": tune.sample_from(
        lambda spec: random.choices(
            spec.config._losses__all,
            spec.config._losses__sample_size,
        ),
    ),
    "dropout": tune.choice([True, False]),
}
richardliaw commented 4 years ago

hmm, sounds interesting - should be much simpler though:


config = {
   "config1": {"tune.uniform": [args]},
   "config2": {"tune.sample_from": "lambda spec: random.choices(...)"}
}
sumanthratna commented 4 years ago

hmm, sounds interesting - should be much simpler though:

config = {
   "config1": {"tune.uniform": [args]},
   "config2": {"tune.sample_from": "lambda spec: random.choices(...)"}
}

@richardliaw i'm not sure what you mean–are you suggesting that the dict you sent should be the input for the conversion function?

richardliaw commented 4 years ago

sorry - as input to the conversion function

richardliaw commented 4 years ago

(if you were to upstream it). Otherwise, perhaps it makes sense to just to build the conversion on your project (with whatever input format makes the most sense for you) for now!

sumanthratna commented 4 years ago

hmm in my case, pathologists with close to no CS experience might be specifying the search space via a config file, so I'd like to avoid syntax like lambda.

for now, I'll keep this in my project codebase; I'm still leaving this open at P3 because I think at some point (post-1.0) it would be cool to implement this in tune

richardliaw commented 4 years ago

very cool! sounds good.

krfricke commented 2 years ago

This should be covered by the Tune search space API conversion: https://docs.ray.io/en/latest/tune/api_docs/search_space.html