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.

[Feature Request] Override loaded config file through a command line flag

See original GitHub issue

🚀 Feature Request

I want to pass yaml file instead of parameters like foo.bar=1 ... to override default configuration:

$ python app.py --yaml foo.yaml

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:40
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

29reactions
jbohnslavcommented, Apr 15, 2020

Hi there,

I just wanted to +1 for this feature request. My use case is as follows. I have a complex configuration file with lots of details the user will not need to interact with, e.g. optimizers. There are elements, particularly regarding the data and augmentations, that all users will have to customize.

Default conf/config.yaml:

train
  lr: 0.0001
  optimizer: adam
dataset
  name: imagenet
  classes: 
    - tench
    - goldfish
    - great white shark
    - ... etc
augs
  resize: 224
  flip_lr: true
  flip_ud: false

user_config.yaml:

dataset
  name: not hotdog
  classes:
    - hotdog
    - not hotdog
augs
  resize: 64
  flip_lr: true
  flip_ud: true

What I want is to be able to use the following syntax and have Hydra load the default configuration file first, and optionally override with the user’s supplied config file: python train.py --config user_config.yaml

Ideally, the user could also supply command line arguments which would take precedence over all. I’m not sure if this is too unique to my use case. I want the priority to be command line args > user defaults from user_config.yaml > conf/config.yaml.

Is there a way to do this currently with hydra?

21reactions
SunQparkcommented, Apr 19, 2020

I’m currently using a workaround for a similar case.

Default conf/config.yaml:

user_config: # path to config file to update.
train:
  lr: 0.0001
  optimizer: adam
dataset:
  name: imagenet
  classes: 
    - tench
    ...

Then, in the train.py you can override hydra config object with OmegaConf.merge function when user_config is given.

if config.user_config is not None:
    user_config = OmegaConf.load(config.user_config)
    config = OmegaConf.merge(config, user_config)

Now, you can use python train.py user_config=user_config.yaml

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Toggles (aka Feature Flags) - Martin Fowler
With a Toggle Configuration file you can now re-configure a feature flag by simply changing that file rather than re-building application code itself....
Read more >
Set Kubelet parameters via a config file - Kubernetes
Start the Kubelet with the --config flag set to the path of the Kubelet's config file. The Kubelet will then load its config...
Read more >
Loading Configuration Files | Junos OS - Juniper Networks
An override operation discards the current candidate configuration and loads the configuration in filename or the configuration that you type at the terminal....
Read more >
Command line options - Envoy Proxy
The following are the command line options that Envoy supports. ... If --config-path is also set, the values in this YAML string will...
Read more >
Load config from file & environment variables in Golang with ...
It can also read values from environment variables or command-line flags. It gives us the ability to set or override default values.
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