Hydra覆盖.YAML配置中的插值dict值

发布于 2025-02-04 05:50:14 字数 804 浏览 2 评论 0原文

假设我有以下配置:

foo:
  a : 1
  b : 2
  c :
    aa : ???
    bb : 2
bar : ${foo.c}
baz : ${foo.c}

并且想要在barbaz中专业化(或覆盖)aa。有什么干净的方法可以做到吗?我看不到如何在没有痛苦的情况下使用默认列表来执行此操作...

如果有一些语法,

...
bar : ${foo.c}
bar.c.aa : 1
baz : ${foo.c}
baz.c.aa : 2

或者使用DSL语法进行命令行覆盖...

编辑:编辑: 我希望结果是

foo:
  a : 1
  b : 2
  c :
    aa : ???
    bb : 2
bar :
  c : 
    aa : 1
    bb : 2
baz : 
  c : 
    aa : 2
    bb : 2

(忽略foo.c.aa缺失的事实) 我知道如何以编程方式执行此操作,我问它是否可以使用某种解决方案/插值完成。

可以使用命令行(例如bar.c.aa = 1)覆盖值,我想要此功能,但在.YAML文件本身中。

Let's say I have a config like the following:

foo:
  a : 1
  b : 2
  c :
    aa : ???
    bb : 2
bar : ${foo.c}
baz : ${foo.c}

and want to specialise (or override) aa in bar and baz. Is there a clean way to do this? I can't see how to do this with the defaults list without some pain...

It would be nice if there was some syntax like:

...
bar : ${foo.c}
bar.c.aa : 1
baz : ${foo.c}
baz.c.aa : 2

or perhaps using the DSL syntax for command-line overrides...

EDIT:
I want the result to be

foo:
  a : 1
  b : 2
  c :
    aa : ???
    bb : 2
bar :
  c : 
    aa : 1
    bb : 2
baz : 
  c : 
    aa : 2
    bb : 2

(ignore the fact that foo.c.aa is missing)
I know how to do this programmatically, I am asking it if can be done just using some kind of resolution/interpolation.

It is possible to override values using the command line (with e.g. bar.c.aa=1), I want this functionality but in the .yaml file itself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笙痞 2025-02-11 05:50:14

九头蛇不支持这种扩展。
您可以通过按照描述的在这里)来实现它。

像:
您可以通过默认列表组成config节点baz.c和bar.c,具有原型foo/proto.yaml充当基础:

aa: ???
bb: 2

bar/c.yaml:

defaults:
 - /foo/c@c
c:
  aa: 1
  # bb will be "inherited" from /foo/c

baz/c.yaml:

defaults:
 - /foo/c@c
c:
  aa: 2
  # bb will be "inherited" from /foo/c

注意:

  1. 我没有运行它,所以这里可能会有一些东西,但是总的来说,这是必经之路。
  2. 您的例子是不透明的,很难说什么是重要的,什么不是。可能有一种更干净的方法来实现您实际要做的事情。

Hydra does not support this kind of extension.
You can achieve it by extending configs as described here.

Something like:
You can compose the config node baz.c and bar.c via the defaults list, having a prototype foo/proto.yaml act as a base:

aa: ???
bb: 2

bar/c.yaml:

defaults:
 - /foo/c@c
c:
  aa: 1
  # bb will be "inherited" from /foo/c

baz/c.yaml:

defaults:
 - /foo/c@c
c:
  aa: 2
  # bb will be "inherited" from /foo/c

Note:

  1. I didn't run it so there could be something off here, but in general that's the way to go.
  2. Your example is opaque and it's hard to say what is important and what is not. There could be a cleaner way to achieve what you are actually trying to do.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文