Skip to content

Fixed warning and added safe globals #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 15 additions & 1 deletion torch_frame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
embedding,
)
from .data import TensorFrame
from .typing import TaskType, Metric, DataFrame, NAStrategy
from .typing import (
TaskType,
Metric,
DataFrame,
NAStrategy,
WITH_PT24,
)
from torch_frame.utils import save, load, cat # noqa
import torch_frame.data # noqa
import torch_frame.datasets # noqa
import torch_frame.nn # noqa
import torch_frame.gbdt # noqa

if WITH_PT24:
import torch

torch.serialization.add_safe_globals([
stype,
torch_frame.data.stats.StatType,
])

__version__ = '0.2.3'

__all__ = [
Expand Down
4 changes: 4 additions & 0 deletions torch_frame/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
from typing import Dict, List, Mapping, Union

import pandas as pd
import torch
from torch import Tensor

from torch_frame.data.multi_embedding_tensor import MultiEmbeddingTensor
from torch_frame.data.multi_nested_tensor import MultiNestedTensor

WITH_PT20 = int(torch.__version__.split('.')[0]) >= 2
WITH_PT24 = WITH_PT20 and int(torch.__version__.split('.')[1]) >= 4


class Metric(Enum):
r"""The metric.
Expand Down
5 changes: 3 additions & 2 deletions torch_frame/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def save(tensor_frame: TensorFrame,


def load(
path: str, device: torch.device | None = None
path: str,
device: torch.device | None = None,
) -> tuple[TensorFrame, dict[str, dict[StatType, Any]] | None]:
r"""Load saved :class:`TensorFrame` object and optional :obj:`col_stats`
from a specified path.
Expand All @@ -95,7 +96,7 @@ def load(
tuple: A tuple of loaded :class:`TensorFrame` object and
optional :obj:`col_stats`.
"""
tf_dict, col_stats = torch.load(path)
tf_dict, col_stats = torch.load(path, weights_only=True)
tf_dict['feat_dict'] = deserialize_feat_dict(
tf_dict.pop('feat_serialized_dict'))
tensor_frame = TensorFrame(**tf_dict)
Expand Down
Loading