2

是否有一个选项可以从@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 等)

4

1 回答 1

2

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

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

于 2021-06-20T16:25:45.270 回答