question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[tune] separate fixed configuration from searchable parameters

See original GitHub issue

Describe your feature request

I’ve wrapped an existing pytorch based project with ray tune PBT. It works great 👍thank you 😃

But one thing I wish I had is, being able to input fixed configuration somewhere else other than in the configuration that is used for searching hyperparameters.

The things is, I have many options (e.g., dataset name and paths) that are completely irrelevant to the algorithm but are necessary. As far as I know, I have to include them in my hyperparameter space as list of length 1 in order to make them available to use in _setup(). But this looks messy and appears constantly when some hyperparameter perturbation occurs.

So it would be great if I could list my basic (fixed) configuration somewhere else, and use the hyperparameter space (dict) purely for tunable hyperparameters.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
crypdickcommented, Jul 27, 2020

@richardliaw would it be difficult to add support for config to (optionally) be an argparse.Namespace? Otherwise, packing args into the config dict is awkward, e.g. self.config["args"].max_epochs. It seems like it would be as simple as adding if isinstance(config, Namespace): config = vars(config).

I wrote my codebase for args, so right now I do args = config_to_args(config) in each of my functions.

def dict_to_namespace(config: Union[argparse.Namespace, Dict]) -> argparse.Namespace:
    """
    ray tournament forces us to pass args inside dict let's make args first-
    class and unpack the dict into it, with dict items taking precedence.
    """
    if isinstance(config, argparse.Namespace):
        args = config
    elif isinstance(config, dict):
        # if we do not copy first, we will have a key error
        # the next time we try to run this function
        config_ = config.copy()
        args = config_.pop("args")  # args should always be a key

        # this is the config created by Ray
        for k, v in config_.items():
            if hasattr(args, k):
                logger.warning(f"Overwriting args {k}={vars(args)[k]} with Ray Tune config {k}={v}")
            vars(args)[k] = v
    else:
        raise TypeError(f"expecting type dict or argparser.Namespace, got {type(config)}")
    return args
1reaction
richardliawcommented, Feb 20, 2020

Are you using argparse? One option is to simply keep everything in the Namespace object and update it on the worker:

args = ArgumentParser().parse_args()
tune.run(Trainable, config={"base_args": args, "lr": ...})

BTW, this should also work:

base_config = {}

class Trainer(tune.Trainable):
    def _setup(self, config):
        self.base_config = base_config
        self.base_config.update(config)
    ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Search Algorithms (tune.search) — Ray 2.2.0
Uses Tune's variant generation for resolving variables. This is the default search algorithm used if no other search algorithm is specified. Parameters.
Read more >
Parameter Configuration for Analysis - MATLAB & Simulink
Specify Parameter Constraints for Models using Referenced Configuration Set · Open the model. · On the Design Verifier tab, click Settings to open...
Read more >
Tune Machine Learning Algorithms in R (random forest ...
Grid Search. Another search is to define a grid of algorithm parameters to try. Each axis of the grid is an algorithm parameter,...
Read more >
Parameter Tuning — RecBole 1.1.1 documentation
RecBole introduces Hyperopt and Ray for parameter tuning. ... config_files is the config files containing fixed parameters, params_file is the file ...
Read more >
Mapping | Elasticsearch Guide [8.5]
Define runtime fields in a search request to experiment with different mapping options, and also fix mistakes in your index mapping values by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found