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

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
:

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!

1 Like

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

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!

Thanks for the answer!

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!

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?

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

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

@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:

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()
    ...

Hey @Dejan_Grubisic, thanks for reaching out.

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