Use safetensors with ONNX
Project description
onnx-safetensors
ONNX extension for saving to and loading from safetensors 🤗.
Install
pip install --upgrade onnx-safetensors
Usage
Load tensors to an ONNX model
import onnx_safetensors
# Provide your ONNX model here
model: onnx.ModelProto
tensor_file = "model.safetensors"
# Apply weights from the safetensors file to the model
onnx_safetensors.load_file(model, tensor_file)
Save weights to a safetensors file
import onnx_safetensors
# Provide your ONNX model here
model: onnx.ModelProto
tensor_file = "model.safetensors"
# Save weights from to the safetensors file
onnx_safetensors.save_file(model, tensor_file, convert_attributes=True)
# Save weights from to the safetensors file and clear the raw_data fields of the ONNX model to reduce its size
# model will be updated inplace
onnx_safetensors.save_file(model, tensor_file, convert_attributes=True, strip_data=True)
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
File details
Details for the file onnx-safetensors-0.1.1.tar.gz
.
File metadata
- Download URL: onnx-safetensors-0.1.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fea650ac07af6b126b485e555f70b23ed31d8e2b409e8c110e56e29dd0fffcd |
|
MD5 | 0eae628bae28a967b23283eb552f53de |
|
BLAKE2b-256 | e76815730fd72c7ecd52f1a7947af2eb77ecc860f05b0164b2ee944b81bf3235 |
File details
Details for the file onnx_safetensors-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: onnx_safetensors-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6456595859678fe0aef9d2c13d900f799cf229f455558cd95c13c82f05ac44f |
|
MD5 | 9c13be39ef9d94deb7da1ad64eb477ed |
|
BLAKE2b-256 | b8f4447ebf56eed958ff01799f53bb49c64f18d75863f2b52e06c91f9d332d89 |