Ubospica commented on code in PR #16090:
URL: https://github.com/apache/tvm/pull/16090#discussion_r1387575333


##########
python/tvm/relax/block_builder.py:
##########
@@ -661,12 +661,20 @@ def normalize(self, expr: Expr) -> Expr:
     def get(self) -> tvm.IRModule:
         """Return the IRModule being built.
 
+        Note this call may invalidate global vars previously returned by this 
builder
+        (see tvm.relax.transform.NormalizeGlobalVar), so it is recommended to 
call this function
+        once at the end of the build process.
+
         Returns
         -------
         ret : tvm.IRModule
             An IRModule with Relax and TIR functions being built.
         """
-        return _ffi_api.BlockBuilderGetContextIRModule(self)  # type: ignore
+        # avoid circular import
+        from .transform import NormalizeGlobalVar
+
+        mod = _ffi_api.BlockBuilderGetContextIRModule(self)  # type: ignore

Review Comment:
   We have considered that. Here the problem is NormalizeGlobalVar will 
invalidate all global vars previously acquired. But I cannot ensure all pass 
will follow the assumption that no global var will be used again after 
BlockBuilderGetContextIRModule. Actually, some passes like AllocateWorkspace 
might already break the assumption.
   
   On the other hand, on python side BlockBuilder is mainly to build a new 
IRModule from scratch, and not involve too complex logic. So apply 
NormalizeGlobalVar to bb.get() could be a good choice.



-- 
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]

Reply via email to