I’m writing a little toy example to better understand custom callbacks and ran into a few questions. I wrote the following that saves model weights after each epoch.
@dataclass class SaveModel(LearnerCallback): """Save Latest Model""" def __init__(self, learn:Learner): super().__init__(learn) def on_epoch_end(self, epoch:int, **kwargs): dt = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') self.learn.save('my_model_' + dt) return False learn = RNNLearner.language_model(data_lm, pretrained_model=URLs.WT103, callback_fns=SaveModel) learn.fit(2, 1e-2)
I’m getting the expected output – which is the model weights to be saved to disk after each epoch. But my questions are:
- Is it possible to pass in function arguments to
SaveModelwhen calling the callback? So as a trivial example, what if I wanted to pass a model name prefix into
learn. Where would I do this?
- What is the difference between passing
callbacksinto the learner object?