Principle:Onnx Onnx External Data Conversion
| Knowledge Sources | |
|---|---|
| Domains | External_Data, Large_Model_Support |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A data transformation mechanism that marks in-memory tensor data for external storage by setting external data references on tensors that exceed a size threshold.
Description
When an ONNX model's tensor data is too large to fit within the 2GB protobuf size limit, the tensors must be externalized: their data is saved to separate files rather than embedded in the protobuf. External data conversion is the preparation step that marks tensors for externalization by setting their data_location to EXTERNAL and populating external_data entries with the target file location. The actual data writing to disk happens in a subsequent step (write_external_data_tensors).
The conversion supports two modes: all tensors to a single external file, or each tensor to its own file. A size threshold controls which tensors are externalized (only tensors at or above the threshold are converted).
Usage
Use this principle when preparing a large model for saving with external data. This is the intermediate step between loading/constructing a model and saving it with external data references. For convenience, save_model with save_as_external_data=True calls this function automatically.
Theoretical Basis
External data conversion marks tensors for externalization:
Failed to parse (syntax error): {\displaystyle \forall t \in \text{tensors}(M): \text{if } |t.\text{raw\_data}| \geq \text{threshold} \text{ then } t.\text{data\_location} \leftarrow \text{EXTERNAL} }