This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch unity in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push: new 138cb651e0 [Unity][BlockBuilder] Restore bb.get() (#16378) 138cb651e0 is described below commit 138cb651e01552544c9fce60ea1e7f7d4db08349 Author: Yixin Dong <ubosp...@gmail.com> AuthorDate: Fri Jan 12 22:23:29 2024 +0800 [Unity][BlockBuilder] Restore bb.get() (#16378) * finalize * fix ci --- include/tvm/relax/block_builder.h | 6 +++++- python/tvm/relax/block_builder.py | 13 ++++++------- tests/python/relax/test_blockbuilder_core.py | 12 ++++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/tvm/relax/block_builder.h b/include/tvm/relax/block_builder.h index 4272b3f75e..a1e5a6bc31 100644 --- a/include/tvm/relax/block_builder.h +++ b/include/tvm/relax/block_builder.h @@ -87,7 +87,11 @@ class BlockBuilderNode : public Object { * GlobalVars in the IRModule to ensure name uniqueness and the invariant: * every public function has the same name as its "global_symbol" attribute. * - * \return The IRModule in this BlockBuilder. + * \note this method should be called only once at the end of the building process, since it may + * invalidate global vars previously returned by this builder. See also + * transform::NormalizeGlobalVar. + * + * \return The result IRModule. */ virtual IRModule Finalize() = 0; diff --git a/python/tvm/relax/block_builder.py b/python/tvm/relax/block_builder.py index 0a408578df..b4206f76f4 100644 --- a/python/tvm/relax/block_builder.py +++ b/python/tvm/relax/block_builder.py @@ -22,7 +22,6 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Union import tvm from tvm import relax as rx from tvm import tir -from tvm.ir.base import deprecated from tvm.ir.module import IRModule from tvm.runtime import Object @@ -654,16 +653,16 @@ class BlockBuilder(Object): """ return _ffi_api.BlockBuilderNormalize(self, expr) # type: ignore - @deprecated("tvm.relax.BlockBuilder.get", "tvm.relax.BlockBuilder.finalize") def get(self) -> tvm.IRModule: - """Return the IRModule being built. + """Return intermediate IRModule. For the situation where the IRModule is needed in the + middle of a building process. Returns ------- ret : tvm.IRModule An IRModule with Relax and TIR functions being built. """ - return self.finalize() + return _ffi_api.BlockBuilderGetContextIRModule(self) # type: ignore def finalize(self) -> tvm.IRModule: """Finalize the building process and return the result IRModule. @@ -671,9 +670,9 @@ class BlockBuilder(Object): Possibly rename GlobalVars in the IRModule to ensure name uniqueness and the invariant: every public function has the same name as its "global_symbol" attribute. - Note this call may invalidate global vars previously returned by this builder - (see tvm.relax.transform.NormalizeGlobalVar), so it can only be called once at the end of - the building process. + Note this method should be called only once at the end of the building process, since it may + invalidate global vars previously returned by this builder. + See also tvm.relax.transform.NormalizeGlobalVar. Returns ------- diff --git a/tests/python/relax/test_blockbuilder_core.py b/tests/python/relax/test_blockbuilder_core.py index 255ef08560..16023c9c91 100644 --- a/tests/python/relax/test_blockbuilder_core.py +++ b/tests/python/relax/test_blockbuilder_core.py @@ -707,8 +707,10 @@ def test_finalize_public_private_name_conflict(): gv1 = bb.emit_te(te_one, primfunc_name_hint="func") bb.emit_func_output((gv0, gv1)) - mod = bb.finalize() - assert rx.analysis.well_formed(mod) + mod = bb.get() + assert not rx.analysis.well_formed(mod) + mod_final = bb.finalize() + assert rx.analysis.well_formed(mod_final) # relax function call bb = rx.BlockBuilder() @@ -724,8 +726,10 @@ def test_finalize_public_private_name_conflict(): gv0 = bb.emit(rx.Call(gvar1, [])) bb.emit_func_output(gv0) - mod = bb.finalize() - assert rx.analysis.well_formed(mod) + mod = bb.get() + assert not rx.analysis.well_formed(mod) + mod_final = bb.finalize() + assert rx.analysis.well_formed(mod_final) def test_emit_nested_seqexpr_in_binding_block():