python - 使用未与已安装的 Hydra 应用程序打包的配置
问题描述
在打包 Hydra 应用程序并包含一个脚本作为入口点时,可以在任何地方从命令行调用该脚本。调用该脚本时,将使用包中包含的配置。有没有办法修改配置搜索路径,以便可以将不同的配置传递给脚本?
例如:
应用程序.py
import hydra
@hydra.main(config_path="conf", config_name="config")
def my_func(cfg):
print(cfg)
配置.yaml
key: value
another_key: second_value
使用entry_points={"console_scripts": ["hydra_app_test = hydra_app_test.app:my_func"]}
.
$ hydra_app_test
{'key': 'value', 'another_key': 'second_value'}
我希望能够定义一个本地配置并将其传递给hydra_test_app
. 这样的事情可能吗?
一些/config/path/config.yaml
key: not_value
mon: key
$ hydra_app_test --config-override=some/config/path
{'key': 'not_value', 'mon': 'key'}
我曾尝试使用--config-dir
and--config-path
覆盖,但没有任何运气。
$ hydra_app_test --config-dir=some/config/path
{'key': 'value', 'another_key': 'second_value'}
$ hydra_app_test --config-path=some/config/path
Primary config module 'hydra_app_test.some.config.path' not found.
Check that it's correct and contains an __init__.py file
有趣的是,如果您不使用已安装的应用程序,但将 app.py 作为脚本运行(具有必要的if __name__ == "__main__"
逻辑) ,则此模式有效
python path/to/app.py --config-path=some/config/path
{'key': 'not_value', 'mon': 'key'}
也许我只是在这里遗漏了一些东西,但看起来你应该能够为已安装的包脚本和 python 脚本复制相同的行为。
解决方案
推荐阅读
- java - 在 Spring 的 swagger 中,是否可以将 Responses 的示例值设置为与方法的返回类型不同?
- firebase - firebase firestore 子集合访问规则
- ios - 如何知道在哪个应用程序键盘中打开?
- php - PHP 数组代码在 PHP 7.2.26 中不起作用
- telerik-reporting - Telerik 报告错误:当前上下文中不存在 sqlDataSource
- python - 列表框选择上的“元组索引超出范围”
- flutter - 声音和弹出通知在颤动中不起作用
- r - 从常数值减去列总和
- r - 将 Voronoi 树图保存为 R 中的高分辨率 JPG 或 PNG 图像
- unity3d - 尝试使用 facebook 登录时出现 NoClassDefFoundError