Can I take only certain keys from each config file?

101 Views Asked by At

Let's say I have two config files in the "base" directory, "base/v1.yaml" and "base/v2.yaml". Let's say each of these are structured something like:

model:
  embedding_size: 20
  num_layers: 4
  ...

dataset:
  name: ...

If I have a new yaml and am trying to set defaults, is there a way I can choose to only take e.g. "model" from v1, and then "dataset" from v2? Ideally, something like:

defaults:
  - base/v1.model
  - base/v2.dataset
  - _self_

...
2

There are 2 best solutions below

2
On BEST ANSWER

It's not exactly what you are asking for but you can load both and save the relevant parts in a separate field e.g.:

defaults:
 - v1@base/v1
 - v2@base/v2
 - _self_

model: ${v1.model}
dataset: ${v2.dataset}

the v1@base/v1 syntax stores the contents of base/v1.yaml in a field called v1

the ${} is used for value interpolation

0
On

If I have a new yaml and am trying to set defaults, is there a way I can choose to only take e.g. "model" from v1, and then "dataset" from v2?

No. You will have to restructure your config, disentangling them into two config groups (e.g. model and dataset).