save_file¶
- onnx_safetensors.save_file(model, /, location, base_dir='', *, size_threshold=0, replace_data=True, max_shard_size=None)[source]¶
Save all tensors in an ONNX model to a safetensors file.
Added in version 1.0.0: The replace_data parameter was added to allow the user to choose whether to replace the data in the ONNX model with the external data.
Removed in version 1.0.0: The convert_attributes and strip_data parameters were removed. Set replace_data to achieve similar effect as strip_data.
Changed in version 1.0.0: The return value is now the updated ONNX model instead of a set of saved tensor names.
Added in version 1.0.1: The base_dir parameter was added so the external data can be referenced relative to the ONNX model file correctly.
Added in version 1.3.0: The max_shard_size parameter was added to support sharding large models.
- Parameters:
model (TModel) – ONNX model proto to save.
location (str | PathLike) – Path to the safetensors file relative to the ONNX model file.
base_dir (str | PathLike) – Directory where the ONNX model file is stored.
size_threshold (int) – Minimum size in bytes for a tensor to be saved. Default is 0, which saves all tensors.
replace_data (bool) – Whether to replace the data in the ONNX model with the external data. Default is True.
max_shard_size (int | str | None) – Maximum size in bytes (as int) or as a string with unit (like “5GB” or “100MB”) for a checkpoint before being sharded. If None, no sharding is performed.
- Returns:
The ONNX model with the external data.
- Return type:
TModel