load_torch_file
¶
Loads a file saved with torch.save (or a plain pickle file) without
PyTorch, with every tensor converted to a numpy.ndarray.
Both the zip-based format (default since PyTorch 1.6) and the legacy
format are supported. Only tensors (on any device, read on the CPU),
containers (lists, tuples, dicts), NumPy arrays and SciPy COO matrices
(read as SparseCOOMatrix) can be loaded: any other object raises
a pickle.UnpicklingError, which makes the loader safe to use on
untrusted files. bfloat16 and complex tensors are not supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, PathLike]
|
Path of the file. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The saved object, with tensors as NumPy arrays. |
Example:
from mlx_graphs.datasets.utils import load_torch_file
graphs = load_torch_file("peptidesfunc/train.pt")
node_features, edge_features, edge_index, y = graphs[0]
Source code in mlx_graphs/datasets/utils/torch_serialization.py
from mlx_graphs.datasets.utils.torch_serialization import load_torch_file · mlx_graphs/datasets/utils/torch_serialization.py