Operators are the basic building blocks that define ONNX model. With a rich set of operators, ONNX can describe most DNN and ML models from various frameworks. Functions allow for composing complex operators from 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.
- Decide what to propose
- Submit PR for new operator/function
- Review of PR by Operators SIG
- Merging of PR and inclusion in next ONNX release
In order to propose a new operator/function, the following is needed:
- If the operator can be composed by other ONNX operators, then it should be a function and not an operator (we have a function in ONNX : MeanVarianceNormalization).
- If the operators can be split to new primitives, propose those primitives instead and make the operator a function.
- Based on a model. This will help us understand the usage and that it solves an actual problem. For the case of the model being private or IP and can't be shared, the operator doesn't belong to the standard and should be implemented as custom OP.
- The operator needs to be implemented by at-least one (well-known) framework. This help us to understand the actual behavior of the operator and its usage.
- Operator signature and behavior:
- If the operator is available in numpy, prefer numpy semantics.
- If the operator is available in more than one frameworks, make sure that your design is general and cover those frameworks.
- Prefer attributes over inputs.
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 detailed description about the operator, and its expected behavior. Pretty much, the description should be clear enough to avoid confusion between implementors.
- Add an example in the description to illustrate the usage.
- Add reference to the source of the operator in the corresponding framework in the description (if possible).
- Write the mathematic formula or a pseudocode in the description. The core algorithm needs to be very clear.
- 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.
- The testing examples will be extracted to the doc.
- We also generate binary data for it.
- Example: https://github.com/onnx/onnx/blob/master/onnx/backend/test/case/node/abs.py
- Update the documentation and generate the test data.
- Running the script to update the doc and generate the test data.
- Shape Inference function
- Please provide a shape inference function in cases where it is meaningful and applicable.
- In cases where shape inference is not possible, it must have logic to perform rank inference at the very least (adding right amount of dimensions to the output shape)
- Shape inference functions must be accompanied by unit tests (https://github.com/onnx/onnx/blob/master/onnx/test/shape_inference_test.py).
- You can refer to the shape inference function for the
TopK
operator while implementing your own function (https://github.com/onnx/onnx/blob/master/onnx/defs/math/defs.cc#L943)
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 master 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 master branch. Your new operator/function will be part of that release.