just as an update, I implemented the following callbacks which I know people have been asking for:


ModelCheckpoint - saves model weights during training here 167


EarlyStopping - terminates training if loss doesnt improve here 93


LearningRateScheduler - schedule LR according to current epoch/LR/loss here 44


ReduceLROnPlateau - reduces LR if loss doesnt improve here 43


CSVLogger - logs train/val loss and other metrics to csv file during training here 42


To note, these can all be used in manual training by instantiating the class and calling the appropriate function - e.g. callback.on_batch_begin() or callback.on_epoch_begin()
Happy to answer any questions or take requests.
Examples of all the callbacks:
from torchsample.callbacks import ModelCheckpoint
callbacks = [ModelCheckpoint(file='/users/ncullen/desktop/test/model_{epoch}_{loss}.pt',
                             monitor='val_loss',
                             save_best_only=False,
                             max_checkpoints=3)]

from torchsample.callbacks import CSVLogger
callbacks = [CSVLogger(file='/users/ncullen/desktop/test/logger.csv',append=True)]

from torchsample.callbacks import EarlyStopping
callbacks = [EarlyStopping(monitor='val_loss',
                           min_delta=0,
                           patience=2)]

from torchsample.callbacks import LearningRateScheduler
save_lrs = []
def lr_schedule(epoch, lr, **kwargs):
    """exponential decay"""
    new_lr = lr[0] * 1e-5**(epoch / 200)
    save_lrs.append(new_lr)
    return new_lr
callbacks = [LearningRateScheduler(lr_schedule)]

from torchsample.callbacks import ReduceLROnPlateau
callbacks = [ReduceLROnPlateau(monitor='val_loss', 
                               factor=0.1, 
                               patience=1,
                               cooldown=0, 
                               min_lr=1e-3,
                               verbose=1)]