Skip to content

Commit 170fbe0

Browse files
committed
defaults for weights_only in torch.hub.load_state_dict_from_url
1 parent 52b3215 commit 170fbe0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/lightning/fabric/utilities/cloud_io.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from fsspec.implementations.local import AbstractFileSystem
2727
from lightning_utilities.core.imports import module_available
2828

29+
from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_6
2930
from lightning.fabric.utilities.types import _MAP_LOCATION_TYPE, _PATH
3031

3132
log = logging.getLogger(__name__)
@@ -56,9 +57,14 @@ def _load(
5657
weights_only=weights_only,
5758
)
5859
if str(path_or_url).startswith("http"):
59-
if weights_only is None and _TORCH_GREATER_EQUAL_2_6:
60-
weights_only = True
61-
log.debug(f"Default to `weights_only=True` for remote checkpoint: {path_or_url}")
60+
if weights_only is None:
61+
if _TORCH_GREATER_EQUAL_2_6:
62+
weights_only = True
63+
log.debug(f"Default to `weights_only=True` for remote checkpoint for torch>=2.6: {path_or_url}")
64+
else:
65+
weights_only = False
66+
log.debug(f"Default to `weights_only=False` for remote checkpoint for torch<2.6: {path_or_url}")
67+
6268
return torch.hub.load_state_dict_from_url(
6369
str(path_or_url),
6470
map_location=map_location, # type: ignore[arg-type]

0 commit comments

Comments
 (0)