Principle:Onnx Onnx Model Merging
| Knowledge Sources | |
|---|---|
| Domains | Model_Composition, Graph_Transformation |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A composition mechanism that combines two ONNX models into a single model by connecting specified outputs of the first model to inputs of the second model.
Description
Model merging is the core operation of ONNX model composition. Given two models and an I/O map specifying how to connect them, the merge operation creates a single unified model containing all nodes, initializers, and metadata from both source models. The merged graph's inputs are the union of both models' inputs (minus those consumed by the I/O map), and the outputs are the union of both models' outputs (minus those feeding into the I/O map).
The operation also handles opset compatibility (requiring both models to use the same opset versions), optional namespace prefixing (to avoid name collisions), metadata property merging, and local function merging. The resulting model is automatically validated via checker.check_model.
Usage
Use this principle when you need to create a pipeline of two ONNX models (e.g., a feature extractor followed by a classifier), combine a preprocessing model with a main model, or construct complex model architectures from independently trained components.
Theoretical Basis
Model merging creates a composed graph:
Failed to parse (syntax error): {\displaystyle G_{\text{merged}} = G_1 \cup G_2 \text{ with } \text{io\_map} \text{ connecting edges} }
The composition process:
- Validate opset compatibility between models
- Apply optional namespace prefixes
- Merge graph nodes, initializers, and value infos
- Connect edges according to io_map
- Compute final input/output sets
- Validate the merged model