safetensors0.7.0
safetensors0.7.0
Published
pip install safetensors
Package Downloads
Authors
Requires Python
>=3.9
Dependencies
- numpy
>=1.21.6; extra == "numpy" - packaging
; extra == "torch" - safetensors
[numpy]; extra == "torch" - torch
>=1.10; extra == "torch" - safetensors
[numpy]; extra == "tensorflow" - tensorflow
>=2.11.0; extra == "tensorflow" - safetensors
[numpy]; extra == "pinned-tf" - tensorflow
==2.18.0; extra == "pinned-tf" - safetensors
[numpy]; extra == "jax" - flax
>=0.6.3; extra == "jax" - jax
>=0.3.25; extra == "jax" - jaxlib
>=0.3.25; extra == "jax" - mlx
>=0.0.9; extra == "mlx" - safetensors
[numpy]; extra == "paddlepaddle" - paddlepaddle
>=2.4.1; extra == "paddlepaddle" - ruff
; extra == "quality" - safetensors
[numpy]; extra == "testing" - h5py
>=3.7.0; extra == "testing" - huggingface-hub
>=0.12.1; extra == "testing" - setuptools-rust
>=1.5.2; extra == "testing" - pytest
>=7.2.0; extra == "testing" - pytest-benchmark
>=4.0.0; extra == "testing" - hypothesis
>=6.70.2; extra == "testing" - safetensors
[numpy]; extra == "testingfree" - huggingface-hub
>=0.12.1; extra == "testingfree" - setuptools-rust
>=1.5.2; extra == "testingfree" - pytest
>=7.2.0; extra == "testingfree" - pytest-benchmark
>=4.0.0; extra == "testingfree" - hypothesis
>=6.70.2; extra == "testingfree" - safetensors
[torch]; extra == "all" - safetensors
[numpy]; extra == "all" - safetensors
[pinned-tf]; extra == "all" - safetensors
[jax]; extra == "all" - safetensors
[paddlepaddle]; extra == "all" - safetensors
[quality]; extra == "all" - safetensors
[testing]; extra == "all" - safetensors
[all]; extra == "dev"
Installation
pip install safetensors
Usage
Numpy
from safetensors.numpy import save_file, load_file
import numpy as np
tensors = {
"a": np.zeros((2, 2)),
"b": np.zeros((2, 3), dtype=np.uint8)
}
save_file(tensors, "./model.safetensors")
# Now loading
loaded = load_file("./model.safetensors")
Torch
from safetensors.torch import save_file, load_file
import torch
tensors = {
"a": torch.zeros((2, 2)),
"b": torch.zeros((2, 3), dtype=torch.uint8)
}
save_file(tensors, "./model.safetensors")
# Now loading
loaded = load_file("./model.safetensors")
Developing
# inside ./safetensors/bindings/python
pip install .[dev]
Should be enough to install this library locally.
Testing
# inside ./safetensors/bindings/python
pip install .[dev]
pytest -sv tests/