Metalhead.jl
Metalhead.jl copied to clipboard
Abstract type for the models
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
@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
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.
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
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?
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.