# \[Tune | RLlib\] Tune sample functions in yaml config files

**URL:** <https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989>\
**Category:** Ray Tune\
**Created:** [April 30, 2021, 12:43pm UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989 "2021-04-30T12:43:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien-Couthouis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/fabien-couthouis/32/814_2.png) [@Fabien-Couthouis](https://discuss.ray.io/u/Fabien-Couthouis)\
**Post date:** [April 30, 2021, 12:43pm UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/1 "2021-04-30T12:43:17Z")

</div>

Hello,

I know there is a keyword to run grid searches using yaml config file in Tune. It is done this way [in some  
tuned examples](https://github.com/ray-project/ray/blob/master/rllib/tuned_examples/dqn/atari-apex.yaml):

```auto
env:
    grid_search:
            - BreakoutNoFrameskip-v4
            - BeamRiderNoFrameskip-v4
            - QbertNoFrameskip-v4
            - SpaceInvadersNoFrameskip-v4

```

My question is: is there a way to do the same thing for the other Tune sample functions (i.e.: choice, randint, loguniform)?  
Thanks!

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [May 1, 2021, 12:58am UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/2 "2021-05-01T00:58:47Z")

</div>

I think these are not supported – but would be a fun contribution project 🙂

The team doesn’t have bandwidth to support this immediately, but feel free to open a request and/or a PR if you want to contribute!

---

<div class="post-metadata">

**Author:** ![Fabien-Couthouis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/fabien-couthouis/32/814_2.png) [@Fabien-Couthouis](https://discuss.ray.io/u/Fabien-Couthouis)\
**Post date:** [May 3, 2021, 7:22am UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/3 "2021-05-03T07:22:12Z")

</div>

Thanks for the answer!

---

<div class="post-metadata">

**Author:** ![MaximeBouton](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/maximebouton/32/450_2.png) [@MaximeBouton](https://discuss.ray.io/u/MaximeBouton)\
**Post date:** [March 7, 2022, 8:53am UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/4 "2022-03-07T08:53:27Z")

</div>

Hi! I am interested in that feature as well, do you have any tips on where to start to implement it?  
I looked at `tune.config_parser` but I couldn’t find where it is handling the grid search part.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Dejan\_Grubisic](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dejan_grubisic/32/2987_2.png) [@Dejan\_Grubisic](https://discuss.ray.io/u/Dejan_Grubisic)\
**Post date:** [October 26, 2022, 6:54pm UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/5 "2022-10-26T18:54:19Z")

</div>

I am also interested to hear more about this. The short way to save config with sweep options, would be just to store it in a python file and load it from there.  
Any better solution?

---

<div class="post-metadata">

**Author:** ![bveeramani](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/bveeramani/32/2941_2.png) [@bveeramani](https://discuss.ray.io/u/bveeramani)\
**Post date:** [October 27, 2022, 4:49am UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/6 "2022-10-27T04:49:32Z")

</div>

Hey @MaximeBouton, thanks for your interest in implementing a solution!

`ray.tune.search.variant_generator.generate_variants` might be a good place to start:

```auto
@DeveloperAPI
def generate_variants(
    unresolved_spec: Dict,
    constant_grid_search: bool = False,
    random_state: "RandomState" = None,
) -> Generator[Tuple[Dict, Dict], None, None]:
    """Generates variants from a spec (dict) with unresolved values.

    There are two types of unresolved values:

        Grid search: These define a grid search over values. For example, the
        following grid search values in a spec will produce six distinct
        variants in combination:

            "activation": grid_search(["relu", "tanh"])
            "learning_rate": grid_search([1e-3, 1e-4, 1e-5])

    ...

    Yields:
        (Dict of resolved variables, Spec object)
    """

```

In particular, it looks grid search is handled in `_try_resolve`:

```auto
def _try_resolve(v) -> Tuple[bool, Any]:
    ...

    elif isinstance(v, dict) and len(v) == 1 and "grid_search" in v:
        # Grid search values
        grid_values = v["grid_search"]
        return False, Categorical(grid_values).grid()
    ...

```

---

<div class="post-metadata">

**Author:** ![bveeramani](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/bveeramani/32/2941_2.png) [@bveeramani](https://discuss.ray.io/u/bveeramani)\
**Post date:** [October 27, 2022, 4:50am UTC](https://discuss.ray.io/t/tune-rllib-tune-sample-functions-in-yaml-config-files/1989/7 "2022-10-27T04:50:07Z")

</div>

Hey @Dejan_Grubisic, thanks for reaching out.

To the best of knowledge, there’s currently not a better solution.
