[Docs] Add tutorial for mixing Python/PyTorch with TVM using BasePyModule#18947
Merged
MasterJH5574 merged 6 commits intoapache:mainfrom Mar 29, 2026
Merged
[Docs] Add tutorial for mixing Python/PyTorch with TVM using BasePyModule#18947MasterJH5574 merged 6 commits intoapache:mainfrom
MasterJH5574 merged 6 commits intoapache:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new tutorial for BasePyModule, demonstrating how to integrate Python functions, TIR kernels, and Relax graphs within a single IRModule. It also refactors the compilation logic in base_py_module.py to more efficiently check for Relax functions. Feedback was provided to improve the R.call_py_func tutorial example by calling the Relax function directly to better illustrate the VM's callback mechanism and to simplify the assertion logic.
Member
Author
|
@tvm-bot rerun |
Contributor
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/23676691613 Detailswith response |
MasterJH5574
approved these changes
Mar 29, 2026
Contributor
MasterJH5574
left a comment
There was a problem hiding this comment.
Overall LGTM, thank you @tlopex .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pr add a new tutorial
mix_python_and_tvm_with_pymodule.pydemonstrating how to useBasePyModuleto mix Python/PyTorch functions with TIR and Relax in a single IRModule.Tutorial Contents (7 steps)
I.pyfunc+call_tirbasics, DLPack zero-copy conversion,show()printin pyfuncs — inspect intermediate tensors without compilingcall_tir,call_dps_packed, and Python/PyTorch in one forward passadd_python_functionRelaxToPyFuncConverter— convert Relax IR to PyTorch at different compilation stages (before and after passes) to verify numerical correctnessR.call_py_func— cross-level calls between compiled Relax VM and Python functionsThis pr also fixs a bug in
BasePyModule._compile_functionswhere modules without Relax functions would incorrectly attempt Relax VM compilation, producing spurious warnings likeFailed to compile Relax VM: 'NoneType' object has no attribute 'kind'.