Skip to content

Commit bbeb0de

Browse files
Address pre-commit hook failures and add comment to explain checkpointing logic with time based validation.
1 parent f29ee07 commit bbeb0de

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/lightning/pytorch/callbacks/model_checkpoint.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class ModelCheckpoint(Checkpoint):
137137
If ``True``, checkpoints are saved at the end of every training epoch.
138138
If ``False``, checkpoints are saved at the end of validation.
139139
If ``None`` (default), checkpointing behavior is determined based on training configuration.
140+
If ``val_check_interval`` is a str, dict, or `timedelta` (time-based), checkpointing is performed after
141+
validation.
140142
If ``check_val_every_n_epoch != 1``, checkpointing will not be performed at the end of
141143
every training epoch. If there are no validation batches of data, checkpointing will occur at the
142144
end of the training epoch. If there is a non-default number of validation runs per training epoch

src/lightning/pytorch/loops/training_epoch_loop.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,8 @@ def _should_check_val_fx(self, data_fetcher: _DataFetcher) -> bool:
538538
interval = self.trainer._val_check_time_interval
539539
if interval is not None:
540540
now = time.monotonic()
541-
if now - self.trainer._last_val_time >= interval:
542-
# time’s up → tell Trainer to validate
543-
return True
544-
return False
541+
# if time’s up → tell Trainer to validate
542+
return now - self.trainer._last_val_time >= interval
545543
# TODO: let training/eval loop handle logic around limit_*_batches and val_check_batch
546544
is_val_check_batch = is_last_batch
547545
if isinstance(self.trainer.limit_train_batches, int) and is_infinite_dataset:

src/lightning/pytorch/trainer/trainer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def __init__(
216216
``check_val_every_n_epoch`` > 1, validation is aligned to epoch multiples: if the interval elapses
217217
before the next multiple-N epoch, validation runs at the start of that epoch (after the first batch)
218218
and the timer resets; if it elapses during a multiple-N epoch, validation runs after the current batch.
219-
For ``None`` or ``1``, the time-based behavior of ``val_check_interval`` applies without additional alignment.
219+
For ``None`` or ``1``, the time-based behavior of ``val_check_interval`` applies without additional
220+
alignment.
220221
Default: ``1``.
221222
222223
num_sanity_val_steps: Sanity check runs n validation batches before starting the training routine.

0 commit comments

Comments
 (0)