Safetensors-based serialization of general data structures
Project description
safestructures
What is safestructures?
safestructures is a Python package based on safetensors to serialize general data structures. It uses safetensors to store tensors and uses its metadata to store the schema of the original data structure as well as other basic data types.
safetensors can be more preferred than pickle when saving tensors, especially for safety reasons. See huggingface/safetensors for more details.
safetensors only stores tensors. safestructures extends safetensors by storing information of the original data structure containing tensors as well as other data types. It utilizes a plugin architecture so that projects that contain custom types can serialize and deserialize their custom data.
Why safestructures?
ML models in practice deal with more than just tensors. Tensors can be passed between layers or outputted using data containers. Other data types are used as well to modify layer behavior.
To have better reproducibility and tracking, we may need to store and load model inputs and outputs, as well as intermediate layer inputs and output in a safe manner. safetensors greatly helps on the tensor side, while safestructures helps with the rest.
Installation and requirements
safestructures requires Python 3.10 and above.
To install, simply run
pip install safestructures
This will also install the minimum dependencies, namely safetensors and numpy.
As for ML / tensor frameworks, safestructures expects numpy at minimum. To use safestructures's PyTorch, TensorFlow, and JAX capabilities, the respective framework must be installed separately.
Usage and plugins
See the usage and plugins guide readmes, or refer to the docs
Support
Currently, safestructures supports out of the box:
- All of Python's built-in data containers and data types.
dataclasses.dataclassobjects.- PyTorch tensors via
safetensors. - TensorFlow 2 tensors via
safetensors. - JAX tensors via
safetensors.
For maximum compatibility with NumPy, all float tensors are stored in FP32.
safestructures aims to cover the same frameworks as safetensors, but for initial release it does not support:
collections- Please comment on this issue to request support.- PaddlePaddle - Please comment on this issue to request support.
- MLX - Please comment on this issue to request support.
However, safestructures supports plugins in case there is a type it does not support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safestructures-1.0.0.tar.gz.
File metadata
- Download URL: safestructures-1.0.0.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da6d5e5f6004800d7a475ca005dc78c63fa8d7fc602ec22c1a62cf664910ddf0
|
|
| MD5 |
9247e3cacbf8e5d2506b9a0565a3db17
|
|
| BLAKE2b-256 |
31c93f6820a82ca807009a620d021837237d509a4dacd604c5252573454a8634
|
File details
Details for the file safestructures-1.0.0-py3-none-any.whl.
File metadata
- Download URL: safestructures-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfbe357602a997f97cf79d7e9138c2625efad08e7c2a3218192c0d989fbc4d83
|
|
| MD5 |
83b18e5a2f39bda443d6b9fa41048df6
|
|
| BLAKE2b-256 |
2eb3f6bc453d10dc015c6c0ec623526a15ffdecb395ce104d63d571fc19e95d0
|