[Unity][BlockBuilder] Depracate BlockBuilder.get() and change it to BlockBuilder.finalize()#16090
Conversation
6b36059 to
a5a7d78
Compare
python/tvm/relax/block_builder.py
Outdated
| # avoid circular import | ||
| from .transform import NormalizeGlobalVar | ||
|
|
||
| mod = _ffi_api.BlockBuilderGetContextIRModule(self) # type: ignore |
There was a problem hiding this comment.
Is it possible to embed the pass inside the BlockBuilderGetContextIRModule? aka we can have the same behavior on both python and cpp side
There was a problem hiding this 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.
There was a problem hiding this comment.
I think that we should not turn it on by default. Because there are not too many cases we create new public functions, and renormlaization can be costly. We should however add wellform check to ensure normal passes do not generate code that violate this assumption
Maybe we do not make it part of BlockBuilder.get() but instead add a new function BlockBuilder.finalize() and add remark that it will also normalizes the calls.
There was a problem hiding this comment.
For the cost of renormalization, currently if no function needs renaming, the pass will return directly and not get into the AST. In this case I think the cost is not that high.
The wellformed check is already added.
And for bb.finalize(), I think this will make it confused to use bb.finalize() or bb.get(), because their only difference is whether apply NormalizeGlobalVar or not. If we require users only use bb.finalize() at the end of the IRModule building process, that means a major behaviour change and all related tests might need to be changed.
There was a problem hiding this comment.
OK, we can keep this for now and keep the documentaiton.
BlockBuilder.get()BlockBuilder.get() and change it to BlockBuilder.finalize()
|
cc @Hzfengsy @tqchen @junrushao Plz take a look |
|
@tvm-bot rerun |
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/6917012591 Detailswith response |
|
@tvm-bot rerun |
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/6917034777 Detailswith response |
|
@tvm-bot rerun |
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/6920387363 Detailswith response |
|
@Ubospica you need to push a new commit |
2b6b68c to
0c5d3e2
Compare
… `BlockBuilder.finalize()` (apache#16090) * 1108 * fix ci * 1109 * finished * fix ci
…ge it to `BlockBuilder.finalize()` (apache#16090)" This reverts commit 2dcb871.
…ge it to `BlockBuilder.finalize()` (apache#16090)" This reverts commit 2dcb871.
Previously BlockBuilder would have a problem about naming of public function if we
Previously, BlockBuilder would rename the latter, i.e. the public function. That led the name of the public function did not match the name of its global_symbol attribute.
To tackle this problem, this PR introduces a new pass NormalizeGlobalVar. This pass will possibly rename the GlobalVar in an IRModule to ensure these properties:
This PR adds a member function
bb.finalize()to be used at the end of the building process. It will call NormalizeGlobalVar to ensure the invariant, and returns the final IRModule. It essentially substitutes the functionality ofbb.get(), so we mark the latter deprecated.About naming: we can still use the interface
bb.get()and execute a NormalizeGlobalVar pass in it. But suchbb.get()can only be called once at the end of the building process. So we rename it tobb.finalize()for clearity and alignment with C++ side.cc @junrushao @tqchen