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 recommended file extension when saving data is
.mts, to prevent confusion with generic.npzfiles.
- 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, array_backend: str = 'torch') 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.- Parameters:
file (str | Path | BinaryIO) –
path of the file to load, or already opened file.
Warning
When using this function in TorchScript mode, only
strarguments are supported.array_backend (str) – array backend to use for the data. Only
"torch"is supported, this parameter exists for compatibility withmetatensor.
- Return type:
- metatensor.torch.load_block(file: str | Path | BinaryIO, array_backend: str = 'torch') TensorBlock[source]¶
Load previously saved
TensorBlockfrom the givenfile.- Parameters:
path –
path of the file to load, or already opened file.
Warning
When using this function in TorchScript mode, only
strarguments are supported.array_backend (str) – array backend to use for the data. Only
"torch"is supported, this parameter exists for compatibility withmetatensor.
- Return type:
- metatensor.torch.load_labels(file: str | Path | BinaryIO, array_backend: str = 'torch') Labels[source]¶
Load previously saved
Labelsfrom the givenfile.- Parameters:
file (str | Path | BinaryIO) –
path of the file to load, or already opened file.
Warning
When using this function in TorchScript mode, only
strarguments are supported.array_backend (str) – array backend to use for the data. Only
"torch"is supported, this parameter exists for compatibility withmetatensor.
- Return type:
- metatensor.torch.load_buffer(buffer: Tensor, *, array_backend: str = 'torch') TensorMap[source]¶
Load a previously saved
TensorMapfrom an in-memory buffer, stored inside a 1-dimensionaltorch.Tensorofuint8.
- metatensor.torch.load_block_buffer(buffer: Tensor, *, array_backend: str = 'torch') TensorBlock[source]¶
Load a previously saved
TensorBlockfrom an in-memory buffer, stored inside a 1-dimensionaltorch.Tensorofuint8.- Parameters:
- Return type: