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.npzfiles.- 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
strarguments 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.Tensorofuint8.- 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
TensorMapfrom the givenfile.TensorMapare serialized using the.mtsformat, i.e. a ZIP file without compression (storage method isSTORED), where each file is stored as a.npyarray. See the C API documentation for more information on the format.
- metatensor.torch.load_block(file: str | Path | BinaryIO) TensorBlock[source]¶
Load previously saved
TensorBlockfrom the givenfile.- Parameters:
- Return type:
- metatensor.torch.load_labels(file: str | Path | BinaryIO) Labels[source]¶
Load previously saved
Labelsfrom the givenfile.
- metatensor.torch.load_buffer(buffer: Tensor) TensorMap[source]¶
Load a previously saved
TensorMapfrom an in-memory buffer, stored inside a 1-dimensionaltorch.Tensorofuint8.
- metatensor.torch.load_block_buffer(buffer: Tensor) TensorBlock[source]¶
Load a previously saved
TensorBlockfrom an in-memory buffer, stored inside a 1-dimensionaltorch.Tensorofuint8.- Parameters:
buffer (Tensor) – CPU tensor of
uint8representing a in-memory buffer- Return type: