Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0

name: Lint

on:
Expand Down Expand Up @@ -57,7 +53,7 @@ jobs:
# Install dependencies
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install --upgrade lintrunner lintrunner-adapters
python -m pip install -r requirements-dev.txt
# Install packages
python -m pip install -e .
lintrunner init
Expand All @@ -67,7 +63,7 @@ jobs:
if ! lintrunner --force-color --all-files --tee-json=lint.json -v; then
echo ""
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner\`.\e[0m"
echo -e "\e[1m\e[36mSee https://github.com/microsoft/onnxscript#coding-style for setup instructions.\e[0m"
echo -e "\e[1m\e[36mSee https://github.com/onnx/onnx_ir/blob/main/CONTRIBUTING.md for setup instructions.\e[0m"
exit 1
fi
- name: Produce SARIF
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0

# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.
Expand Down
27 changes: 27 additions & 0 deletions LICENSES/BSD-3-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) [year], [fullname]
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of [project] nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 changes: 21 additions & 0 deletions LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global-exclude *_test.py
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ONNX IR

[![PyPI - Version](https://img.shields.io/pypi/v/onnx-ir.svg)](https://pypi.org/project/onnx-ir)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation.

## Features ✨
Expand All @@ -14,9 +17,9 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio

## Code Organization 🗺️

- [`_protocols.py`](_protocols.py): Interfaces defined for all entities in the IR.
- [`_core.py`](_core.py): Implementation of the core entities in the IR, including `Model`, `Graph`, `Node`, `Value`, and others.
- [`_enums.py`](_enums.py): Definition of the type enums that correspond to the `DataType` and `AttributeType` in `onnx.proto`.
- [`_name_authority.py`](_name_authority.py): The authority for giving names to entities in the graph, used internally.
- [`_linked_list.py`](_linked_list.py): The data structure as the node container in the graph that supports robust iteration and mutation. Internal.
- [`_metadata.py`](_metadata.py): Metadata store for all entities in the IR.
- [`_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.
77 changes: 76 additions & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0

version = 1
Expand All @@ -18,8 +17,84 @@ path = [
"**/*.toml",
"**/*.yml",
"CODEOWNERS",
"MANIFEST.in",
"requirements*.txt",
"requirements/**/*.txt",
]
precedence = "aggregate"
SPDX-FileCopyrightText = "Copyright (c) ONNX Project Contributors"
SPDX-License-Identifier = "Apache-2.0"

[[annotations]]
path = "src/onnx_ir/_thirdparty/asciichartpy.py"
precedence = "aggregate"
SPDX-FileCopyrightText = [
"2016 Igor Kroitor",
]
SPDX-License-Identifier = "MIT"

