torchoutil.extras.safetensors module

dump_safetensors(
tensors: Dict[str, Tensor],
fpath: str | Path | None = None,
metadata: Dict[str, str] | None = None,
*,
overwrite: bool = True,
make_parents: bool = True,
convert_to_tensor: Literal[False] = False,
) bytes[source]
dump_safetensors(
tensors: Dict[str, Any],
fpath: str | Path | None = None,
metadata: Dict[str, str] | None = None,
*,
overwrite: bool = True,
make_parents: bool = True,
convert_to_tensor: Literal[True],
) bytes

Dump tensors to safetensors format. Requires safetensors package installed.

load_safetensors(
fpath: str | Path,
*,
device: str = 'cpu',
return_metadata: Literal[False] = False,
) Dict[str, Tensor][source]
load_safetensors(
fpath: str | Path,
*,
device: str = 'cpu',
return_metadata: Literal[True],
) Tuple[Dict[str, Tensor], Dict[str, str]]
to_safetensors(
tensors: Dict[str, Any],
fpath: str | Path | None = None,
metadata: Dict[str, str] | None = None,
*,
overwrite: bool = True,
make_parents: bool = True,
convert_to_tensor: bool = False,
) bytes[source]

Dump tensors to safetensors format. Requires safetensors package installed.