Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/pytorch_tabular/tabular_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,14 @@ def _load_dataset_from_cache(self, tag: str = "train"):
)
elif self.cache_mode is self.CACHE_MODES.DISK:
try:
dataset = torch.load(self.cache_dir / f"{tag}_dataset", weights_only=False)
# get the torch version
torch_version = torch.__version__
if torch_version < "2.6":
dataset = torch.load(
self.cache_dir / f"{tag}_dataset"
) # fix for torch version change of torch.load
elif torch_version >= "2.6":
dataset = torch.load(self.cache_dir / f"{tag}_dataset", weights_only=False)
except FileNotFoundError:
raise FileNotFoundError(
f"{tag}_dataset not found in {self.cache_dir}. Please provide the" f" data for {tag} dataloader"
Expand Down
13 changes: 11 additions & 2 deletions src/pytorch_tabular/utils/python_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,24 @@ def pl_load(
"""
if not isinstance(path_or_url, (str, Path)):
# any sort of BytesIO or similar
return torch.load(path_or_url, map_location=map_location, weights_only=False)
# get the torch version
torch_version = torch.__version__
if torch_version < "2.6":
return torch.load(path_or_url, map_location=map_location) # for torch version < 2.6
elif torch_version >= "2.6":
return torch.load(path_or_url, map_location=map_location, weights_only=False)
if str(path_or_url).startswith("http"):
return torch.hub.load_state_dict_from_url(
str(path_or_url),
map_location=map_location, # type: ignore[arg-type] # upstream annotation is not correct
)
fs = get_filesystem(path_or_url)
with fs.open(path_or_url, "rb") as f:
return torch.load(f, map_location=map_location, weights_only=False)
torch_version = torch.__version__
if torch_version < "2.6":
return torch.load(f, map_location=map_location) # for torch version < 2.6
elif torch_version >= "2.6":
return torch.load(f, map_location=map_location, weights_only=False)


def check_numpy(x):
Expand Down
Loading