-
-
Notifications
You must be signed in to change notification settings - Fork 644
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
Allow configuring the search path via the config file #274
Comments
Not sure if this is the feature I'm waiting for, but I want my users to install my app and easily point to a new config directory that overrides my defaults. My app is based on the hydra_app_example. Please advise. |
Ok, I think I figured it out. First add a default search path to config.yaml: search_path: config.yaml Then merge it using OmegaConf import hydra
from omegaconf import OmegaConf
@hydra.main(config_path='conf/config.yaml', strict = False)
def main(cfg):
if cfg.search_path is not None:
override_path = hydra.utils.to_absolute_path(cfg.search_path)
override_conf = OmegaConf.load(override_path)
cfg = OmegaConf.merge(cfg, override_conf) Now the user can run your app from any directory containing a config.yaml, or specify their own: myapp search_path=path/to/user/config.yaml |
That's a pretty good workaround. I would call this something like config_override and not search_path, as search path is an internal concept in Hydra that will eventually be exposed. Asher, can you share a bit about your project? I am curious about how people are using Hydra and for what. |
@omry It's for a project called Kamodo, which is a functional, publication-focused API for space weather models and data (though it can be used for much more!). Kamodo handles function composition, unit conversion, and automatic plot generation via function inspection, which should minimize the effort needed to create analysis pipelines and perform data-model comparisons. Kamodo is built with sympy and plotly. Most of our science users are comfortable with command-line but are inexperienced with modern programing languages. The CLI for kamodo will allow them to configure their data sources and any equations they want to use for post processing and quickly generate plots. Our users will often test different models or data sources for science relevance and will want to easily reproduce those results, so Hydra's ability to compose several overlapping configurations and have timestamped output directories is perfect for our use case. Github - https://github.com/nasa/Kamodo I'm also considering Hydra for my other project Hourly, which uses git "clock in" and "clock out" messages to track hours worked, generate time sheets, and produce work charts. Since I started freelancing, I've logged at least 1000 sessions across 5 different projects using Hourly. Currently, Hourly's cli is based on click, but I need to provide default functionality specific to a particular repo (to ignore errant clock-in/outs, etc). I'd also like to generate time sheets from related projects, so config composition would come in handy. Finally, I'm usually the only one who uses hourly, but eventually I'll need to iterate over all contributors to a project (assuming I get more users!). Project page - https://asherp.github.io/hourly/index.html |
Kamodo looks awesome, and I am really happy to start seeing serious projects that are making use of Hydra. A few notes:
I am considering creating a "Who is using Hydra" section in the docs, would you agree to write a short testimonial saying why you find it useful? |
One more thing: You can do it programmatically and automatically via the search plugin API. |
I have the similar use cases as @asherp .
@omry Can we resolve the config_path relative to the $pwd, which makes more sense in CLI cases |
You can probably achieve that now via a config searchpath plugin. |
by the way, take a look at the Application Packaging page.
|
I have a related use case I'm not sure can be supported easily right now: I would like to have an application coming with its own config file (packaged with the app, not to be edited), that would also let the user override some parameters through their own config file (stored in the directory where they use the app). I haven't looked closely yet at the config search path plugin, but reading the doc it sounds like it's going to stop at the first matching file (instead of merging configurations from multiple files). Just curious if there's an option I'm not seeing, or something I misunderstood? |
It seems like something Hydra may already support? As an example, all of Hydra's plugin gets their config added by SearchPathPlugin, example here: https://github.com/facebookresearch/hydra/blob/master/plugins/hydra_colorlog/hydra_plugins/hydra_colorlog/colorlog.py#L6-L9 |
Maybe -- I haven't looked closely at it, the reason why I thought it wouldn't work is because the doc says "When a config is requested, The first matching config in the search path is used", suggesting that there is no merging (just use whichever is found first). But I may not be understanding properly. As an example I may want to have a directory structure like this:
And I would like both config files to be merged (in my case the config found under "user_code" would only modify keys already existing in the "my_app" config, not add new keys). I managed to make it work with the Compose API but (1) I had to drop |
Configuring the defaults list (the topic of this issue) has little to do with your question. First of all, if you have two configs in the same name and the same group, only one will be visible. In 1.0, you only get one defaults list - in the primary config.
The chunkiness in this solution will be addressed once recursive default supports coming in 1.1. |
It may not have been what you had in mind when you created this issue, but #274 (comment) is pretty close to what I want to achieve.
I had a look, I may not understand it all, but I'm not sure it would work for my use case. To make things more concrete, let's take this example from Hydra docs: https://hydra.cc/docs/next/tutorials/structured_config/static_schema host: mysql007.staging And then by running The reason why I'm doubtful about recursive defaults enabling this is because of this example in the doc you shared: defaults:
- d2/model: resnet50 # model from an installed framework
- _self_
- db: mysql
# This will override the value provided by the framework
d2:
model:
num_layers: 100 Here, |
Just an additional thought: if there's a way to do it via config files it'd make sense to also be able to do it via a command line override. Something like:
|
Here is another example from the docs of the next version (both the logic this is documenting and the docs themselves are work in progress): |
Please move the discussion to a dedicated issue. |
Sorry for the hijack :) Thanks for the pointers, I think I have a better understanding now of how things currently are and how they will be in the future. I believe I can solve my problem with a slightly different approach which makes more sense in my situation, so I won't open another issue. |
@omry After reading the design doc, especially the new feature My question related to this proposal is, how can we combine that with allowing users to provide another config file/group when hydra-based framework is installed. For example, we have some configuration files installed with our hydra app, and the default configuration is: defaults:
- dataset: mnist
- model: vanilla
- trainer: basic_cv_trainer When the user has installed our framework, he/she can follow the doc to run the framework with pre-defined configurations or providing override command line arguments. Now the user wants to arrange his/her experiments in his own repo using overriding configs and the structure is like this:
Here the single yaml file can be a folder to override the default settings. According to what I learned here, the overriding yaml file (nlp/bert/version_1.yaml) should be like this: # @package _global_
default:
- overrider /dataset: swag_dataset
- override /model: bert
- override /trainer: bert_trainer
model:
bert:
d_model: 384 How can I select different overriding configs when running different tasks? Maybe add that config to the search path? |
Hi @npuichigo!
That design doc is not the latest one, this is. :).
The Config search path is similar to the PYTHONPATH or the Java CLASSPATH. Manipulation of the config search path should be done in order to add new roots to the search path. It seems like your question is more about how to use configs that are in arbitrary config groups. Please go ahead and read the following pages:
I think between those pages you should have enough information to do what you want. While you can use the config search path add different config roots and thus slightly change the config structure, I suggest that you try to leverage the default package when organizing your config (the default package marches the config group). |
Thanks for ur reply @omry.
Here I already make the installed configs of my framework march the config group, for example:
These part are aligned with the framework codes, so users have no direct access to the configs. In order to override the pre-installed config, one way is to provide command line args:
It's a little strange to record different command line args for different experiments. So they may provide another config file to override them.
Here the user configs play a role as the command line arguments.
So I still need to deal with case of two config sources (pre-installed configs / user overrides). |
|
Sorry. Just find several guys above are talking about the same thing in this thread. |
No worries. |
I updated the description of the issue with a design doc. |
Regarding previous discussions: Is the case below possible?
/configs/common/arch/arch1.yaml:
In a nutshell, is the interpolation in the search path(based on the default list or the final config) may add in the future? |
I don't think it's possible. Try to leverage default list interpolation instead. defaults:
- arch: ???
- _self_
- foo/bar: ${arch} |
Thanks for your reply! I am confused about the position of the
In conclusion, why it cannot use arguments from the command line as its interpolation?
|
My example does not have hydra.searchpath at all.
I have no idea what you are talking about. If you have following questions please create a new issue. closed issues are not a channel to get support. |
Ok, thanks. |
Design doc outlining consideration and possible implementations:
https://docs.google.com/document/d/1Dx77SThg1ugnGHvZ8Dq1FQusXDvGn0tyyWBeJ3nXvro/edit?usp=sharing
The text was updated successfully, but these errors were encountered: