Train a PyTorch model with validation monitoring and stop after the configured number of unimproved epochs.