-
-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Consider supporting singleton pattern in recursive instantiation #1393
Comments
This would be very powerful. It would effectively enable Hydra to be used for dependency injection (but orchestrated via configs). |
This comment was marked as outdated.
This comment was marked as outdated.
As a note, I would like this to work: misc:
a:
_target_: mymodule.A
_singleton_: true
foo: 1
b:
_target_: mymodule.B
bar: 2
a: ${misc.a}
c:
_target_: mymodule.C
baz: 3
a: ${misc.a} i.e., the reference would not need to happen inside the same object to be instantiated. This may be very useful for cases where the same object (say some datapipeline) is to be used by models or other things, while keeping some structure to the config |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Hi, I noticed that this was initially part of the Hydra 1.3.0 milestone but was removed. It seems like a very useful feature to have. Are there any updates on when we can expect this feature? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I'll comment to record one potential issue I see with the proposed API. It looks like calling from omegaconf import OmegaConf
cfgA = OmegaConf.create("""
object1:
_target_: MyTarget
_singleton_: true
object2: ${object1}
""")
cfgB = cfgA.copy()
OmegaConf.resolve(cfgB)
assert OmegaConf.to_yaml(cfgB) == """\
object1:
_target_: MyTarget
_singleton_: true
object2:
_target_: MyTarget
_singleton_: true
""" Concretely, how would Hydra know that |
@Jasha10 thank you for the response. Just to stress out the issue, in most image generation/video generation projects we instantiate objects that use GPU and other expensive resources, and use them multiple times. Without this feature we need to manually pass these objects. This workaround breaks the clean flow that hydra usually enables 😢 |
Is there any progress on this? The lack of this feature breaks the free config-based pattern that hydra enables for deep learning applications, as already stated by @yuvalkirstain. |
The following config can in theory be used to instantiate one object
This will will probably require changes in OmegaConf.
The text was updated successfully, but these errors were encountered: