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.

[Bug] return configuration variable from hydra.main function

See original GitHub issue

🐛 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

import hydra
from omegaconf import DictConfig

from runner import Runner


@hydra.main(config_path="config_hydra/config.yaml")
def my_app(cfg : DictConfig) -> DictConfig:
    # print(cfg.pretty())
    return cfg



if __name__ == "__main__":
    cfg = my_app()
    print(cfg)

** Minimal Code/Config snippet to reproduce **

** Stack trace/error message **

None
// Paste the bad output here!

Expected Behavior

System information

Additional context

Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
noklamcommented, Feb 11, 2020

Thank you! That helps.

1reaction
krishnachaitanya7commented, Dec 13, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specializing configuration - Hydra
We want to specialize the config based on the choice of the selected dataset and model: Furthermore, we only want to do it...
Read more >
python 3.x - Using hydra.main on main method - Stack Overflow
I'm running a requests call on an API endpoint, whose request params are hidden in a config file and I decided to try...
Read more >
Complete tutorial on how to use Hydra in Machine Learning ...
@hydra.main(config_path="config", config_name="config") This is the main decorator function that is used when any function requires contents ...
Read more >
Configuration Management For Data Science Made Easy With ...
Here's my FREE 7-step guide to help you consistently design great software: https://arjancodes.com/designguide.Dealing with configuration ...
Read more >
Tutorial: Learning Hydra for configuring ML experiments
Sometimes, we might need to load our configuration file outside the main function. While we can do this with OmegaConf , it does...
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