Metalhead.jl icon indicating copy to clipboard operation
Metalhead.jl copied to clipboard

Abstract type for the models

Open theabhirath opened this issue 3 years ago • 5 comments
trafficstars

Given that all the high-level model APIs implement (m::Model)(x), backbone(m::Model) and classifier(m::Model), would it make sense to have an abstract type MetalheadModel that the models can subtype? I take it that there's no way to implement an interface for these functions that can be inherited via types but this way at least we can document in the documentation for MetalheadModel what every single model in the repo implements

theabhirath avatar Jul 15 '22 16:07 theabhirath

@darsnack @ToucheSir what do you make of this proposal? This might reduce code duplication if we could write the methods for just the MetalheadModel type (not to mention that this would make the docstrings for backbone and classifier a lot less ambiguous than just saying "use the camel-cased model names"). If https://github.com/FluxML/Flux.jl/pull/1932 landed with Flux v0.13.6 this could go even further and remove the entire pretty-printing mechanism by simply @layering the supertype

theabhirath avatar Sep 07 '22 12:09 theabhirath

I think having an abstract type that's used internally to remove duplication is fine (though I think you really only remove the forward pass and maybe @functor?). What I want to avoid is any notion that a user needs to inherit from this type for their own customized models.

darsnack avatar Sep 07 '22 13:09 darsnack

though I think you really only remove the forward pass and maybe @functor?

Also backbone and classifier.

What I want to avoid is any notion that a user needs to inherit from this type for their own customized models.

Yeah I think that we can state that explicitly in the docs, shouldn't be a problem. I'll wait on FluxML/Flux.jl#1932 to be resolved before I get this in I think

theabhirath avatar Sep 07 '22 13:09 theabhirath

Funny, I can't seem to remove @functor when I try this. It errors by saying type does not have a definite number of fields?

theabhirath avatar Sep 08 '22 02:09 theabhirath

How are you trying to do it? By using the macro? That won't work. You need to define the function functor for the abstract type.

darsnack avatar Sep 08 '22 02:09 darsnack