Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions models/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@ def load_checkpoint_state_dict(
torch.serialization.add_safe_globals(
[argparse.Namespace, pathlib.PosixPath, pathlib.WindowsPath]
)

checkpoint = torch.load(
checkpoint_path,
map_location="cpu",
weights_only=True,
)
checkpoint = torch.load(
checkpoint_path,
map_location="cpu",
weights_only=True,
)
else:
# torch < 2.4 has no add_safe_globals, so the weights_only unpickler
# cannot be extended to allow the argparse.Namespace that Lightning
# stores under hyper_parameters. A pretraining checkpoint therefore
# fails to load with weights_only=True. Fall back to a full load; the
# checkpoint is a local, trusted file produced by pretrain.py.
checkpoint = torch.load(
checkpoint_path,
map_location="cpu",
weights_only=False,
)
if not isinstance(checkpoint, Mapping):
raise TypeError("Checkpoint must contain a mapping")

Expand Down