Here is my code, I set patience=3. My max epoch=10. I find that the model always ends at epoch=3. The model seems to monitor epoch=0 as the max val_acc.
checkpoint_callback = ModelCheckpoint(monitor='val_acc',
dirpath="{}".format(save_log_path),
filename='best_{}'.format(seed),
save_top_k=1,
mode='max',
save_weights_only=False,
save_last=False)
early_stop_callback = EarlyStopping(monitor="val_acc", min_delta=0.00, patience=args.patience,
verbose=False, mode="max")
trainer = Trainer(devices="auto", accelerator="auto", precision=16,
strategy=DDPStrategy(find_unused_parameters=True),
logger=tb_logger, log_every_n_steps=10, callbacks=[checkpoint_callback, early_stop_callback],
max_epochs=args.epochs, detect_anomaly=True)
def validation_step(self, batch, batch_idx, dataloader_idx=None):
f1, precision, recall, acc, current_batch_size = self.share_val_step(batch)
metrics = {'val_f1': f1,'val_acc': acc, 'val_precision': precision, 'val_recall': recall}
self.log_dict(metrics, prog_bar=True, logger=True, on_epoch=True,
rank_zero_only=True, batch_size=current_batch_size)