Skip to content

Commit 8ba6381

Browse files
committed
add exception prefix to checkpoints saved on exception
1 parent 467c57b commit 8ba6381

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/lightning/pytorch/callbacks/model_checkpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class ModelCheckpoint(Checkpoint):
214214
CHECKPOINT_JOIN_CHAR = "-"
215215
CHECKPOINT_EQUALS_CHAR = "="
216216
CHECKPOINT_NAME_LAST = "last"
217+
CHECKPOINT_EXCEPTION_PREFIX = "exception"
217218
FILE_EXTENSION = ".ckpt"
218219
STARTING_VERSION = 1
219220

@@ -345,7 +346,7 @@ def on_validation_end(self, trainer: "pl.Trainer", pl_module: "pl.LightningModul
345346
def on_exception(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", exception: Exception) -> None:
346347
if self._should_save_on_exception(trainer):
347348
monitor_candidates = self._monitor_candidates(trainer)
348-
filepath = self.format_checkpoint_name(metrics=monitor_candidates)
349+
filepath = self.format_checkpoint_name(metrics=monitor_candidates, prefix=self.CHECKPOINT_EXCEPTION_PREFIX)
349350
self._save_checkpoint(trainer, filepath)
350351
self._save_last_checkpoint(trainer, monitor_candidates)
351352
rank_zero_info(f"An exception was raised saved checkpoint to {filepath}")

0 commit comments

Comments
 (0)