Skip to content

Commit

Permalink
Merge the two contributing docs and create instructions for updating …
Browse files Browse the repository at this point in the history
…an op (onnx#5584)

### Description

Merge the two contributing docs and create instructions for updating an
op

### Motivation and Context

Fixes onnx#5379

---------

Signed-off-by: Justin Chu <justinchu@microsoft.com>
Co-authored-by: G. Ramalingam <grama@microsoft.com>
  • Loading branch information
justinchuby and gramalingam committed Sep 13, 2023
1 parent 55ffe4e commit b82bd2d
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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/onnx/onnx/blob/main/docs/CONTRIBUTING.md#code-style for setup instructions.\e[0m"
echo -e "\e[1m\e[36mSee https://github.com/onnx/onnx/blob/main/CONTRIBUTING.md#coding-style for setup instructions.\e[0m"
exit 1
fi
- name: Produce SARIF
Expand All @@ -107,7 +107,7 @@ jobs:
- name: Check auto-gen files are up-to-date
run: |
echo -e "\n::group:: ===> check auto-gen files are up-to-date..."
ONNX_ML=1 python onnx/defs/gen_doc.py
python onnx/gen_proto.py -l
python onnx/gen_proto.py -l --ml
Expand Down
176 changes: 164 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,164 @@ Copyright (c) ONNX Project Contributors

ONNX is a community project and we welcome your contributions! In addition to contributing code, you can also contribute in many other ways:

* Meetings and Discussions
Join SIGS, Working Groups, Community meetings to learn about what is needed and then where there is a good fit to interest and areas of expertise, find ways to actively contribute. Participate in [ONNX technical discussions](https://github.com/onnx/onnx/discussions) on GitHub. Join the ONNX Slack channels at LF AI and Data, help answer questions and welcome new members.
- Meetings and Discussions

* Use Cases and Tools
Develop use cases for ONNX and advocate for ONNX in developer conferences and meetups. Develop tools that import and export using the ONNX spec, and help grow the community of ONNX users. Become a champion for ONNX in your company or organization.
Join SIGS, Working Groups, Community meetings to learn about what is needed and then where there is a good fit to interest and areas of expertise, find ways to actively contribute. Participate in [ONNX technical discussions](https://github.com/onnx/onnx/discussions) on GitHub. Join the ONNX Slack channels at LF AI and Data, help answer questions and welcome new members.

* Roadmap and Features
Understand the ONNX roadmap document, feature priorities, and help implement them. Become an ONNX code and documentation contributor, and work towards committer status on important repos.
- Use Cases and Tools

* Releases and Model Zoo
Help in achieving a release of ONNX, including increasing the number of models in the ONNX Model Zoo that exercise ONNX features.
Develop use cases for ONNX and advocate for ONNX in developer conferences and meetups. Develop tools that import and export using the ONNX spec, and help grow the community of ONNX users. Become a champion for ONNX in your company or organization.

* Publications and Blogs
Add to the growing number of arXiv papers that refer to ONNX. Create blogs, presentations, books, articles and other materials that help increase the adoption of ONNX, and grow the community of users and contributors.
- Roadmap and Features

* Steering Committee
Attend ONNX Steering Committee meetings - they are open to all in the community. Help out where needed and appropriate on SC to-do items. Note that SIG and Working Groups leaders as well as others with demonstrated commitment and contributions to ONNX community may want to self-nominate during the annual SC election cycle.
Understand the ONNX roadmap document, feature priorities, and help implement them. Become an ONNX code and documentation contributor, and work towards committer status on important repos.

- Releases and Model Zoo

Help in achieving a release of ONNX, including increasing the number of models in the ONNX Model Zoo that exercise ONNX features.

- Publications and Blogs

Add to the growing number of arXiv papers that refer to ONNX. Create blogs, presentations, books, articles and other materials that help increase the adoption of ONNX, and grow the community of users and contributors.

- Steering Committee

Attend ONNX Steering Committee meetings - they are open to all in the community. Help out where needed and appropriate on SC to-do items. Note that SIG and Working Groups leaders as well as others with demonstrated commitment and contributions to ONNX community may want to self-nominate during the annual SC election cycle.

## Adding a new operator or creating a new version of an existing operator

ONNX is an open standard, and we encourage developers to contribute high
quality operators to ONNX specification.

Before proposing a new operator, please read [the tutorial](docs/AddNewOp.md).

## Contributing code

You can submit a pull request (PR) with your code. The [SIG](community/sigs.md) or [Working Group](community/working-groups.md) that is responsible for the area of the project your PR touches will review it and merge once any comments are addressed.

### Development

To build ONNX from source please follow the instructions listed [here](https://github.com/onnx/onnx#build-onnx-from-source).

Then, after you have made changes to Python and C++ files:

- `Python files`: The changes are effective immediately in your installation. You don't need to install these again.
- `C++ files`: You need to install these again to trigger the native extension build.

Assuming build succeed in the initial step, simply running

```sh
pip install -e .
```

from onnx root dir should work.

### Folder structure

- `onnx/`: the main folder that all code lies under
- `onnx.proto`: the protobuf that contains all the structures
- `checker.py`: a utility to check whether a serialized ONNX proto is legal
- `shape_inference.py`: a utility to infer types and shapes for ONNX models
- `version_converter.py`: a utility to upgrade or downgrade version for ONNX models
- `parser.py`: a utility to create an ONNX model or graph from a textual representation
- `hub.py`: a utility for downloading models from [ONNX Model Zoo](https://github.com/onnx/models)
- `compose.py`: a utility to merge ONNX models
- `helper.py`: tools for graph operation
- `defs/`: a subfolder that defines the ONNX operators
- `test/`: test files

### Generated operator documentation

Operator docs ([Operators.md](Operators.md), [Operators-ml.md](Operators-ml.md)) and Changelog docs ([Changelog.md](Changelog.md), [Changelog-ml.md](Changelog-ml.md)) are automatically generated based on C++ operator definitions and backend Python snippets. To refresh all these docs, run the following commands from the repo root and commit the results by setting "ONNX_ML=1". By contrast, setting `ONNX_ML=0` will only update `Operators.md` and `Changelog.md`.

```pwsh
# Windows
set ONNX_ML=1
```

```sh
# UNIX
export ONNX_ML=1
pip install -e .
python onnx/defs/gen_doc.py
```

### Coding style

We use `lintrunner` to drive multiple linters defined in `.lintrunner.toml` to lint the codebase.

To run these checks locally, install `lintrunner` and the linters with

```sh
pip install lintrunner lintrunner-adapters
lintrunner init
```

Then lint with

```sh
lintrunner
```

format with

```sh
# Display all lints and apply the fixes
lintrunner -a
# Or apply fixes only (faster)
lintrunner f
```

Run `lintrunner --help` and see the `.lintrunner.toml` file for more usage examples, as well as instructions on how to adopt new linters.

### Testing

ONNX uses [pytest](https://docs.pytest.org) as a test driver. To run tests, you'll first need to install pytest:

```sh
pip install pytest nbval
```

After installing pytest, run from the root of the repo:

```sh
pytest
```

to run the tests.

<!-- TODO(justinchuby): Get rid of the need for manually running stat_coverage -->

You'll need to regenerate test coverage too, by running this command from the root of the repo:

```sh
python onnx/backend/test/stat_coverage.py
```

#### Cpp tests (googletest)

Some functionalities are tested with googletest. Those tests are listed in `test/cpp`, and include tests for shape inference, data propagation, parser, and others.

To run them, first build ONNX with `-DONNX_BUILD_TESTS=1` or `ONNX_BUILD_TESTS=1 pip install -e .`.

##### Linux and MacOS

The cpp tests require dynamically linking to built libraries.

```sh
export LD_LIBRARY_PATH="./.setuptools-cmake-build/:$LD_LIBRARY_PATH"
.setuptools-cmake-build/onnx_gtests
```

##### Windows

```pwsh
# If you set DEBUG=1, use `.setuptools-cmake-build\Debug\onnx_gtests.exe` instead
.setuptools-cmake-build\Release\onnx_gtests.exe
```

### DCO

ONNX has adopted the [DCO](https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin). All code repositories under ONNX require a DCO. (ONNX previously used a CLA, which is being replaced with the DCO.)

DCO is provided by including a sign-off-by line in commit messages. Using the `-s` flag for `git commit` will automatically append this line. For example, running `git commit -s -m 'commit info.'` it will produce a commit that has the message `commit info. Signed-off-by: My Name <my_email@my_company.com>`. The DCO bot will ensure commits are signed with an email address that matches the commit author before they are eligible to be merged.
Expand All @@ -50,3 +185,20 @@ git checkout -b original_patch # create a new branch with the same
git commit -m 'type your own commit msg' -s # signoff that single commit
git push origin original_patch -f # forcibly override the old branch`
```

## CI Pipelines

Every PR needs to pass CIs before merge. CI pipelines details are [here](docs/CIPipelines.md).

## Other developer documentation

- [How to implement ONNX backend (ONNX to something converter)](docs/ImplementingAnOnnxBackend.md)
- [Backend test infrastructure and how to add tests](docs/OnnxBackendTest.md)

## License

[Apache License v2.0](/LICENSE)

## Code of Conduct

[ONNX Open Source Code of Conduct](http://onnx.ai/codeofconduct.html)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ONNX is [widely supported](http://onnx.ai/supported-tools) and can be found in m

ONNX is a community project and the open governance model is described [here](community/readme.md). We encourage you to join the effort and contribute feedback, ideas, and code. You can participate in the [Special Interest Groups](community/sigs.md) and [Working Groups](community/working-groups.md) to shape the future of ONNX.

Check out our [contribution guide](docs/CONTRIBUTING.md) to get started.
Check out our [contribution guide](/CONTRIBUTING.md) to get started.

If you think some operator should be added to ONNX specification, please read
[this document](docs/AddNewOp.md).
Expand Down Expand Up @@ -321,7 +321,7 @@ pytest

# Development

Check out the [contributor guide](docs/CONTRIBUTING.md) for instructions.
Check out the [contributor guide](/CONTRIBUTING.md) for instructions.

# License

Expand Down
56 changes: 35 additions & 21 deletions docs/AddNewOp.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,41 @@ SPDX-License-Identifier: Apache-2.0

# Adding New Operator or Function to ONNX

Or updating an existing operator to a new Opset version.

## Table of Contents

- [Adding New Operator or Function to ONNX](#adding-new-operator-or-function-to-onnx)
- [Table of Contents](#table-of-contents)
- [Proposing and submitting a new operator or function to ONNX ](#proposing-and-submitting-a-new-operator-or-function-to-onnx-)
- [4 steps to add an operator ](#4-steps-to-add-an-operator-)
- [Step 1: Proposing a new operator/function ](#step-1-proposing-a-new-operatorfunction-)
- [Step 2: Submit PR ](#step-2-submit-pr-)
- [Proposing and submitting a new operator or function to ONNX](#proposing-and-submitting-a-new-operator-or-function-to-onnx)
- [4 steps to add an operator](#4-steps-to-add-an-operator)
- [Step 1: Proposing a new operator/function](#step-1-proposing-a-new-operatorfunction)
- [Step 2: Submit PR](#step-2-submit-pr)
- [Example to Follow](#example-to-follow)
- [Step 3: PR Review by Operators SIG ](#step-3-pr-review-by-operators-sig-)
- [Step 3: PR Review by Operators SIG](#step-3-pr-review-by-operators-sig)
- [Sign-off](#sign-off)
- [Step 4: ONNX release ](#step-4-onnx-release-)
- [Removing operator or function ](#removing-operator-or-function-)
- [Removing operator ](#removing-operator-)
- [Removing function ](#removing-function-)
- [Document removing operator or function ](#document-removing-operator-or-function-)
- [Step 4: ONNX release](#step-4-onnx-release)
- [Updating an existing operator](#updating-an-existing-operator)
- [Checklist](#checklist)
- [Removing operator or function](#removing-operator-or-function)
- [Removing operator](#removing-operator)
- [Removing function](#removing-function)
- [Document removing operator or function](#document-removing-operator-or-function)

## Proposing and submitting a new operator or function to ONNX <a name="new_operator_or_function"></a>
## Proposing and submitting a new operator or function to ONNX

Operators are the basic building blocks used to define ONNX models. With a rich set of operators, ONNX can describe most DNN and ML models from various frameworks. Functions enable expressing complex operators in terms of more primitive operators. The ONNX specification includes a core set of operators that enable many models. It is a non-goal to add all possible operators, however more operators are added as needed to cover evolving needs.

In this document, we describe the process of accepting a new proposed operator and how to properly submit a new operator as part of ONNX standard. The goal is to improve on what we currently have based on our experience, learning and feedbacks we gathered from the community.

## 4 steps to add an operator <a name="steps_to_add_an_operator"></a>
## 4 steps to add an operator

1. Decide what to propose
2. Submit PR for new operator/function
3. Review of PR by Operators SIG
4. Merging of PR and inclusion in next ONNX release

### Step 1: Proposing a new operator/function <a name="step1_new_operator_or_function"></a>
### Step 1: Proposing a new operator/function

In order to propose a new operator/function, the following is needed:

Expand All @@ -54,7 +58,7 @@ This requires carefully balancing generality and complexity. For example, genera
N-D tensors is straight-forward (implementation-wise) for some operators, but complex for other operators.
The choice in such cases will be made based on the complexity of such a generalization.

### Step 2: Submit PR <a name="step2_new_operator_or_function"></a>
### Step 2: Submit PR

Once the criteria of proposing new operator/function has been satisfied, you will need to submit a PR for the new operator/function. Here the expectation of what the PR should include. The reviewer is expected to verify the completeness of the PR before signoff.

Expand Down Expand Up @@ -85,21 +89,31 @@ rank inference at the very least (adding right amount of dimensions to the outpu

[PR 1959](https://github.com/onnx/onnx/pull/1959) is a good example to follow.

### Step 3: PR Review by Operators SIG <a name="step3_new_operator_or_function"></a>
### Step 3: PR Review by Operators SIG

The [Operators SIG](https://github.com/onnx/sigs/tree/main/operators) is responsible for the operators/functions in the ONNX specification. The SIG regularly meets and reviews PRs.

#### Sign-off

At least two sign-off from the Operators SIG [contributors](https://github.com/onnx/onnx/tree/main/community#community-roles).

### Step 4: ONNX release <a name="step4_new_operator_or_function"></a>
### Step 4: ONNX release

Once the PR is reviewed and signed off by the Operators SIG, it will be merged. Your new operator/function will be part of the main branch and available to anyone building from source. These are not official releases. ONNX periodically releases official new versions that are a snapshot of the main branch. Your new operator/function will be part of that release.

## Removing operator or function <a name="removing_operator_or_function"></a>
## Updating an existing operator

The definition of an existing operator may need to be updated when e.g. there are new scenarios or input types to support. The process is largely similar to that for creating a new operator.

### Checklist

Use this checklist when updating an existing operator: https://github.com/onnx/onnx/wiki/Checklist-for-updating-an-existing-operator

## Removing operator or function

There are a lot of reasons for removing existing ONNX operator or function, such us being replaced with different operator or can be decomposed by a set of other operators. This document describes the criteria of removing an existing ONNX operator from the standard.

### Removing operator <a name="removing_operator"></a>
### Removing operator

Any operator in ONNX was added because it was required by a model and/or framework. In order to deprecate such an operator we need to do the following.

Expand All @@ -111,11 +125,11 @@ Any operator in ONNX was added because it was required by a model and/or framewo
- Add a version adapter which turns the operator into its replacement for the version converter. Example: [onnx/version_converter/adapters/upsample_9_10.h](/onnx/version_converter/adapters/upsample_9_10.h)
- No grace period is needed for deprecated operators.

### Removing function <a name="removing_function"></a>
### Removing function

Function, by definition, is composed of ONNX primitives; however, function could have been accelerated by framework or runtime that support ONNX. So, removing function is not recommended, with the exception of adding another single function which supersede its functionality.
Function, by definition, is composed of ONNX primitives; however, function could have been accelerated by framework or runtime that support ONNX. So, removing function is not recommended, with the exception of adding another single function which supersedes its functionality.

### Document removing operator or function <a name="document_removing_operator_or_function"></a>
### Document removing operator or function

To make sure everyone is aware of the deprecation, the following need to happen:

Expand Down

0 comments on commit b82bd2d

Please sign in to comment.