[[annotations]]
path = "tests/public_api_test.py"
precedence = "aggregate"
SPDX-FileCopyrightText = [
"""
From PyTorch:

Copyright (c) 2016- Facebook, Inc (Adam Paszke)
Copyright (c) 2014- Facebook, Inc (Soumith Chintala)
Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
Copyright (c) 2011-2013 NYU (Clement Farabet)
Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)

From Caffe2:

Copyright (c) 2016-present, Facebook Inc. All rights reserved.

All contributions by Facebook:
Copyright (c) 2016 Facebook Inc.

All contributions by Google:
Copyright (c) 2015 Google Inc.
All rights reserved.

All contributions by Yangqing Jia:
Copyright (c) 2015 Yangqing Jia
All rights reserved.

All contributions by Kakao Brain:
Copyright 2019-2020 Kakao Brain

All contributions by Cruise LLC:
Copyright (c) 2022 Cruise LLC.
All rights reserved.

All contributions by Tri Dao:
Copyright (c) 2024 Tri Dao.
All rights reserved.

All contributions by Arm:
Copyright (c) 2021, 2023-2024 Arm Limited and/or its affiliates

All contributions from Caffe:
Copyright(c) 2013, 2014, 2015, the respective contributors
All rights reserved.

All other contributions:
Copyright(c) 2015, 2016 the respective contributors
All rights reserved.

Caffe2 uses a copyright model similar to Caffe: each contributor holds
copyright over their contributions to Caffe2. The project versioning records
all such contribution and copyright details. If a contributor wants to further
mark their specific copyright on a particular contribution, they should
indicate their copyright solely in the commit message of the change when it is
committed.

All rights reserved.
"""
]
SPDX-License-Identifier = "BSD-3-Clause"
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"myst_nb",
"sphinx_copybutton",
"sphinx_exec_code",
"sphinx_gallery.gen_gallery",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio
Overview <self>
getting_started
tensors
ir_api/index
api/index
```
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "onnx-ir"
version = "0.0.1"
dynamic = ["version"]
authors = [
{name = "ONNX Contributors", email = "[email protected]"},
]
Expand All @@ -20,8 +20,12 @@ dependencies = ["numpy", "onnx>=1.16", "typing_extensions>=4.10", "ml_dtypes"]

[project.urls]
Homepage = "https://onnx.ai/onnx-ir"
Issues = "https://github.com/onnx/onnx-ir/issues"
Repository = "https://github.com/onnx/onnx-ir"

[tool.setuptools.dynamic]
version = {attr = "onnx_ir.__version__"}

[tool.pytest.ini_options]
addopts = "--tb=short --color=yes"

Expand Down
34 changes: 34 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
setuptools>=70.0.0
onnxruntime>=1.17.0
rich>=13.7.1

# Docs site
furo
jax[cpu]
matplotlib
myst-parser[linkify]
sphinx-copybutton
sphinx-exec-code
sphinx-gallery
sphinx>=6
myst_nb
chardet

# Testing
expecttest==0.1.6
hypothesis
packaging
parameterized
pytest-cov
pytest-randomly
pytest-subtests
pytest-xdist
pytest!=7.1.0
pyyaml
torch>=2.3
torchvision>=0.18.0
transformers>=4.37.2

# Lint
lintrunner>=0.10.7
lintrunner_adapters>=0.12.0
27 changes: 17 additions & 10 deletions src/onnx_ir/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) ONNX Project Contributors
# SPDX-License-Identifier: Apache-2.0
"""In-memory intermediate representation for ONNX graphs."""

__all__ = [
Expand Down Expand Up @@ -81,11 +81,13 @@
# IO
"load",
"save",
# Flags
"DEBUG",
]

from onnxscript.ir import convenience, external_data, passes, serde, tape, traversal
from onnxscript.ir._convenience._constructors import node, tensor
from onnxscript.ir._core import (
from onnx_ir import convenience, external_data, passes, serde, tape, traversal
from onnx_ir._convenience._constructors import node, tensor
from onnx_ir._core import (
Attr,
AttrFloat32,
AttrFloat32s,
Expand Down Expand Up @@ -121,12 +123,12 @@
TypeAndShape,
Value,
)
from onnxscript.ir._enums import (
from onnx_ir._enums import (
AttributeType,
DataType,
)
from onnxscript.ir._io import load, save
from onnxscript.ir._protocols import (
from onnx_ir._io import load, save
from onnx_ir._protocols import (
ArrayCompatible,
AttributeProtocol,
DLPackCompatible,
Expand All @@ -145,14 +147,19 @@
TypeProtocol,
ValueProtocol,
)
from onnxscript.ir.serde import TensorProtoTensor, from_onnx_text, from_proto, to_proto
from onnx_ir.serde import TensorProtoTensor, from_onnx_text, from_proto, to_proto

__version__ = "0.1.0"
DEBUG = False


def __set_module() -> None:
"""Set the module of all functions in this module to this public module."""
global_dict = globals()
for name in __all__:
global_dict[name].__module__ = __name__
if hasattr(global_dict[name], "__module__"):
# Set the module of the function to this module
global_dict[name].__module__ = __name__


__set_module()
11 changes: 5 additions & 6 deletions src/onnx_ir/_convenience/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) ONNX Project Contributors
# SPDX-License-Identifier: Apache-2.0
"""Convenience methods for constructing and manipulating the IR.

This is an internal only module. We should choose to expose some of the methods
Expand All @@ -20,7 +20,7 @@

import onnx

from onnxscript.ir import _core, _enums, _protocols, serde
from onnx_ir import _core, _enums, _protocols, serde

SupportedAttrTypes = Union[
str,
Expand Down Expand Up @@ -188,7 +188,7 @@ def convert_attributes(
types are: int, float, str, Sequence[int], Sequence[float], Sequence[str],
:class:`_core.Tensor`, and :class:`_core.Attr`::

>>> from onnxscript import ir
>>> import onnx_ir as ir
>>> import onnx
>>> import numpy as np
>>> attrs = {
Expand Down Expand Up @@ -269,7 +269,7 @@ def replace_all_uses_with(

We want to replace the node A with a new node D::

>>> from onnxscript import ir
>>> import onnx_ir as ir
>>> input = ir.Input("input")
>>> node_a = ir.Node("", "A", [input])
>>> node_b = ir.Node("", "B", node_a.outputs)
Expand Down Expand Up @@ -355,7 +355,6 @@ def replace_nodes_and_values(
old_values: The values to replace.
new_values: The values to replace with.
"""

for old_value, new_value in zip(old_values, new_values):
# Propagate relevant info from old value to new value
# TODO(Rama): Perhaps this should be a separate utility function. Also, consider
Expand Down
Loading