Numpy API
safetensors.numpy.load_file
< source >(
filename: typing.Union[str, os.PathLike]
)
β
Dict[str, np.ndarray]
Parameters
-
filename (
str
, oros.PathLike
)) — The name of the file which contains the tensors -
device (
Dict[str, any]
, optional, defaults tocpu
) — The device where the tensors need to be located after load. available options are all regular numpy device locations
Returns
Dict[str, np.ndarray]
dictionary that contains name as key, value as np.ndarray
Loads a safetensors file into numpy format.
safetensors.numpy.load
< source >(
data: bytes
)
β
Dict[str, np.ndarray]
Loads a safetensors file into numpy format from pure bytes.
safetensors.numpy.save_file
< source >(
tensor_dict: typing.Dict[str, numpy.ndarray]
filename: typing.Union[str, os.PathLike]
metadata: typing.Union[typing.Dict[str, str], NoneType] = None
)
β
None
Parameters
-
tensor_dict (
Dict[str, np.ndarray]
) — The incoming tensors. Tensors need to be contiguous and dense. -
filename (
str
, oros.PathLike
)) — The filename we’re saving into. -
metadata (
Dict[str, str]
, optional, defaults toNone
) — Optional text only metadata you might want to save in your header. For instance it can be useful to specify more about the underlying tensors. This is purely informative and does not affect tensor loading.
Returns
None
Saves a dictionnary of tensors into raw bytes in safetensors format.
safetensors.numpy.save
< source >(
tensor_dict: typing.Dict[str, numpy.ndarray]
metadata: typing.Union[typing.Dict[str, str], NoneType] = None
)
β
bytes
Parameters
-
tensor_dict (
Dict[str, np.ndarray]
) — The incoming tensors. Tensors need to be contiguous and dense. -
metadata (
Dict[str, str]
, optional, defaults toNone
) — Optional text only metadata you might want to save in your header. For instance it can be useful to specify more about the underlying tensors. This is purely informative and does not affect tensor loading.
Returns
bytes
The raw bytes representing the format
Saves a dictionnary of tensors into raw bytes in safetensors format.