You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tvm.apache.org by Zihao Ye via Apache TVM Discuss <no...@discuss.tvm.ai> on 2021/08/01 18:45:51 UTC
[Apache TVM Discuss] [Development/pre-RFC] [RFC] Better type hinting
for TVM scripts
Current TVM's scripting mode (TIR's hybrid script/TVM's hybrid script) uses sub-language embedded in python frontend, user cannot use type hinting and auto completion tools because the code is not parsed by python.
We can create a `.pyi` stub for these keywords which only annotates type and leave the implementations empty (actually we don't need them). The stub could also help us generate language reference for user to grasp the syntax and semantics of TIR scripts.
For example, if I write a `__init__.pyi` under `tvm.tir` (from simplicity, it only cover a few keywords):
```python
from typing import Tuple, Union, List
from .schedule import LoopRV, BlockRV
from ..ir import PrimExpr
class serial:
def __init__(self, start: PrimExpr, end: PrimExpr) -> None: ...
def __enter__(self) -> LoopRV: ...
class grid:
def __init__(self, *args: Union[int, PrimExpr, ]) -> None: ...
def __enter__(self) -> LoopRV: ...
class block:
def __init__(self, *args: PrimExpr, name: str = '') -> None: ...
def __enter__(self) -> List[LoopRV]: ...
```
The purpose of this stub is to create an environment where user can write TVM scripts as fluent as general python programs, with normal type hinting and auto completion when user write their TIR scripts.
To achieve this purpose, we want to retain the semantics of TIR keywords in Python. However, the API of tir functions nested in hybridscripts doesn't necessarily align with that of functions defined under `tvm.tir` python module, the alignment requires some effort. We can also create another namespace (module) for keywords and import them via `import tvm.tir.script.namespace as T`.
Besides the alignment issue, I want to hear more from the community about the proposal, feel free to leave your suggestions and concerns here.
---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-better-type-hinting-for-tvm-scripts/10672/1) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/1faf361d613d77cc46faceac231e4ac9fe64e7d966d6e0533b7504b35465e4a0).
[Apache TVM Discuss] [Development/pre-RFC] [RFC] Better type hinting
for TVM scripts
Posted by Junru Shao via Apache TVM Discuss <no...@discuss.tvm.ai>.
Thanks for the proposal! It is definitely extremely important for us to have better type hints and documents for TVM scripts.
One quick question I have been thinking of: is it possible to unify and prevent divergence between `tir.XXX` in the script and `tvm.tir` namespace? If so, there probably won't be necessary to introduce a new namespace `tvm.tir.script.namespace `
---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-better-type-hinting-for-tvm-scripts/10672/2) to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/84422c5059e6f675dd4409c8415e336cc7370425fe4b3bdba4c4e69f3851de4a).