https://github.com/onnx/ir-py
Efficient in-memory representation for ONNX, in Python
https://github.com/onnx/ir-py
computation-graph intermediate-representation large-language-models machine-learning onnx
Last synced: 7 days ago
JSON representation
Efficient in-memory representation for ONNX, in Python
- Host: GitHub
- URL: https://github.com/onnx/ir-py
- Owner: onnx
- License: apache-2.0
- Created: 2025-05-14T03:03:53.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-08-08T15:49:52.000Z (5 months ago)
- Last Synced: 2025-08-08T16:09:52.439Z (5 months ago)
- Topics: computation-graph, intermediate-representation, large-language-models, machine-learning, onnx
- Language: Python
- Homepage: http://onnx.ai/ir-py/
- Size: 810 KB
- Stars: 22
- Watchers: 6
- Forks: 9
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# 
[](https://pypi.org/project/onnx-ir)
[](https://github.com/astral-sh/ruff)
[](https://codecov.io/gh/onnx/ir-py)
[](https://pepy.tech/projects/onnx-ir)
An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.
## Getting Started
[onnx-ir documentation](https://onnx.ai/ir-py/)
### Installation
Via pip:
```
pip install onnx-ir
```
Or from source:
```
pip install git+https://github.com/onnx/ir-py.git
```
## Features ✨
- Full ONNX spec support: all valid models representable by ONNX protobuf, and a subset of invalid models (so you can load and fix them).
- Low memory footprint: mmap'ed external tensors; unified interface for ONNX TensorProto, Numpy arrays and PyTorch Tensors etc. No tensor size limitation. Zero copies.
- Straightforward access patterns: Access value information and traverse the graph topology at ease.
- Robust mutation: Create as many iterators as you like on the graph while mutating it.
- Speed: Performant graph manipulation, serialization/deserialization to Protobuf.
- Pythonic and familiar APIs: Classes define Pythonic apis and still map to ONNX protobuf concepts in an intuitive way.
- No protobuf dependency: The IR does not require protobuf once the model is converted to the IR representation, decoupling from the serialization format.
## Concept Diagram

## Code Organization 🗺️
- [`_protocols.py`](src/onnx_ir/_protocols.py): Interfaces defined for all entities in the IR.
- [`_core.py`](src/onnx_ir/_core.py): Implementation of the core entities in the IR, including `Model`, `Graph`, `Node`, `Value`, and others.
- [`_enums.py`](src/onnx_ir/_enums.py): Definition of the type enums that correspond to the `DataType` and `AttributeType` in `onnx.proto`.
- [`_name_authority.py`](src/onnx_ir/_name_authority.py): The authority for giving names to entities in the graph, used internally.
- [`_linked_list.py`](src/onnx_ir/_linked_list.py): The data structure as the node container in the graph that supports robust iteration and mutation. Internal.
- [`_metadata.py`](src/onnx_ir/_metadata.py): Metadata store for all entities in the IR.