Lightning-AI / Lightning-AI/pytorch-lightning
EarlyStopping in the middle of an epoch
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Description & Motivation
I'm fitting a normalizing flow to learn the mapping between two embedding spaces. The first embedding space is sampled using the mapper of a pretrained stylegan and the second embedding space is derived by a pretrained covnet. I want to learn a mapper from the second embedding space back to the first one. Since the stylegan can produce infinite data, I'm using an iterable dataset across one single epoch that encompasses the entire training run. So, I want `EarlyStopping` to trigger in the middle of the epoch. Validation data isn't available.
### Pitch
An option called `check_interval` should be added to `EarlyStopping`. If the value is a float, it is the fraction of an epoch between checks. If the value is an integer, it is the amount of training steps between checks. For the change to be non-breaking, its default should be `1.0`.
### Alternatives
Currently, I'm passing the EarlyStopping callback to the LightningModule and manually calling the check at the end of each training batch:
```py
def on_train_batch_end(self, outputs, batch, batch_idx):
self.early_stopping_callback._run_early_stopping_check(self.trainer)
```
### Additional context
_No response_
cc @borda @carmocca @awaelchli
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the EarlyStopping callback and its existing _run_early_stopping_check entry point, then trace when checks are currently triggered during training. Define the check_interval behavior for fractional epochs and integer step counts, preserve the default behavior, and verify that checks work without validation data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100