Add support for 4 merging modes of DictConfig #917
+212
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See the description of omegaconf/omegaconf.py. Essentially, the idea is to introduce 4 different modes of merging DictConfigs on their keys, where the keys are to be understood as nested keys. E.g. the dictionary
or
{a1: 1, a2: {b1: 2, b2: {c1: 3, c2: 4}}}
can be understood as a dictionary mapping nested keys to values asThe way of merging can be provided through the
how
keyword inOmegaConf.merge()
, for example asOmegaConf.merge(config1, config2, how='left')
.The four different modes are as follows:
1. left:
Only merge on keys from the left DictConfig. E.g.
{a1: 1, a2: {b1: 2, b2: 3}}, {a2: {b2: 11, b2: 12}, a3: 13} -> {a1: 1, a2: {b1: 2, b2: 11}}
2. inner:
Only merge on keys from both DictConfigs. E.g.
{a1: 1, a2: {b1: 2, b2: 3}}, {a2: {b2: 11, b2: 12}, a3: 13} -> {a2: {b2: 11}}
3. outer-left:
Merge on keys from both DictConfigs. E.g.
{a1: 1, a2: {b1: 2, b2: 3}}, {a2: {b2: 11, b2: 12}, a3: 13} -> {a1: 1, a2: {b1: 2, b2: 11, b3: }}
If nesting levels conflict, use keys on the left. E.g.
{a1: {b1: 9}}, {a1: {b1: {c1: 21}}, a2: 22} -> {a1: {b1: 9}, a2: 22}
4. outer-right:
Merge on keys from both DictConfigs (see outer-left).
If nesting levels conflict, use keys on the right. E.g.
{a1: {b1: 9}}, {a1: {b1: {c1: 21}}, a2: 22} -> {a1: {b1: {c1: 21}}, a2: 22}
The current default is
"outer-right"
, which corresponds to the current Omegaconf merging behavior.