跳转到主要内容

使用safetensors与ONNX

项目描述

onnx-safetensors

CI PyPI - Version PyPI - Python Version Ruff Ruff

ONNX扩展,用于保存到和从safetensors加载 🤗。

安装

pip install --upgrade onnx-safetensors

用法

将张量加载到ONNX模型中

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)

将权重保存到safetensors文件

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)

项目细节


下载文件

下载适用于您平台文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

onnx-safetensors-0.1.1.tar.gz (7.7 kB 查看散列)

上传时间: 源代码

构建分发

onnx_safetensors-0.1.1-py3-none-any.whl (8.1 kB 查看哈希值)

上传时间 Python 3

由以下支持