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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] return configuration variable from hydra.main function #407
Comments
Hi, If you just want to generate a config object you can use the compose API, but this will not provide command line integration, automatic working directory, logging support and other things. |
So if I have modules that rely on this global config, how would I do that by wrapping all the logic inside the main()? I can't quite figure out how I should use this for more complicated experiments setting, I couldn't just write all the parameters inside a big main() or passing the config as an argument everytime I need it. |
I recommend that you do pass the config around (or parts of it). @hydra.main(config_path="config_hydra/config.yaml")
def my_app(cfg : DictConfig) -> DictConfig:
global config
config = cfg
# call the rest of your logic from here.
if __name__ == "__main__":
my_app() As I said, I do recommend that instead of doing this you pass the config or a part of it forward. for example: def train(cfg):
...
def test(cfg):
...
@hydra.main(config_path="config_hydra/config.yaml")
def my_app(cfg : DictConfig) -> DictConfig:
if cfg.action == "train":
train(cfg)
elif cfg.action == "test":
test(cfg)
if __name__ == "__main__":
my_app()
|
Thank you! That helps. |
I encountered this thread because some of the debugger frames were getting lost when there is an error in the function encapsulated by the Hydra decorator. Hence I was trying to get the config in the same way as @noklam did. It turned out it's already solved in this PR #930 To not lose any debugger stack frames, set HYDRA_FULL_ERROR to 1. That should do the trick. I hope that helps! |
@krishnachaitanya7, I recommend that you always use the latest stable Hydra version :). |
@omry definitely! Thank you for the tip! |
馃悰 Hydra return config variable
I try to return the config from a function but get a None return instead. I am trying to keep the config as a global variable for other modules to import the config
To reproduce
** Minimal Code/Config snippet to reproduce **
** Stack trace/error message **
Expected Behavior
System information
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: