[Bug] [TIR] variable b has been used before definition! #17572
Labels
needs-triage
PRs or issues that need to be investigated by maintainers to find the right assignees to address it
type: bug
I want to create my own prefill tir function, but when i built this module to test, the error messages above were appeared.
I don't know the reason why the bug will be created.
Actual situation
Traceback (most recent call last): File "/home/octal/mlc-llm/3rdparty/tvm/python/tvm/relax/frontend/nn/llm/test_equal.py", line 554, in <module> lib_cpu = tvm.build(IR_cpu, target="llvm") File "/home/octal/mlc-llm/3rdparty/tvm/python/tvm/driver/build_module.py", line 297, in build rt_mod_host = _driver_ffi.tir_to_runtime(annotated_mods, target_host) File "/home/octal/mlc-llm/3rdparty/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 245, in __call__ raise_last_ffi_error() File "/home/octal/mlc-llm/3rdparty/tvm/python/tvm/_ffi/base.py", line 481, in raise_last_ffi_error raise py_err File "/home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc", line 531, in operator() return TIRToRuntime(inputs_arg, host_target); File "/home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc", line 492, in tvm::TIRToRuntime(tvm::runtime::Map<tvm::Target, tvm::IRModule, void, void> const&, tvm::Target const&) auto pair = SplitMixedModule(ir_module, target, target_host); File "/home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc", line 418, in tvm::SplitMixedModule(tvm::IRModule, tvm::Target const&, tvm::Target const&) mod_mixed = ApplyPasses(mod_mixed, MixedModulePassManager(mod_mixed, target)); File "/home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc", line 291, in tvm::ApplyPasses(tvm::IRModule, tvm::transform::Sequential) mod = seq(std::move(mod)); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/transforms/make_packed_api.cc", line 458, in operator() func = MakePackedAPI(std::move(func)); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/transforms/make_packed_api.cc", line 420, in tvm::tir::MakePackedAPI(tvm::tir::PrimFunc) Array<Var> undefined = UndefinedVars(func_ptr->body, func_ptr->params); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc", line 186, in tvm::tir::UndefinedVars(tvm::tir::Stmt const&, tvm::runtime::Array<tvm::tir::Var, void> const&) m(stmt); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h", line 35, in VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > fvisit(arr[i]); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 119, in operator() VisitArray(op->seq, [this](const Stmt& s) { this->VisitStmt(s); }); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc", line 58, in tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) this->VisitStmt(op->body); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc", line 61, in tvm::tir::VarUseDefAnalyzer::VisitStmt_(tvm::tir::ForNode const*) this->HandleDef(op->loop_var); File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc", line 136, in tvm::tir::VarUseDefAnalyzer::HandleDef(tvm::tir::Var const&) ICHECK(!def_count_.count(v)) << "variable " << v->name_hint tvm.error.InternalError: Traceback (most recent call last): 45: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc:531 44: tvm::TIRToRuntime(tvm::runtime::Map<tvm::Target, tvm::IRModule, void, void> const&, tvm::Target const&) at /home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc:492 43: tvm::SplitMixedModule(tvm::IRModule, tvm::Target const&, tvm::Target const&) at /home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc:418 42: tvm::ApplyPasses(tvm::IRModule, tvm::transform::Sequential) at /home/octal/mlc-llm/3rdparty/tvm/src/driver/driver_api.cc:291 41: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/transforms/make_packed_api.cc:458 40: tvm::tir::MakePackedAPI(tvm::tir::PrimFunc) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/transforms/make_packed_api.cc:420 39: tvm::tir::UndefinedVars(tvm::tir::Stmt const&, tvm::runtime::Array<tvm::tir::Var, void> const&) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc:186 38: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 37: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 36: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 35: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 34: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 33: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 32: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 31: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 30: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 29: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 28: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 27: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 26: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 25: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 24: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 23: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 22: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 21: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 20: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 19: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 18: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 17: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 16: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 15: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 14: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 13: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 12: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 11: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::SeqStmtNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 10: VisitArray<tvm::tir::Stmt, tvm::tir::StmtVisitor::VisitStmt_(const tvm::tir::SeqStmtNode*)::<lambda(const tvm::tir::Stmt&)> > at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/functor_common.h:35 9: operator() at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:119 8: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 7: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 6: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 5: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 4: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 3: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 2: tvm::tir::StmtVisitor::VisitStmt_(tvm::tir::AllocateNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/ir/stmt_functor.cc:58 1: tvm::tir::VarUseDefAnalyzer::VisitStmt_(tvm::tir::ForNode const*) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc:61 0: tvm::tir::VarUseDefAnalyzer::HandleDef(tvm::tir::Var const&) at /home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc:136 File "/home/octal/mlc-llm/3rdparty/tvm/src/tir/analysis/var_use_def_analysis.cc", line 138 InternalError: Check failed: (!use_count_.count(v)) is false: variable b has been used before definition!
Reproduce
cc @Hzfengsy @junrushao @quic-sanirudh @shingjan
The text was updated successfully, but these errors were encountered: