[Bugfix][Relax] BlockBuilder may not assume unique input functions #16805
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this commit, the implementation of
relax::BlockBuilder::AddFunctionimplicitly assumed that the inputIRModuledoes not contain duplicate copies of the same function. This commit updates the implementation, removing the reliance on this assumption. This commit resolves the error by tracking allGlobalVarthat map to the same function, rather than an just one.A well-formed IRModule may contain duplicate function definitions. This is rare, as most functions can be disambiguated by the the function attribute
tvm::attr::kGlobalSymbol. However, private functions do not have this attribute, and a well-formed IRModule may contain multiple copies of the same function.The regression test added in this PR calls
BlockBuilder::UpdateFuncandBlockBuilder::AddFuncin a specific order to reproduce this issue. In practice, this failure was sporadic, depending on the order in which a transformation pass visited functions in a module. This was first observed inVMShapeLower, with sporadic errors depending on the order of iteration overmod->functions.