-
Notifications
You must be signed in to change notification settings - Fork 493
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
The current instantiation does not trigger the initialization of submodules #2273
Comments
I love this question! We deliberately decided against allowing submodule initialization akin to Hydra for a few reasons:
You can see the original PR discussion for some context: #406 If it starts becoming imperative to enable submodule initialization for better UX on more nested components for complex features, then I'm open to revisiting this discussion. But so far we've been able to work around this. I'd be curious to understand what you are trying to achieve with recursive instantiation. One way we typically work around this is having "builder" functions that takes all the flat params that can be easily specified in the config with only one instantiation, and the builder constructs all the components needed for you. This is exactly how many of our component builders work to instantiate any model. |
There are two perspectives: The first is the need for a quick migration, moving from another algorithm or framework to Torchtune, with support for submodule initialization. The required code changes are minimal, and optimizations for code and performance can be considered later. The second is that, in the future, users can define the model structure through the configuration, without the need to write code every time. |
and it can work like this:
|
Not sure I fully understand. Are you trying to migrate from another framework that uses recursive instantiation or Hydra?
Right, I can see why this is compelling. And while it would be convenient for config power users to define a full architecture in config, it brings you away from the actual python code itself. And I would also say that builder functions can achieve the same thing, without causing bloated configs:
Then, in the config:
Basically, in your example This is just the opinionated design stance we decided to take. Open to discussing any difficulties you may be having doing this for your use case, if it's not working out. |
Currently, the instantiation method used in Torchtune's configuration does not trigger the initialization of its submodules. The instantiate function from hydra.utils does handle this, but it differs from the current approach in Torchtune. Is there an elegant way to trigger the initialization of submodules?
Below is a simple example of how hydra.utils successfully triggers the initialization of submodules.
The text was updated successfully, but these errors were encountered: