Skip to content

Commit d2caff6

Browse files
committed
ValueError if no parameters
1 parent 443e229 commit d2caff6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lightning/pytorch/core/saving.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ def _load_from_checkpoint(
8686
return _load_state(cls, checkpoint, **kwargs)
8787
if issubclass(cls, pl.LightningModule):
8888
storage = _load_state(cls, checkpoint, strict=strict, **kwargs)
89-
assert len(checkpoint["state_dict"]) > 0
89+
state_dict = checkpoint["state_dict"]
90+
if not state_dict:
91+
raise ValueError(f"The state dict in {checkpoint_path!r} contains no parameters.")
92+
map_location = list(state_dict.values())[0].device
9093
assert isinstance(storage, pl.LightningModule)
91-
map_location = list(checkpoint["state_dict"].values())[0].device
9294
return storage.to(map_location)
9395

9496
raise NotImplementedError(f"Unsupported {cls}")

0 commit comments

Comments
 (0)