-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[PyTorch]Add PyTorchTVM: compile torchscript to tvm and export as pytorch_op #8777
Conversation
It would be good for this scope of new feature to start with an RFC. |
Yeah it is super exciting feature for TVM, so would get more visibility in the community if we have like a RFC |
Thanks, I will write an RFC this week. |
Looks great! cc @minminsun |
c8461f4
to
e38511c
Compare
@Meteorix any updates on when this will be ready for review? happy to help shepherd these changes and work with you to get them merged. |
Yes, it's ready for review! |
apps/pt_class/CMakeLists.txt
Outdated
cmake_minimum_required(VERSION 3.2) | ||
project(tf_tvmdsoop C CXX) | ||
|
||
set(TFTVM_COMPILE_FLAGS -std=c++14) |
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.
Update 'TF' or tf
references
python3 -c "import tvm; print(tvm.runtime.enabled('gpu'))" | grep -e 1 | ||
if [ "$?" -eq 0 ]; then | ||
echo "Build PT_TVMCLASS with gpu support and execute tests" | ||
CMAKE_OPTIONS="-DUSE_CUDA=/data00/liuxin.ai/cuda_111 -DPython3_EXECUTABLE=python3 -DTVM_ROOT=${TVM_ROOT}" |
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.
Update /data00/liuxin.ai/cuda_111
|
||
|
||
model = resnet50().half().cuda() | ||
x = torch.rand([1, 3, 244, 244]).half().cuda() |
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.
224?
a9ba531
to
4db2d9e
Compare
I've fixed some namespace and style issues. Could you please help review this PR? @junrushao1994 @jcf94 @msakai @jroesch And I have some questions to discuss:
|
Sorry I forgot about this PR, will take another look soon. cc @junrushao1994 @jroesch |
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.
Code mostly looks good. I have a couple of questions around target/device.
To answer @kongroo's question:
- For multi-threaded applications, users should create multiple instances of TVM / PT module per thread from the same dll.
- Not sure if that is a TVM's problem or an OS issue (related? https://stackoverflow.com/questions/16525016/how-to-dynamic-load-the-library-with-same-name-but-in-different-directory-in-lin), but always enforcing an absolute path sounds good to me (either in
dso_library.cc
or at the application level). - Currently, our performance on dynamic input is terrible. Moreover, we need to deal with the same problem in other contexts too, such as in CUTLASS BYOC [BYOC] CUTLASS integration #9261 or AutoTIR. So I suggest deferring this problem for now.
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.
Great!
@kongroo Please make sure to pass the CI. @jroesch @junrushao1994 @tqchen @comaniac Please take a look if you want to review. Otherwise I'm going to merge this week, I think we can bring this to the v0.8 release. |
@kongroo Looks like you've hit an unfortunate flaky test error, please kick another job. |
Finally CI passed... |
…orch_op (apache#8777) * add pt_op * add compile api * perf: support set_output_zero_copy * fix: cpu device_id mismatch * fix: pt_class test script * refactor: unify namespace to tvm.contrib.torch * add ASF header * build: set pt tvmdsoop default off * build: remove unset_log_macros.h * refactor: change header order * refactor: fix python code format * style: resolve pylint issues * style: add blank line * style: fix pylint invalid_name * trigger CI * test: add more test scripts * style: add empty lines * test: update test for trace tvm module * style: fix linting issues * style: remove single quote * style: disable pylint invalid-name * trigger CI * trigger CI Co-authored-by: kongroo <imjcqt@gmail.com>
…orch_op (apache#8777) * add pt_op * add compile api * perf: support set_output_zero_copy * fix: cpu device_id mismatch * fix: pt_class test script * refactor: unify namespace to tvm.contrib.torch * add ASF header * build: set pt tvmdsoop default off * build: remove unset_log_macros.h * refactor: change header order * refactor: fix python code format * style: resolve pylint issues * style: add blank line * style: fix pylint invalid_name * trigger CI * test: add more test scripts * style: add empty lines * test: update test for trace tvm module * style: fix linting issues * style: remove single quote * style: disable pylint invalid-name * trigger CI * trigger CI Co-authored-by: kongroo <imjcqt@gmail.com>
…orch_op (apache#8777) * add pt_op * add compile api * perf: support set_output_zero_copy * fix: cpu device_id mismatch * fix: pt_class test script * refactor: unify namespace to tvm.contrib.torch * add ASF header * build: set pt tvmdsoop default off * build: remove unset_log_macros.h * refactor: change header order * refactor: fix python code format * style: resolve pylint issues * style: add blank line * style: fix pylint invalid_name * trigger CI * test: add more test scripts * style: add empty lines * test: update test for trace tvm module * style: fix linting issues * style: remove single quote * style: disable pylint invalid-name * trigger CI * trigger CI Co-authored-by: kongroo <imjcqt@gmail.com>
…orch_op (apache#8777) * add pt_op * add compile api * perf: support set_output_zero_copy * fix: cpu device_id mismatch * fix: pt_class test script * refactor: unify namespace to tvm.contrib.torch * add ASF header * build: set pt tvmdsoop default off * build: remove unset_log_macros.h * refactor: change header order * refactor: fix python code format * style: resolve pylint issues * style: add blank line * style: fix pylint invalid_name * trigger CI * test: add more test scripts * style: add empty lines * test: update test for trace tvm module * style: fix linting issues * style: remove single quote * style: disable pylint invalid-name * trigger CI * trigger CI Co-authored-by: kongroo <imjcqt@gmail.com>
To increase the TVM accessibility for PyTorch users, we add PyTorchTVM module to support the following workflow:
The example usage is here: apps/pt_class/tests/test_pt_script.py. We hope to further discuss the user api with the community. Please help review @Laurawly @junrushao1994 @tqchen, thanks!
Credit: the original author is @kongroo .