Skip to content
Draft
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
7 changes: 7 additions & 0 deletions torchvision/models/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def verify(cls, obj: Any) -> Any:
return obj

def get_state_dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
# Load checkpoints with ``weights_only=True`` by default so a tampered
# checkpoint cannot execute arbitrary code via pickle during unpickling.
# ``torch.hub.load_state_dict_from_url`` forwards ``weights_only`` to
# ``torch.load`` explicitly, so it does not benefit from the
# ``weights_only=True`` default that ``torch.load`` itself adopted in
# PyTorch 2.6 -- it must be requested here. Callers may still override.
kwargs.setdefault("weights_only", True)
return load_state_dict_from_url(self.url, *args, **kwargs)

def __repr__(self) -> str:
Expand Down