-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[TVM EP] Improved usability of TVM EP #10241
Conversation
onnxruntime/__init__.py
Outdated
@@ -44,6 +44,15 @@ | |||
except ImportError: | |||
pass | |||
|
|||
try: |
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.
I would prefer to have a mechanism only available when onnxruntime is compiled for this EP and not something always in the code whatever the compilation are.
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.
Hello @xadupre!
Could you take a look at the changes? Maybe you also had some ideas about this?
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.
It looks ok. At least, users know this code is only needed for this provider. I had in mind something which does not add extra code when onnxruntime is compiled without this provider. Something like an import made from C++ surrounded by #ifdef ... STVM ... #endif.
Hello @xadupre!
The first two functions can be removed, for this we already have a corresponding task in Jira. However, the third function ( @tvm.register_func("tvm_onnx_import_and_compile")
def onnx_compile(...):
... This call must occur at runtime, so we cannot move this part to the compilation stage, where it is possible to use Unfortunately, at the moment we are not aware of many alternatives that can solve this problem:
In our opinion, the solution that we proposed in this PR is the best of the voiced alternatives. It does not require any actions from the user and does not require deep reworking of the code in ORT and TVM. @tmoreau89, @jwfromm what do you think about this? Do you have any comments or suggestions? |
Thanks for the clarifications. |
@xadupre, it looks like while working on another task, I found a better way to solve it. |
Will it work for Windows or MacOS ? |
Hi, I don't fully understand the details here. But I assume that this supports initiating execution of onnxruntime from all languages (supported by ort), not just python, right? |
Hello @gramalingam! |
As @KJlaccHoeUM9l said, much of the validation work we've done has been on Linux using Python. I suggest that expanding the scope of OSes supported and languages/envs. supported can be tackled in follow up work/PRs. |
Hello @xadupre! Could you take a look at the changes? |
setup.py
Outdated
@@ -145,6 +145,28 @@ def _rewrite_ld_preload_tensorrt(self, to_preload): | |||
f.write(' import os\n') | |||
f.write(' os.environ["ORT_TENSORRT_UNAVAILABLE"] = "1"\n') | |||
|
|||
def _rewrite_ld_preload_tvm(self): | |||
with open('onnxruntime/capi/_ld_preload.py', 'a') as f: | |||
f.write('import warnings\n\n') |
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.
I suggest the following to make this part easier to read and to modify.
f.write(textwrap.dedent("""
"""))
@xadupre, your comment has been taken into account. Could you please re-approve the PR? |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline |
/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows WebAssembly CI Pipeline, orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed, onnxruntime-python-checks-ci-pipeline |
Azure Pipelines successfully started running 9 pipeline(s). |
Azure Pipelines successfully started running 8 pipeline(s). |
* improved usability of TVM EP * moved technical import under a condition related to TVM EP only * Revert "moved technical import under a condition related to TVM EP only" * add conditional _ld_preload.py file extension for TVM EP * improve readability of inserted code (cherry picked from commit a0fe4a7)
Working between the C++ and Python parts in
TVM EP
is done using thePackedFunc
andRegistry
classes. In order to use a Python function in C++ code, it must be registered in the global table of functions.Registration is carried out through the JIT interface, so it is necessary to call special functions for registration. To do this, we need to make the following import:
In order not to write this line at the beginning of every script where
TVM EP
is required, it was moved to__init__.py
.Thus, only one import needs to be called: