Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can update a config_dict from yaml/json file? #35

Open
Chutlhu opened this issue Oct 7, 2024 · 2 comments
Open

Can update a config_dict from yaml/json file? #35

Chutlhu opened this issue Oct 7, 2024 · 2 comments

Comments

@Chutlhu
Copy link

Chutlhu commented Oct 7, 2024

Hi all, thank you for this nice library.

I am using config_dicts in my ML pipeline as explained in the README.
I currently use the CLI interface to run different ML models with different parameters.
Instead, is it possible to update a ConfigDict using a yaml config file generated via ConfigDict().to_yaml()?

@Chutlhu Chutlhu changed the title Can overwrite a config_dict from yaml/json file? Can update a config_dict from yaml/json file? Oct 7, 2024
@xk-huang
Copy link

I use OmegaConf to achieve this:

import os.path as osp
from omegaconf import OmegaConf

FLAGS_DEF = {}
condig_root_name="src.config"
for flag_values in FLAGS.get_flags_for_module(condig_root_name):
    # NOTE xk: flag_values.name is the key, flag_values.value is the ConfigDict, which has `to_dict`, `to_yaml` methods.
    FLAGS_DEF[flag_values.name] = flag_values.value

config = OmegaConf.create({k: v.to_dict() for k, v in FLAGS_DEF.items()})

# save config
config_path = osp.join(config.main.ckpt_dir, "config.yaml")
OmegaConf.save(config=config, f=config_path)

@Conchylicultor
Copy link
Member

You can simply pass the json dict to the ConfigDict constructor:

cfg = ConfigDict(json.loads(data))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants