vak icon indicating copy to clipboard operation
vak copied to clipboard

ENH/CLN: replace sub-classing Engine/Model methods with callbacks / classes

Open NickleDave opened this issue 4 years ago • 1 comments

we want to avoid subclassing for code sharing

WRT this, engine.Model should still be used for training / predicting / etc., but

  • the pseudo-private _train, _predict etc should be removed from the class
    • original design was that a user would sub-class Model and override these methods if necessary
  • instead these should be functions defined external to the class as default_train_func, default_predict_func, etc.
  • each method should now accept an argument something_func, a callback that defaults to the corresponding default for that method. E.g. Model.predict(predict_func=default_predict_func)
  • alternatively go for full-on classes and allow each method to accept a Trainer, Predictor, etc., argument with a defined interface but no other constraints on what's passed in? Again with a default

NickleDave avatar Nov 27 '21 04:11 NickleDave

I think we should just rename Engine and pass in torch.Module models. This feels like the most explicit API that best provides composability: there's an engine, it takes in models and functions and uses the function to do things with the models

NickleDave avatar Jul 01 '22 02:07 NickleDave

Closing because after switching to lightning as a backend in #597 this is no longer needed; one can write custom train_step, predict_step, etc., for models, achieving the same thing, and the core lightning.Trainer similarly has many hooks and allows for callbacks during training

NickleDave avatar Dec 18 '22 01:12 NickleDave