Skip to content

Conversation

@tlopex
Copy link
Member

@tlopex tlopex commented Aug 30, 2025

This PR implements TVMScript printer to format IRModules containing @I.pyfunc decorated Python functions.

Example:

@I.ir_module
class MyModule(BasePyModule):
    @I.pyfunc
    def python_func(self, x, y):
        x_tvm = self._convert_pytorch_to_tvm(x)
        y_tvm = self._convert_pytorch_to_tvm(y)
        result = self.call_tir(self.add_tir, [x_tvm, y_tvm], 
                             out_sinfo=R.Tensor((5,), "float32"))
        return self._convert_tvm_to_pytorch(result)
    
    @T.prim_func
    def add_tir(a: T.handle, b: T.handle, c: T.handle):
        A = T.match_buffer(a, (5,), "float32")
        B = T.match_buffer(b, (5,), "float32")
        C = T.match_buffer(c, (5,), "float32")
        for i in range(5):
            C[i] = A[i] + B[i]

# Usage:
print(MyModule.script())  # Print formatted TVMScript
MyModule.show()           # Display formatted output

@tlopex
Copy link
Member Author

tlopex commented Aug 30, 2025

cc @MasterJH5574

@tlopex
Copy link
Member Author

tlopex commented Sep 3, 2025

cc @MasterJH5574

Copy link
Contributor

@MasterJH5574 MasterJH5574 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @tlopex.

@MasterJH5574 MasterJH5574 merged commit 887a9ca into apache:main Sep 4, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants