save

onnx_ir.save(model: Model, path: str | PathLike, format: str | None = None, external_data: str | PathLike | None = None, size_threshold_bytes: int = 256) None

Save an ONNX model to a file.

The model remains unchanged after the call. If any existing external tensor references the provided external_data path, it will be invalidated after the external data is overwritten. To obtain a valid model, use load() to load the newly saved model, or provide a different external data path that is not currently referenced by any tensors in the model.

Parameters:
  • model – The model to save.

  • path – The path to save the model to. E.g. “model.onnx”.

  • format – The format of the file (e.g. protobuf, textproto, json, etc.). If None, the format is inferred from the file extension.

  • external_data – The relative path to save external data to. When specified, all initializers in the model will be converted to external data and saved to the specified directory. If None, all tensors will be saved unmodified. That is, if a tensor in the model is already external, it will be saved with the same external information; if the tensor is not external, it will be serialized in the ONNX Proto message.

  • size_threshold_bytes – Save to external data if the tensor size in bytes is larger than this threshold. Effective only when external_data is set.

Raises:

ValueError – If the external data path is an absolute path.