﻿# ONNX local functions: copy domain bindings and operator imports with the body

Move ONNX local functions between models without losing their domain identity, imported operator semantics or attribute bindings during graph composition and inlining.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-onnx-local-function-domain-opset-binding/
Language: en

## A copied function runs under the wrong interpretation

A graph composition tool extracts a useful local function and appends its body to another model. The node names look correct, but the destination resolves an operation against a different imported definition. This is a semantic integration error even when every tensor has an acceptable shape. Before comparing GPU performance, establish which function is called and which operator meanings its body expects. A textually identical operation name does not settle either question.

## Function metadata establishes a separate contract

The [ONNX IR specification](https://onnx.ai/onnx/repo-docs/IR.html) describes function definitions, their identity fields and operator imports. A function’s implementation has its own declared imports rather than an implicit promise to inherit any convenient destination interpretation. Preserve its domain, name and applicable identity metadata together with its arguments and attributes. Do not rename only the call site while leaving references to nested functions inconsistent with the new model’s definitions.

## Build the function through an explicit interface

The [helper API](https://onnx.ai/onnx/api/helper.html) exposes `make_function` with inputs, outputs, nodes and imports. Reviewing those arguments is more reliable than treating a function as a bag of nodes. Include the referenced attributes and any nested dependencies in the composition review. The [schema version mapping guide](/journal/data-guide-label-taxonomy-version-mapping/) supplies a useful analogy: identical labels in separate namespaces need an explicit mapping before their meanings can be safely combined.

## Inlining also needs semantic preservation

The [ONNX inliner API](https://onnx.ai/onnx/api/inliner.html) provides function-inlining operations. Inlining removes a call boundary, but does not make operator-version differences disappear by definition. Review the selected API’s conversion behavior and the resulting import map. Compare the composed model against the original function on inputs that exercise its attributes, not merely an all-default path. A successful composition should preserve observable computation as well as produce a graph accepted by tooling.

## Record what was imported and what was rewritten

Keep an inventory of function definitions, domain bindings, attribute decisions and any version conversion used during composition. Protect the final graph through [artifact verification](/journal/artifact-signature-verification/). If a mismatch appears, this evidence distinguishes a namespace collision from a shape error or backend limitation. The goal is a reproducible semantic binding, rather than an assumption that copying familiar-looking node text between models automatically copies the full meaning of the source function.
