Principle:Onnx Onnx External Data Saving
| Knowledge Sources | |
|---|---|
| Domains | External_Data, Model_Persistence |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A serialization mechanism that writes ONNX model tensor data to external files on disk and saves the model protobuf with references to those external files.
Description
External data saving is the final step in the external data workflow: it physically writes tensor data to external files and saves the model protobuf (now containing external data references instead of inline data) to disk. The process involves two operations: write_external_data_tensors serializes the raw data of each externally-marked tensor to the specified files and clears the in-memory raw data, then the model protobuf (now lightweight) is serialized and saved.
For convenience, save_model with save_as_external_data=True performs the complete pipeline: conversion, writing, and saving in a single call.
Usage
Use this principle as the final step when saving a large model with external data. Either call save_model with save_as_external_data=True for the automated pipeline, or manually call convert_model_to_external_data followed by save_model (which internally calls write_external_data_tensors) for more control.
Theoretical Basis
External data saving performs two sequential operations:
- Write tensor data to external files:
Failed to parse (syntax error): {\displaystyle \forall t \in \text{tensors}(M): \text{if } t.\text{data\_location} = \text{EXTERNAL} \text{ then write}(t.\text{raw\_data}, t.\text{location}) }
- Save the model protobuf (now without inline data):