this would go well with a change to the config definition of an instantiated object:
model:
cls: foo.bar.ResNet
params:
num_layers: 50
model:
_target_: model.ResNet
num_layers: 50
Once this is implemented, we can describe recursive instantiation like:
trainer:
_target_: trainer.Trainer
batch_size: 32
model:
_target_: model.ResNet
num_layers: 50
An remaining open question is how to support passthrough for nested objects.
Currently, passthrough can override individual values:
trainer = instantiate(cfg.trainer, batch_size=64)
a possible approach is for nested objects is to use a dictionary:
trainer = instantiate(cfg.trainer, batch_size=64, overrides={"trainer.model.num_layers": 50})
Is the New style intended to replace the current one?
Not entirely. If you don't own the the dataclass you will not be able to add the _type_ field to it.
Okay my original concern was if we could keep around the params namespace but if both the styles can be used, that request is moot.
we may want to deprecate it in favor of
args:
- positional_1
- positional_1
kwargs:
named_1 : 1
named_2 : 2
we may want to deprecate it in favor of
args: - positional_1 - positional_1 kwargs: named_1 : 1 named_2 : 2
Looks good!
This is coming in Hydra 1.1.
I have a question for people who liked this issue (indicating that they would like to have this supported):
I would like to make recursive instantiation the default, but this is a breaking change for people that are actually interested in it because right now they are getting the nested config as a config and they need to manually call instantiate on it.
Assuming that there will be an alternative way to instantiate non recursively, is such a breaking change acceptable to folks here?
Like this comment to indicate yes and dislike it to indicate no.
Feel free to followup with a discussion.
I second having this be the default behavior. For me personally it is an acceptable breaking change, since it allows to have portable code (that does not depend on Hydra) and use Hydra on top for configuring. Currently, calling instantiate manually breaks the modularity since we can only instantiate via Hydra this way (and we would like to be able to do both).
Can you explain more how instantiate behaving one way or another interacts with your ability to do things outside of Hydra?
This is now in Hydra master branch.
Feedback welcome.
Most helpful comment
This is coming in Hydra 1.1.
I have a question for people who liked this issue (indicating that they would like to have this supported):
I would like to make recursive instantiation the default, but this is a breaking change for people that are actually interested in it because right now they are getting the nested config as a config and they need to manually call instantiate on it.
Assuming that there will be an alternative way to instantiate non recursively, is such a breaking change acceptable to folks here?
Like this comment to indicate yes and dislike it to indicate no.
Feel free to followup with a discussion.