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 a ModelDefinition class #406

Closed
NickleDave opened this issue Nov 27, 2021 · 3 comments
Closed

add a ModelDefinition class #406

NickleDave opened this issue Nov 27, 2021 · 3 comments
Labels
ENH: enhancement enhancement; new feature or request

Comments

@NickleDave
Copy link
Collaborator

i.e. an ABC

which will be, like, pytorch-lightning but w/out the sub-classing

goal is to provide a way to specify a model programatically that includes network, optimizer, and whatever else is needed

that could then be passed to an Engine that trains, predicts, etc

from abc import ABC

class Model(ABC):
    @property
    @abstractmethod
    network
       
@NickleDave NickleDave added this to the 0.5.0 milestone Nov 27, 2021
@NickleDave NickleDave added the ENH: enhancement enhancement; new feature or request label Dec 8, 2021
@NickleDave
Copy link
Collaborator Author

Have decided I don't want to do this, in favor of the approach in #536

@NickleDave NickleDave changed the title implement a Model interface? add a ModelDefinition class Nov 24, 2022
@NickleDave
Copy link
Collaborator Author

NickleDave commented Nov 24, 2022

After working on implementing #536 I have decided I actually do want to do this, kind of

We will have a separate ModelDefinition class, that declares in code how a model is defined. Our definition of a neural network model is the network function itself, the loss function, and the optimizer, in addition to a set of metrics.

In terms of code, then, models defined in the vak codebase and by users will look like a dataclass, where a required set of "fields" defines a model. These "fields", i.e. class variables, will then be network, loss, optimizer, metrics. To declare these expected class variables in code, and provide a type for model definitions that can be used by a static type checker, we implement a ModelDefinition with its own class variables network, loss, etc.

To avoid these ModelDefinition class variables shadowing/clashing with an instance of a Model that will have as attributes the instances of network, optimizer, and so on, we will implement a Model base class that attaches the ModelDefinition as its own attribute, definition. When we instantiate a model, that subclasses Model, the Model.__init__ method will use its definition to create the new instances of network and so on, which become the attributes of the model instance.

@NickleDave
Copy link
Collaborator Author

Closed by #605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ENH: enhancement enhancement; new feature or request
Projects
None yet
Development

No branches or pull requests

1 participant