Skip to content

Commit ccd87ca

Browse files
vballolitchatoncarmocca
authored
Changes resume_from_checkpoint warning to error (#7075)
Co-authored-by: thomas chaton <[email protected]> Co-authored-by: Carlos Mocholí <[email protected]>
1 parent 6b29211 commit ccd87ca

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pytorch_lightning/trainer/connectors/checkpoint_connector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ def restore(self, checkpoint_path: str, on_gpu: bool) -> bool:
8787
# Try to read the checkpoint file at `checkpoint_path`. If not exist, do not restore checkpoint.
8888
fs = get_filesystem(checkpoint_path)
8989
if not fs.exists(checkpoint_path):
90-
rank_zero_warn("No checkpoint file exists at `resume_from_checkpoint`. Start from scratch")
91-
return False
90+
raise FileNotFoundError(
91+
f"Checkpoint at {checkpoint_path} not found. Aborting training."
92+
)
9293

9394
checkpoint, load_optimizer_states = self.trainer.training_type_plugin.restore_model_state_from_ckpt_path(
9495
checkpoint_path, map_location=lambda storage, loc: storage

tests/models/test_restore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def test_try_resume_from_non_existing_checkpoint(tmpdir):
148148
trainer.fit(model, datamodule=dm)
149149
# `True` if resume/restore successfully else `False`
150150
assert trainer.checkpoint_connector.restore(str(tmpdir / "last.ckpt"), trainer.on_gpu)
151-
assert not trainer.checkpoint_connector.restore(str(tmpdir / "last_non_existing.ckpt"), trainer.on_gpu)
151+
with pytest.raises(FileNotFoundError, match="Aborting training"):
152+
trainer.checkpoint_connector.restore(str(tmpdir / "last_non_existing.ckpt"), trainer.on_gpu)
152153

153154

154155
class CaptureCallbacksBeforeTraining(Callback):

0 commit comments

Comments
 (0)