docs/AddNewOp.md
Or updating an existing operator to a new Opset version.
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.
In order to propose a new operator/function, the following is needed:
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.
Description:
Write a reference implementation in Python, this reference implementation should cover all the expected behavior of the operator. Only in extremely rare case, we will waive this requirement.
Operator version: check out our versioning doc
Write unit test, that cover main usage and corner cases.
Write upgrade and downgrade tests:
_test_op_upgrade. These tests create a given operator at a given opset version (usually the version the operator was introduced in) and test that the version converter is able to convert them to the highest available version. So for a new operator _test_op_upgrade will not test anything, but as soon as the operator gets updated in a future opset the test will automatically become nontrivial._test_op_downgrade. Specifying the current version so that once the op is updated at a higher opset version the test will ensure downward conversion is validated.Update the documentation and generate the test data.
onnx/backend/test/data/node which cannot be generated by the scripts from onnx/backend/test/case/node, please further use python onnx/backend/test/cmd_tools.py generate-data --clean to cleanup the directory and only preserve needed test data.
to update the doc and generate the test data.Shape Inference function
TopK operator while implementing your own function (onnx/defs/math/defs.cc)PR 1959 is a good example to follow.
The Operators SIG is responsible for the operators/functions in the ONNX specification. The SIG regularly meets and reviews PRs.
At least two sign-off from the Operators SIG contributors.
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.
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.
Use this checklist when updating an existing operator: https://github.com/onnx/onnx/wiki/Checklist-for-updating-an-existing-operator
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.
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.
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.
To make sure everyone is aware of the deprecation, the following need to happen:
def.cc need to be remove, old.cc will remain.old.cc need to be updated with the mapping to the replacement.operator.md file.