safetensors0.4.5
safetensors0.4.5
Published
pip install safetensors
Package Downloads
Authors
Requires Python
>=3.7
Dependencies
- numpy
>=1.21.6; extra == "numpy"
- 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.11.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"
- black
==22.3; extra == "quality"
- click
==8.0.4; extra == "quality"
- isort
>=5.5.4; extra == "quality"
- flake8
>=3.8.3; 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
[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/