safetensors

50 个版本 Python >=3.10
安装
pip install safetensors
poetry add safetensors
pipenv install safetensors
conda install safetensors
描述

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/
版本列表
0.8.0 2026-06-09
0.8.0.dev0 2026-04-14
0.8.0rc1 2026-06-01
0.8.0rc0 2026-04-14
0.7.0 2025-11-19
0.7.0.dev0 2025-11-17
0.7.0rc1 2025-11-17
0.7.0rc0 2025-10-30
0.6.2 2025-08-08
0.6.1 2025-08-06
0.6.0.dev0 2025-06-16
0.6.1rc0 2025-08-06
0.6.0rc0 2025-06-16
0.5.3 2025-02-26
0.5.2 2025-01-08
0.5.1 2025-01-07
0.5.0 2025-01-02
0.5.0rc0 2025-01-02
0.4.6.dev0 2024-11-07
0.4.5 2024-09-05
0.4.4 2024-08-05
0.4.3 2024-04-15
0.4.2 2024-01-23
0.4.1 2023-11-27
0.4.0 2023-10-06
0.4.4rc0 2024-08-05
0.4.3rc0 2024-04-15
0.4.2rc0 2024-01-22
0.4.1rc1 2023-11-17
0.4.0rc1 2023-10-05
0.3.3 2023-08-23
0.3.3.post1 2023-08-25
0.3.2 2023-08-22
0.3.1 2023-04-25
0.3.0 2023-03-03
0.3.3rc1 2023-08-23
0.3.2rc1 2023-08-07
0.3.1rc1 2023-04-24
0.3.0rc1 2023-03-02
0.2.8 2023-01-16
0.2.7 2022-12-27
0.2.6 2022-12-13
0.2.5 2022-11-23
0.2.4 2022-11-07
0.2.3 2022-10-27
0.2.2 2022-10-26
0.2.1 2022-09-30
0.2.1.dev0 2022-10-26
0.2.0 2022-09-29
0.0.1 2022-09-23