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

CLN: Refactor model abstraction, fix #737 #726 #753

Merged

Conversation

NickleDave
Copy link
Collaborator

This PR refactors the model abstraction, basically as described here: #737 (comment)

We replace vak.models.base.Model, that sub-classed lightning.LightningModule, with vak.models.factory.ModelFactory, that no longer sub-classes LightningModule. Instead, its __init__ takes a model definition and a model family, the latter of which is a lightning.LightningModule, and its from_config and from_instances methods return new instances of the family, with instances of the network, loss, optimizer, and metrics attributes of the definition.

This is really just a shim, in the form of several layers of indirection, to fix the broken logging for now. I'm not sure it makes it much easier to add a model (see #751).

But it does appear to fix the logging issue--logs look as expected when I inspect them now.

…d to have class variables definition and family, that are *both* used by the from_config method to make a new instance of the family with instances of the definition's attributes (trust me, this makes perfect sense)
…s Model, then make a new instance of the subclass, add that instance to the registry, and then return the instance. This makes it possible to call the 'from_config' method of the instance and get a new class instance. Think of the instance as a Singleton
…ingleton that can return new lightning.Module instances with the appropriate instances of network + loss + optimizer + metrics from its from_config method
…ass anymore, but we do change Model instance's __name__,__doc__, and __module__ to match those of the definition
…ot pytorch_lightning.LightningModule :eyeroll:) and to no longer pass network, loss, etc to super().__init__ since its no longer a sub-class of models.base.Model
…ghtning.pytorch.LightningModule) and to no longer pass network, loss, etc to super().__init__ since its no longer a sub-class of models.base.Model
…ing with duplicate values -- we need to not use the 'epoch' Scalar since it's all zeros
@NickleDave NickleDave merged commit 4862c9d into main May 6, 2024
0 of 4 checks passed
@NickleDave NickleDave deleted the refactor-model-class-to-not-subclass-lightning-module branch May 6, 2024 17:00
NickleDave added a commit that referenced this pull request May 6, 2024
NickleDave added a commit that referenced this pull request May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant