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.

Implementation:Onnx Onnx Compose IO Map

From Leeroopedia


Knowledge Sources
Domains Model_Composition, Data_Flow
Last Updated 2026-02-10 00:00 GMT

Overview

Interface specification for the I/O mapping data structure used in ONNX model composition.

Description

The io_map is a user-defined Python data structure, not a library function. It is a list of tuples where each tuple contains two strings: an output name from the first model and an input name from the second model. This data structure is passed to merge_models (and internally to merge_graphs) to specify how the two models are wired together.

This is a Pattern Doc: users construct this data structure themselves rather than calling a library function.

Interface Specification

io_map: list[tuple[str, str]]
# Each tuple: (output_name_from_model1, input_name_of_model2)
# Example: [("m1_output", "m2_input")]

Code Reference

Source Location

  • Repository: onnx
  • File: onnx/compose.py
  • Lines: 297-311 (parameter definition in merge_models)

Constraints

  • Output names must exist in model 1's graph outputs
  • Input names must exist in model 2's graph inputs
  • If prefixes are applied (via add_prefix or merge_models prefix parameters), the io_map must use the prefixed names
  • Each output/input can appear at most once in the mapping

I/O Contract

Inputs

Name Type Required Description
io_map list[tuple[str, str]] Yes Pairs of (output_from_m1, input_of_m2)

Outputs

Name Type Description
io_map list[tuple[str, str]] Data structure passed to merge_models

Usage Examples

Basic IO Map

# Model 1 outputs: ["features"]
# Model 2 inputs: ["input_features", "labels"]
# Connect model 1's "features" to model 2's "input_features"

io_map = [("features", "input_features")]

Multiple Connections

# Model 1 outputs: ["embedding", "attention_mask"]
# Model 2 inputs: ["hidden_state", "mask", "config"]

io_map = [
    ("embedding", "hidden_state"),
    ("attention_mask", "mask"),
]
# "config" remains as an external input of the merged model

With Prefixed Names

# After applying prefixes "encoder/" and "decoder/"
io_map = [
    ("encoder/output", "decoder/input"),
]

Related Pages

Implements Principle

Requires Environment

Page Connections

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