tlopex opened a new pull request, #18288:
URL: https://github.com/apache/tvm/pull/18288
This PR adds symbolic shape support to `BasePyModule`, which enables dynamic
tensor operations with runtime shape inference. This allows users to use
Relax's symbolic shape functionality in Python function calls through
BasePyModule, with dimensions automatically resolved at execution time based on
input tensor shapes.
## Usage Example
```python
import tvm
from tvm.script import ir as I, relax as R
from tvm.relax.base_py_module import BasePyModule
import numpy as np
@I.ir_module
class VectorAddModule(BasePyModule):
@R.function
def add(x: R.Tensor(("n",), "float32"),
y: R.Tensor(("n",), "float32")) -> R.Tensor(("n",), "float32"):
return R.add(x, y)
module = VectorAddModule(device=tvm.cpu(0), target="llvm")
a = np.array([1.0, 2.0, 3.0], dtype="float32")
b = np.array([4.0, 5.0, 6.0], dtype="float32")
result = module.add(a, b) # Result: [5.0, 7.0, 9.0]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]