You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Structured config with dict as default value does not handle overrides correctly #2350
A structured config with a dictionary-valued default (specified via default factory) will not instantiate properly when that field is overridden with another dictionary during instantiation. The override will be merged with the default value during instantiation.
I found that this error manifests for hydra 1.1.0-1.2.0 and omegaconf 2.1.0 - 2.2.3. The error seems to be particular to dictionaries.
Thanks for reporting this. I confirmed this still reproduces on current main.
The current behavior comes from instantiate() recursively merging call-site kwargs into the config before instantiation. For normal Python call semantics, this is surprising: a kwarg passed to instantiate() should override/replace the configured argument value, not merge into it.
We will handle this in Hydra 1.4 as a breaking bugfix: call-site kwargs should replace non-target argument values. We will preserve the documented nested-target patching behavior, e.g. instantiate(cfg.trainer, optimizer={"lr": 0.3}), where optimizer is itself an instantiate config.
If we later want arbitrary call-site merge semantics, that should be explicit via a marker/wrapper rather than implicit recursive merging.
Activity
LucaButera commentedon Apr 24, 2023
Any update on this? I am currently facing the same issue
omry commentedon Jul 3, 2026
Thanks for reporting this. I confirmed this still reproduces on current
main.The current behavior comes from
instantiate()recursively merging call-site kwargs into the config before instantiation. For normal Python call semantics, this is surprising: a kwarg passed toinstantiate()should override/replace the configured argument value, not merge into it.We will handle this in Hydra 1.4 as a breaking bugfix: call-site kwargs should replace non-target argument values. We will preserve the documented nested-target patching behavior, e.g.
instantiate(cfg.trainer, optimizer={"lr": 0.3}), whereoptimizeris itself an instantiate config.If we later want arbitrary call-site merge semantics, that should be explicit via a marker/wrapper rather than implicit recursive merging.
Replace configured value with a dict call-site argument
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Complete structured config dict override coverage
Preserve Structured Config semantics for dict overrides
Preserve structured and target config override semantics
Preserve structured and target config override semantics
Replace configured value with a dict call-site argument (#3352)