Registry / ai-ml / onnx-ir

onnx-ir

JSON →
library1.0.0pypypi✓ verified 30d ago

onnx-ir provides an efficient in-memory representation for ONNX graphs, allowing for programmatic creation, manipulation, and optimization of ONNX models in Python. It is currently at version 0.2.0 and has a frequent release cadence, often seeing multiple patch releases per month, indicating active development.

pip install onnx-ir
INSTALL
IMPORT
SIG · ONNX-IR
O
onnx-ir
ai-mlpythonv1.0.0
Install
11.7s avg
Import
—
Disk
255MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
build_error
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 11.7s · import 0.000s · 236MB
255MB installed
● package 255MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Graph
✓ from onnx_ir import Graph
✗ from onnx_ir import Graph

This quickstart demonstrates how to create a simple ONNX graph representing an 'Add' operation using `onnx-ir`'s core components: `Value`, `Type`, `Shape`, `Node`, and `Graph`.

import onnx_ir as ir import numpy as np # Create input values with specific types and shapes input_a = ir.Value("input_a", ir.Type(ir.Shape([2, 2]), ir.TensorElementDataType.FLOAT)) input_b = ir.Value("input_b", ir.Type(ir.Shape([2, 2]), ir.TensorElementDataType.FLOAT)) # Define the output value for the Add node output_c = ir.Value("output_c") # Create an 'Add' node with inputs and outputs add_node = ir.Node("Add", inputs=[input_a, input_b], outputs=[output_c]) # Assemble a graph from inputs, outputs, and nodes graph = ir.Graph( [input_a, input_b], # Graph inputs [output_c], # Graph outputs [add_node], # Nodes in the graph "simple_add_graph" # Name of the graph ) print(f"Created graph: {graph.name}") print(f"Graph has {len(graph.nodes)} node(s).") print(f"Input 'input_a' shape: {input_a.type.shape.dims}")
Debug
Known issues
breakingIn `v0.1.9`, the `ir.Input` class was deprecated in favor of `ir.val`. Additionally, attribute signatures for nodes were simplified, requiring tuples for repeating attributes. Code using the old `ir.Input` or the previous attribute signature format will break.
fix
Replace `ir.Input` with `ir.val`. Update node attribute definitions to use tuples for repeating attributes as specified in the updated API documentation.
affects: >=0.1.9
gotchaWhen using the `Value.replace_all_uses_with` method (introduced in `v0.1.12`) with the `replace_graph_outputs` option, users are responsible for manually assigning the original output name to the replacement value if they wish to preserve the graph's signature. Failing to do so can lead to a modified graph signature.
fix
After calling `Value.replace_all_uses_with` with `replace_graph_outputs=True`, ensure the replacement `Value` has its `.name` attribute set to the original output's name if graph signature preservation is desired.
affects: >=0.1.12
gotchaThe `v0.2.0` release introduced `sympy` as a new dependency for symbolic shape inferencing. This will increase the total install size and might slightly extend the installation time for new environments.
fix
Ensure your environment is prepared for the additional `sympy` dependency. No code changes are required unless you were explicitly trying to avoid `sympy`.
affects: >=0.2.0
Upgrade
Version history
1.0.0latest on PyPI · released Aug 11, 2026
Audit
Dependencies
onnxrequiredCore dependency for ONNX model manipulation.
numpyrequiredUsed for tensor data handling.
sympyrequiredAdded in v0.2.0 for symbolic shape inferencing infrastructure.
Agent activity
34 hits · last 30 days
node
32
Resources
onnx-ir — pip install onnx-ir · libregistry