-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Question: How to implement CLI shortcuts for nested configs? #2022
Comments
I'm not sure that could be achieved from a general point of view. |
At least for trainer:
criterion:
_target_: [...]
arg: 1337
config:
batch_size: ${batch_size}
batch_size: 32 This would allow |
This solution would leave |
Got it. In that case, the only workaround I can think of are:
deleting the top-level "aliases" before instantiating:aliases: List[str] = ["batch_size"]
@hydra.main(...)
def app(cfg):
OmegaConf.resolve(cfg)
for alias in aliases:
if alias in cfg:
del cfg[alias]
instantiate(cfg) Edit: Added a call to using the root level as a "scratch space":instantiate_me:
trainer:
criterion:
_target_: [...]
arg: 1337
config:
batch_size: ${batch_size}
# scratch:
batch_size: 32 @hydra.main(...)
def app(cfg):
instantiate(cfg.instantiate_me) |
This will work with recursive instantiation but in turn won't work with duplicate config detection. In |
Interesting! Would you be willing to share the code that you use for comparing an experiment with previous experiments? I'm wondering whether a strategically-placed call to |
My approach is really simple and not very pretty :) First I set root of a search to the outputs directory. Then I use
This gives me potential candidates for duplicated experiments. Then I do artifacts checks. |
Cool, thanks for sharing!
My idea was to modify def def detect_duplicated_run():
current_config = OmegaConf.load('.hydra/config.yaml')
OmegaConf.resolve(curent_config)
for alias in aliases:
current_config.pop(alias, None)
...
if '.hydra' in s:
OmegaConf.resolve(c)
for alias in aliases:
c.pop(alias, None)
... This has the drawback that you'd need the same list |
What if you use a top-level key in your config to store a list of experiment-specific alias keys? @hydra.main(...)
def app(cfg):
OmegaConf.resolve(cfg)
for alias in cfg.pop("_aliases", []):
if alias in cfg:
del cfg[alias]
instantiate(cfg) And you could add something like this to your duplicate config detection function (before the call to def detect_duplicated_run():
current_config = OmegaConf.load('.hydra/config.yaml')
OmegaConf.resolve(curent_config)
for alias in current_config.pop("_aliases", []):
current_config.pop(alias, None)
...
if '.hydra' in s:
OmegaConf.resolve(c)
for alias in c.pop("_aliases", []):
c.pop(alias, None)
... |
Closed accidentally. |
The idea of maintaining list of aliases in a root config is a really good one, I think. In my application I have couple different entry points which reuse config files (for training/inference/deployment/preprocessing). This way I have to add couple config specific python lines to each of them. This feels like it should be handled by hydra. Should I open a feature request? |
I can't promise that we'd implement such a feature; it can be implemented on the user side or by a third party library, and implementing it on the Hydra side would involve committing to a new top-level reserved key (e.g. |
Moving discussion to the FR #2032 |
So far I have resolved tons of config management issues with OmegaConf's custom resolvers. It isn't the neatest solution but from the user perspective it gets the job done. But there is one thing that I cannot do: I want to create shortcut(alias) in the top level config that will be resolved to a full path. Example:
Typing
python hydra_app.py trainer.config.batch_size=32 trainer/criterion=L1
is really cumbersome. I'd like to type this interchangeably:python hydra_app.py batch_size=32 criterion=L1
. Is there any possibility to do this?The text was updated successfully, but these errors were encountered: