[Bug] MergeCompositeFunctions fails on a well-formed module when main is not the only Relax function
Thanks for participating in the TVM community! We use https://discuss.tvm.apache.org/ for any general usage questions and discussions. The issue tracker is used for actionable items such as feature proposals discussion, roadmaps, and bug tracking. You are always welcomed to post on the forum first :smile_cat:
Issues that are inactive for a period of time may get closed. We adopt this policy so that we won't lose track of actionable issues that may fall at the bottom of the pile. Feel free to reopen a new one if you feel there is an additional problem that needs attention when an old one gets closed.
Expected behavior
relax.transform.MergeCompositeFunctions should return an IRModule for any well-formed module.
A Relax function that is never called by main should not affect the pass.
Actual behavior
The pass aborts with an internal check failure, and the failing Variable belongs to an unrelated function:
tvm.error.InternalError: Check failed: (it_group != obj2group_.end()) is false:
Variable z could not be found in any groupz is a local binding inside stray, a function that is never referenced by main.
Removing stray from the same module makes the pass succeed.
The error is raised from:
src/relax/transform/fuse_ops.cc:1063
OperatorFusor::GetGroupFromVarEnvironment
- TVM version:
0.26.dev0 - Commit:
8312a17f8734ddfd56e5f3977cd5df25b83ec49f - OS: Linux x86_64, Ubuntu
- Kernel:
5.15 - Python:
3.11 - Device: CPU only
- Reproduces with:
relax.transform.MergeCompositeFunctionsalone
Steps to reproduce
import tvm
from tvm.script import ir as I, relax as R
@I.ir_module
class Module:
@R.function
def main(
x: R.Tensor((4,), "float32"),
) -> R.Tensor((4,), "float32"):
with R.dataflow():
y = R.add(x, x)
R.output(y)
return y
@R.function
def stray(
x: R.Tensor((4,), "float32"),
) -> R.Tensor((4,), "float32"):
with R.dataflow():
z = R.add(x, x)
R.output(z)
return z
tvm.relax.transform.MergeCompositeFunctions()(Module)Difference from a passing case
The same module succeeds if stray is removed:
Only main
-> OK
main + unrelated function stray
-> InternalError: Check failed: (it_group != obj2group_.end()) is false:
Variable z could not be found in any groupIn other words, adding a Relax function that is unrelated to main changes MergeCompositeFunctions from succeeding to failing.
Triage
needs-triagebug
Source: apache/tvm