[POC] PyTorch Inlined Extension #29546
Draft
+308
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It is a seamless way to embed a Python portion of the original PyTorch model into OpenVINO model as a custom operation without the explicit creation of a custom operation class.
This feature combines two core technologies: Python OpenVINO custom ops and PyTorch opaque
autograd.Function
(the same tool that is used underneath theModuleExtension
).The main target users are model enablers who are exporting complex models from PyTorch ecosystem to OpenVINO ecosystem. They can hide parts of the original PyTorch model in on-the-fly defined opaque custom operations if there are issues with model tracing/conversion to OpenVINO.
Run the resulting OpenVINO model as-is with vanilla OpenVINO API in the same Python process. Provide an optimized implementation of such operations in C++ OpenVINO custom operations for performance reasons and to be ready to deploy without Python/PyTorch dependency.
Example:
Resulting OpenVINO model (custom op is
InlinedCustomOp
,id
attribute is unique for each op instance):Discovered limitations
Thanks to @eaidova, it was found that when
torch.Tensor
objects is used insideinlined_extension
decorated function and this object is not present among input arguments as traced object (that means it is hidden inside some opaque data structure in one of the arguments, or even not passed to a function as an argument), then it leads to the exception thrown from C++ torch implementation like this one: