【问题标题】:Returning the config from the function decorated with hydra.main()从用 hydra.main() 修饰的函数返回配置
【发布时间】:2021-06-21 00:27:08
【问题描述】:

是否有一个选项可以从 @hydra.main 装饰器下的函数中获取配置对象作为字典?

我尝试过这样的事情,但它返回 None

@hydra.main(config_path="conf", config_name="config")
def my_app(cfg) -> dict:
    print(cfg) # --> work, the cfg object exists inside the function scope
    return cfg
a = my_app()
print(a)

我知道我可以使用compose API,但我不想使用它,因为它的功能有限(Tab 补全、Multirun 等)

【问题讨论】:

    标签: python fb-hydra


    【解决方案1】:

    没有。 @hydra.main() 不会有意返回值。 (如果您使用--multirun 并且您的函数多次返回,您希望返回值是多少?)

    从您的 @hydra.main 函数中调用您的逻辑并将 cfg 对象传递给它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 2021-01-17
      • 2020-04-28
      • 2021-06-30
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多