Skip to content
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

Add functionality to save nn.Modules supplied as arguments when initialising LightningModule #19906

Closed
tom-hehir opened this issue May 25, 2024 · 0 comments
Labels
feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers

Comments

@tom-hehir
Copy link

tom-hehir commented May 25, 2024

Description & Motivation

There are scenarios where it makes sense to supply nn.Modules as arguments when initialising a LightningModule, indeed this seems to be endorsed in some of the Lightning docs, however it is recommended to ignore the nn.Modules when calling self.save_hyperparameters(). This pattern is inconvenient when it comes to saving/loading models, since if you simply save the LightningModule you will be unable to load it again, as you will not have the necessary information to instantiate the nn.Modules (although their weights will be stored in the checkpoint).

Pitch

When suppling nn.Modules as arguments to LightningModules, checkpoints currently save only the weights of the nn.Modules which is insufficient to instantiate the nn.Modules as part of loading the LightningModule.

Add functionality to seamlessly save nn.Modules provided as arguments to LightningModules such that the LightningModule can be loaded without having to separately save the initialisation arguments of the nn.Modules and initialise the nn.Modules before supplying them as arguments when loading the LightningModule from the checkpoint.

Alternatives

No response

Additional context

No response

cc @Borda

@tom-hehir tom-hehir added feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers labels May 25, 2024
@tom-hehir tom-hehir closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers
Projects
None yet
Development

No branches or pull requests

1 participant