Serialization¶
- metatensor.torch.save(file: str | Path | BinaryIO, data: TensorMap | TensorBlock | Labels)[source]¶
Save the given data (either
TensorMap
,TensorBlock
, orLabels
) to the givenfile
.If the file already exists, it is overwritten. The recomended file extension when saving data is
.mts
, to prevent confusion with generic.npz
files.- Parameters:
file (str | Path | BinaryIO) –
path of the file where to save the data, or already opened file.
Warning
When using this function in TorchScript mode, only
str
arguments are supported.data (TensorMap | TensorBlock | Labels) – data to serialize and save
- metatensor.torch.save_buffer(data: TensorMap | TensorBlock | Labels) Tensor [source]¶
Save the given data (either
TensorMap
,TensorBlock
, orLabels
) to an in-memory buffer, represented as 1-dimensionaltorch.Tensor
ofuint8
.- Parameters:
data (TensorMap | TensorBlock | Labels) – data to serialize and save
- Return type:
- metatensor.torch.load(file: str | Path | BinaryIO) TensorMap [source]¶
Load a previously saved
TensorMap
from the givenfile
.TensorMap
are serialized using the.mts
format, i.e. a ZIP file without compression (storage method isSTORED
), where each file is stored as a.npy
array. See the C API documentation for more information on the format.
- metatensor.torch.load_block(file: str | Path | BinaryIO) TensorBlock [source]¶
Load previously saved
TensorBlock
from the givenfile
.- Parameters:
- Return type:
- metatensor.torch.load_labels(file: str | Path | BinaryIO) Labels [source]¶
Load previously saved
Labels
from the givenfile
.
- metatensor.torch.load_buffer(buffer: Tensor) TensorMap [source]¶
Load a previously saved
TensorMap
from an in-memory buffer, stored inside a 1-dimensionaltorch.Tensor
ofuint8
.
- metatensor.torch.load_block_buffer(buffer: Tensor) TensorBlock [source]¶
Load a previously saved
TensorBlock
from an in-memory buffer, stored inside a 1-dimensionaltorch.Tensor
ofuint8
.- Parameters:
buffer (Tensor) – CPU tensor of
uint8
representing a in-memory buffer- Return type: