Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Onnx Onnx External Data Loading

From Leeroopedia


Knowledge Sources
Domains External_Data, Large_Model_Support
Last Updated 2026-02-10 00:00 GMT

Overview

A deferred loading mechanism that reads externally stored tensor data into an ONNX model's in-memory representation from separate files on disk.

Description

For ONNX models whose tensor data exceeds the 2GB protobuf size limit, tensor data is stored in separate external files rather than embedded in the model protobuf. External data loading resolves these external references by reading the tensor data from the specified files and populating the model's tensor raw_data fields. This two-phase loading approach allows the model structure to be loaded quickly while deferring the potentially expensive data loading.

The external data reference in each tensor specifies a file location (relative to the model), an optional byte offset, and an optional data length. After loading, the tensor's data_location is reset to DEFAULT and the external data references are cleared.

Usage

Use this principle when working with large ONNX models that use external data storage, particularly when the external data files are in a different directory from the model file. Load the model with load_external_data=False, then call load_external_data_for_model with the correct base directory.

Theoretical Basis

External data loading resolves file references:

Failed to parse (syntax error): {\displaystyle \forall t \in \text{tensors}(M): \text{if } t.\text{data\_location} = \text{EXTERNAL} \text{ then } t.\text{raw\_data} = \text{read}(t.\text{location}, t.\text{offset}, t.\text{length}) }

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment