Skip to content

Commit c852002

Browse files
authored
[Relax] Add Relax to Python Function Converter (#18269)
### Overview This PR implements a Relax to Python Function Converter that transforms Relax functions into executable Python functions using PyTorch operations. This enables seamless conversion between TVM's Relax IR and Python/PyTorch environments, which provides enhanced debugging capabilities and leveraging existing PyTorch operator libraries for testing and deployment purposes. ### Key Feature - **High-level operator mapping**: Maps 60+ Relax operators to corresponding PyTorch APIs - **Special operation handling**: Supports `call_tir`, `call_dps_packed`, and Relax function calls with DLPack integration - **Symbolic shape support**: Handles symbolic shapes and dynamic tensor operations ### **Example** ```python from tvm.relax.relax_to_pyfunc_converter import RelaxToPyFuncConverter # Convert Relax functions to Python functions converter = RelaxToPyFuncConverter(ir_module) converted_ir_mod = converter.convert("my_function") # Execute converted function with PyTorch tensors result = converted_ir_mod.pyfuncs['my_function'](input_tensor) ```
1 parent 0ae2dc1 commit c852002

File tree

2 files changed

+1970
-0
lines changed

2 files changed

+1970
-0
lines changed

0 commit comments

Comments
 (0)