This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch unity-staging
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 2b4e4d930aa877e1520a931c6bf89b2b5b315dec
Author: Ruihang Lai <[email protected]>
AuthorDate: Fri Feb 17 23:06:52 2023 -0500

    [Unity][TVMScript] Move tir/relax import in script out of __init__.py 
(#14033)
    
    Prior to this PR, `python/tvm/script/__init__.py` imports both tir and relax
    submodules. This leads to the phenomenum that when people does
    ```python
    from tvm.script import tir as T
    ```
    , the relax submodule will be implicitly visited by `__init__.py` as well.
    
    Since TIR does not rely on Relax, it is good not to import both of them
    at the same time. (This can prevent cyclic imports sometimes.)
    
    This PR does this decoupling by introducing two files
    
    * `python/tvm/script/relax.py`
    * `python/tvm/script/tir.py`
    
    and removing the imports from `python/tvm/script/__init__.py` and
    `python/tvm/script/parser/__init__.py`. With this change, we force people to
    manually do `from tvm.script import tir` and `from tvm.script import relax`
    to use TVMScript parser, which is right our conventional way.
---
 python/tvm/script/__init__.py               | 2 --
 python/tvm/script/parser/__init__.py        | 6 ++----
 python/tvm/script/parser/tir/__init__.py    | 2 +-
 python/tvm/script/{__init__.py => relax.py} | 7 ++-----
 python/tvm/script/{__init__.py => tir.py}   | 7 ++-----
 5 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/python/tvm/script/__init__.py b/python/tvm/script/__init__.py
index 6d92c68367..f5ee692cbb 100644
--- a/python/tvm/script/__init__.py
+++ b/python/tvm/script/__init__.py
@@ -17,5 +17,3 @@
 """TVM Script APIs of TVM Python Package"""
 from .parser import ir, ir_module
 from .parser import parse as from_source
-from .parser import tir
-from .parser import relax
diff --git a/python/tvm/script/parser/__init__.py 
b/python/tvm/script/parser/__init__.py
index 678297799e..ba7f085c08 100644
--- a/python/tvm/script/parser/__init__.py
+++ b/python/tvm/script/parser/__init__.py
@@ -13,10 +13,8 @@
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
-# under the Licens.
+# under the License.
 """The parser"""
-from . import _core, ir, tir, relax
+from . import _core, ir
 from ._core import parse
 from .ir import ir_module
-from .tir import prim_func
-from .relax import function
diff --git a/python/tvm/script/parser/tir/__init__.py 
b/python/tvm/script/parser/tir/__init__.py
index ad16821a89..e44b6b521b 100644
--- a/python/tvm/script/parser/tir/__init__.py
+++ b/python/tvm/script/parser/tir/__init__.py
@@ -32,4 +32,4 @@ if TYPE_CHECKING:
 else:
     from .entry import prim_func
 
-__all__ = _tir.__all__ + ["Buffer", "Ptr", "prim_func"]
+__all__ = _tir.__all__ + ["Buffer", "Ptr", "bool", "prim_func"]
diff --git a/python/tvm/script/__init__.py b/python/tvm/script/relax.py
similarity index 82%
copy from python/tvm/script/__init__.py
copy to python/tvm/script/relax.py
index 6d92c68367..2301463059 100644
--- a/python/tvm/script/__init__.py
+++ b/python/tvm/script/relax.py
@@ -14,8 +14,5 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-"""TVM Script APIs of TVM Python Package"""
-from .parser import ir, ir_module
-from .parser import parse as from_source
-from .parser import tir
-from .parser import relax
+"""TVM Script APIs of TVM Python Package for Relax"""
+from .parser.relax import *  # pylint: 
disable=redefined-builtin,unused-wildcard-import,wildcard-import
diff --git a/python/tvm/script/__init__.py b/python/tvm/script/tir.py
similarity index 82%
copy from python/tvm/script/__init__.py
copy to python/tvm/script/tir.py
index 6d92c68367..49f3ecd42c 100644
--- a/python/tvm/script/__init__.py
+++ b/python/tvm/script/tir.py
@@ -14,8 +14,5 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-"""TVM Script APIs of TVM Python Package"""
-from .parser import ir, ir_module
-from .parser import parse as from_source
-from .parser import tir
-from .parser import relax
+"""TVM Script APIs of TVM Python Package for TIR"""
+from .parser.tir import *  # pylint: 
disable=redefined-builtin,unused-wildcard-import,wildcard-import

Reply via email to