-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Support set schema inference function in python #5940
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
Conversation
We're spending a considerable amount of code on passing proto objects between C++ and Python. However, the repository seems well-prepared for this feature. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5940 +/- ##
==========================================
+ Coverage 56.31% 56.50% +0.18%
==========================================
Files 509 509
Lines 32607 32732 +125
Branches 3099 3099
==========================================
+ Hits 18364 18495 +131
+ Misses 13385 13379 -6
Partials 858 858 ☔ View full report in Codecov by Sentry. |
Hi @justinchuby , In this PR, we can implement shape inference on the Python side, similar to how it's done on the C++ side. If you have any suggestions for this implementation, I'm open to making adjustments accordingly. |
Thank you! Is it ready to be reviewed? |
Yes, I have removed the 'WIP' prefix from the title. Please feel free to leave any comments. :D |
It would be a nice feature to have. |
Thanks for creating the PR! It would be great to add this functionality. My comments above. |
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.
Forgive my mistake, I didn't know that the response need to be commit manually. My reply is always in pending status.
I would do this in a different way. I think we should export in python all functions doing shape inference for every operator. We should have a python version of the algorithm doing shape inference. That way, adding new shape inference function would be easier and we could do local shape inference. This feature is needed when building a model. Shapes can be used to write efficient sequences of onnx operators. |
Hi Xavier, After thinking about it for a while, please correct me if my understanding is wrong. Implementing a Python version of shape inference may not eliminate the need to pass ONNX protos between C++ and Python. In the current architecture, if we want to obtain any proto in the shape inference function, we need to export Best Regards. |
The code-freeze for 1.17 is coming up soon. We may need to move this to a later release. |
6cd35d0
to
2315678
Compare
Hi @gramalingam Sorry for the delay. Please let me briefly describe the changes I made since my last commit.
It looks like there are plans to upgrade protobuf? (#6167) |
8070a53
to
2e7f99e
Compare
Sorry for the delayed response. We are interested in getting this PR in if you are still interested |
Consider possible compatibility issues with zero copy (In fact, we have not enable this feature at present based on pybind11_protobuf) and the number of changes to the project, I removed pybind11_protobuf in the latest commit and add the object transport based on serialization and deserialization. Further optimization may be carried out in the future. If anyone has any suggestions, please feel free to comment. For new types, it is expected to use these to add support. And it will be check at build-time (Only for the type which inherited from Message/Lite Type) |
Maybe I should add more unit tests. |
Signed-off-by: oPluss <opluss@qq.com>
20106ab
to
16ac26a
Compare
Signed-off-by: oPluss <opluss@qq.com>
Hi @justinchuby , the PR has been ready for review. If you have any suggestion, please feel free to comment. |
I think the main changes look good! Sorry for the delay. Just some minor nits |
ffd61fe
to
66a5274
Compare
Need and additional review @xadupre @gramalingam |
It would be great to add an example in the documentation. Let's merge this one but a standalone example would be great. |
### Description Support set schema inference callback function for custion OpSchema before register in python. example: ``` def func(ctx: onnx.shape_inference.InferenceContext): # get some info assert ctx.get_num_inputs() == 2 value = ctx.get_input_type(0) ... # get or create output proto object output = ctx.get_output_type(0) # set type or shape ... # set the result proto ctx.set_output_type(0, output) schema.set_type_and_shape_inference_function(func) ``` ### Note Depends on onnx#5906 ### Motivation and Context Follow up of onnx#5019 --------- Signed-off-by: oPluss <opluss@qq.com> Signed-off-by: gramalingam <grama@microsoft.com>
Description
Support set schema inference callback function for custion OpSchema before register in python.
example:
Note
Depends on #5906
Motivation and Context
Follow up of #5019