-
Notifications
You must be signed in to change notification settings - Fork 3.8k
ONNX2: prototype for a replacement of protobuf = same API, same format as ONNX but without protobuf #7208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7208 +/- ##
==========================================
+ Coverage 54.33% 55.98% +1.64%
==========================================
Files 511 519 +8
Lines 31819 33708 +1889
Branches 2848 2995 +147
==========================================
+ Hits 17290 18871 +1581
- Misses 13753 14008 +255
- Partials 776 829 +53 ☔ View full report in Codecov by Sentry. |
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
### Description Switch to pybind11 3.0. --------- Signed-off-by: xadupre <[email protected]>
### Description <!-- - Describe your changes. --> `BUILD_ONNX_PYTHON` has been deprecated since 1.18. ### Motivation and Context Better code. # Signed-off-by: cyy <[email protected]> Co-authored-by: Andreas Fehlner <[email protected]> Signed-off-by: xadupre <[email protected]>
Remove deprecated methods that are scheduled to removed in 1.20. Fixes onnx#7213 --------- Signed-off-by: Justin Chu <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description currently, convInteger does handle ``x_zero_points`` and ``w_zero_points`` correctly when they are not ``None``. The ``None`` check on the arguments only worked when they are ``None`` since calling ``bool``on a numpy Array does not work. Furthermore, the broadcasting for ``w_zero_points`` did not work correctly, since ``w_zero_points`` needs to be applied per-output-channel and thus needs manual dimension expanding. ### Motivation and Context The problem arouse when testing onnx-reference via the [onnx-tests](https://github.com/cbourjau/onnx-tests) tool. --------- Signed-off-by: Konstantin Pueckler <[email protected]> Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Andreas Fehlner <[email protected]> Co-authored-by: Justin Chu <[email protected]> Co-authored-by: justinchuby <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description <!-- - Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? --> <!-- - If it fixes an open issue, please link to the issue here. --> --------- Signed-off-by: Andreas Fehlner <[email protected]> Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Justin Chu <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description <!-- - Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? --> <!-- - If it fixes an open issue, please link to the issue here. --> Signed-off-by: Andreas Fehlner <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description <!-- - Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? --> <!-- - If it fixes an open issue, please link to the issue here. --> Signed-off-by: Andreas Fehlner <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description Clean up tests. Remove unnecessary skips and imports. ### Motivation and Context As per issue onnx#7098 there are unnecessary skips and imports in some tests. I found 17 tests that were marked as skipped a couple of years ago, now they pass without warnings. --------- Signed-off-by: Eetu Tunturi <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description In the Attentiion op definition, update the inputs to Range to be scalars as opposed to 1-element vectors, as required by the Range op spec. ### Motivation and Context See discussion [here](onnx#7164 (comment)). --------- Signed-off-by: Yuan Yao <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description <!-- - Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? --> <!-- - If it fixes an open issue, please link to the issue here. --> Signed-off-by: Andreas Fehlner <[email protected]> Signed-off-by: xadupre <[email protected]>
This helps automatic license checkers like pip-licenses to identify the right license for this project This is also the recommendation at https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license Signed-off-by: Erik Cederstrand <[email protected]> Signed-off-by: xadupre <[email protected]>
### Description <!-- - Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? --> <!-- - If it fixes an open issue, please link to the issue here. --> --------- Signed-off-by: Andreas Fehlner <[email protected]> Signed-off-by: xadupre <[email protected]>
…toml) (onnx#7246) ### Description <!-- - Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? --> <!-- - If it fixes an open issue, please link to the issue here. --> Signed-off-by: Andreas Fehlner <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
|
I realize that this is a draft PR, but I just wanted to say that, IMHO, a non-code RFC would be a more manageable basis for a discussion. The Rust RFC template is an excellent starting point for such an endeavor in my experience. |
|
Not sure I'll continue that effort. I wrote the code quite fast. My point was to prove it is doable to remove protobuf. When there is a need, this work will pop up again. |
|
Issues we would not run into by using this: microsoft/onnxruntime#25825. |
onnx2 is a prototype which replicates onnx API without using protobuf. It replaces the protobuf definition of ONNX classes (ModelProto, TensorProto, ...). It is able to load and save onnx files with the same format as protobuf.
This PR is a first step to open a discussion about whether or not we should remove the dependency on protobuf and a way to show this is possible.
The code is placed in a separate folder to let others experiment with it.
The code is not perfect and can be surely improved but it already supports the serialization and parsing for all onnx classes (except TrainingInfoProto and Opaque). It is concrete enough to open a discussion on whether this could replace protobuf. Many tests were implemented to make sure this can be done (see tests in
onnx/tests/test_onnx2_*andonnx/tests/cpp/test_onnx2_*). One file goes through all onnx files in the backend test and makes sure the model remains the same after it was deserialized and serialized again with onnx2. Every model is loaded with onnx2, serialized with onnx2 then parsed with onnx and serialized with onnx. The final serialized strings is equal to the original one. Currently, the serialized strings have the same content, only the order of the attribute may change.It currently provides the following features:
raw_datain a queue. This queue is processed by as many threads as the user wants. This is the only implemented strategy but with 4 threads, a 1Gb model can be read twice faster.onnx.helper.pyruns without any change.The features which are not implemented yet:
HasField(easy to fix).oneofrule: the implementation is not complete yet and could be improvoed. Right now, every oneof attribute does not share the same space in memory.The features we could easily implement:
Proto Definition
Their definition can be found in onnx/onnx2/cpu/onnx2.h. Here is a simple example for class
OperatorSetIdProto. The current implementation in C++ uses many macros instead of templates. That's something which could be easily improved.Their implementation is done in onnx/onnx2/cpu/onnx2.cpp. It should be possible to refactor the code to avoid writing the list of all attributes four times (it is a prototype):
this feature alone allows any future parallelization of the serialization.
Everything not related to the onnx class definition was placed in other files. This work would be used to define other classes than the ONNX ones.
More in onnx/onnx2/README.md.
A comparison of the python bindings and idea of the performance gain.
Unit tests are currently passing. The style needs to be addressed. I'll do that if this idea gets some attraction.