Passing the early_stop_callback to the Trainer
I am trying to pass my earlystopping callback to the trainer but I can't figure out how to do so. The trainer is initialized in my def(main) and the arguments are being passed to it using the argument parser.
If the parser only accepts arguments of type bool, int and str, how can I pass it this callback:
early_stop_callback = EarlyStopping(monitor='avg_val_loss',patience=hparams.val_patience)
EDIT: and just callbacks in general. Such as on_train_end and on_test_end, how can I add them to the trainer if I have set up the code in the following manner.
Code
def main(hparams):
# Initialise model 
model = NFLRush(hparams)

# Set early stopping 
#early_stop_callback = EarlyStopping(monitor='avg_val_loss',patience=hparams.val_patience)

# Set trainer
trainer = pl.Trainer.from_argparse_args(hparams)

# Train model 
trainer.fit(model)

if name == 'main':
# Data import details
fileDir = os.path.dirname(os.path.abspath(__file__))   # Directory of the Module
rootDir = os.path.dirname(fileDir)                   # Directory of the Module directory
modelDir = str(rootDir + '/Models/')
logDir = modelDir+'lightning_logs/'

parser = ArgumentParser()

# Trainer
parser.add_argument('--min_epochs', type=int, default=1)
parser.add_argument('--max_epochs', type=int, default=5)
parser.add_argument('--overfit_pct', type=int, default=0)
parser.add_argument('--default_save_path', type=str, default=modelDir)

# Add hyperparameters
hparams = parser.parse_args()

# Train
main(hparams)

What have you tried?
I can obviously contstruct my Trainer call differently as such:
trainer = pl.Trainer(experiment= exp, max_epochs=hparams.max_epochs, overfit_pct = hparams.overfit_pct, reload_dataloaders_every_epoch = True, early_stop_callback=early_stop_callback, default_save_path=hparams.default_save_path, gpus=0)
but this still does not let me activate and deactivate the callback using the previous structure. I guess I kind of solved my problem for myself.