[Bug][Relax] `FoldConstant` leaks bindings emitted by a legalizer it only tries speculatively: `dynamic_strided_slice` leaves a `call_tir` to an undefined `shape_func` ("There is no definition of Module.shape_func")
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start in src/relax/transform around FoldConstant and the legalizer it invokes; the issue does not name the implementation file or a test. Reproduce with the supplied dynamic_strided_slice module and relax.transform.FoldConstant(), then inspect the generated bindings and module functions. Done when speculative legalization no longer leaves a call_tir to an undefined shape_func, and the transformed module compiles with LLVM.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The following code:
import tvm
from tvm import relax
from tvm.script import ir as I
from tvm.script import relax as R
@I.ir_module
class Module:
@R.function
def main(
x: R.Tensor((8, 8), "float32"),
begin: R.Tensor((2,), "int64"),
end: R.Tensor((2,), "int64"),
strides: R.Tensor((2,), "int64"),
):
with R.dataflow():
gv = R.dynamic_strided_slice(x, begin, end, strides)
R.output(gv)
return gv
tvm.compile(Module, target="llvm") # OK
mod = relax.transform.FoldConstant()(Module)
mod.show() # leftover call_tir(Module.shape_func, ...) + match_cast bindings; no shape_func in the module
print([gv.name_hint for gv in mod.functions.keys()]) # ['main']
# relax.analysis.well_formed(mod) -> ValueError: GlobalVar Module.shape_func is not defined.
tvm.compile(mod, target="llvm")
# tvm.error.InternalError: Check failed: (it != functions.end()) is false: There is no definition of Module.shape_func
After FoldConstant:
with R.dataflow():
lv = R.call_tir(Module.shape_func, (x, begin, end, strides), ty_args=[R.Tensor((2,), dtype="int64")])
lv1: R.Shape(ndim=2) = R.tensor_to_shape(lv)
lv2: R.Shape([s, s_1]) = R.match_cast(lv1, R.Shape([s, s_1]))
gv: R.Tensor(dtype="float32", ndim=2) = R.dynamic_strided_slice(x, begin, end, strides)
R.output(gv)
Resulted in this output:
File "src/relax/ir/transform.cc", line 140, in tvm::relax::transform::FunctionPassObj::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
File "src/relax/transform/rewrite_dataflow_reshape.cc", line 166, in operator()
File "src/relax/transform/rewrite_dataflow_reshape.cc", line 159, in tvm::relax::RewriteDataflowReshape(tvm::relax::Function const&, tvm::IRModule const&)
File "src/relax/ir/expr_functor.cc", line 786, in tvm::relax::ExprMutator::VisitExpr_(tvm::relax::FunctionNode const*)
File "src/relax/ir/expr_functor.cc", line 828, in tvm::relax::ExprMutator::VisitExpr_(tvm::relax::SeqExprNode const*)
File "src/relax/transform/rewrite_dataflow_reshape.cc", line 67, in tvm::relax::DataflowReshapeRewriter::VisitBindingBlock(tvm::relax::BindingBlock const&)
File "src/relax/ir/expr_functor.cc", line 936, in tvm::relax::ExprMutator::VisitBindingBlock_(tvm::relax::DataflowBlockNode const*)
File "src/relax/ir/expr_functor.cc", line 851, in tvm::relax::ExprMutator::VisitBinding_(tvm::relax::VarBindingNode const*, tvm::GenericConstNode const*)
File "src/relax/transform/rewrite_dataflow_reshape.cc", line 94, in tvm::relax::DataflowReshapeRewriter::VisitExpr_(tvm::CallNode const*)
File "src/ir/module.cc", line 206, in tvm::BaseFunc tvm::IRModuleNode::Lookup(const tvm::GlobalVar&) const
tvm.error.InternalError: Check failed: (it != functions.end()) is false: There is no definition of Module.shape_func
There are two possible fixes. One is to run the speculative legalization in a scratch scope (a fresh BlockBuilder or a discarded binding block) and keep its bindings and PrimFuncs only when the call actually folds. The other is to skip the legalize attempt unless every tensor argument is a constant. Any legalizer that emits bindings (not only dynamic_strided_slice) can leak the same way. Related open FoldConstant/legalizer issues: #20192, #20193 (different symptom: reshape legalizer assertion on a runtime shape).
No GPU is needed (the original failure was on nvptx, but llvm fails the same way). Reproduces 3/3.
To reproduce:
python3 min.py
Commit:
apache/tvm 46a45c5f574360e69e312236cafda7e7eb48b440 (2026-10-11)
Build configuration:
config.cmake + USE_LLVM "llvm-config-18 --link-static", USE_LIBBACKTRACE ON, USE_SORT ON, USE_RANDOM ON,
USE_VULKAN ON, USE_KHRONOS_SPIRV /usr; cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo (gcc 11, lld)
Operating System:
Ubuntu 22.04.5 LTS (Docker image fusion-fuzz-tvm:latest), no GPU
- Ngôn ngữ chính
- Python
- Star
- 13.9k
- Fork
- 4k
- Merge trung bình
- 7 giờ 59 phút
- Pull request đã merge (30 ngày)
- 159
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/tvm
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] [Relax][ONNX] OneHot does not convert floating-point depth to int64Có thể đã có người làm @tandede đã nhận 2 ngày trước. Đang mởneeds-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug][Relax] ReorderTakeAfterMatmul fails on vector dot productsCó thể đã có người làm @hiyufan đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/tvm#20595 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
graphql-python/graphql-core#304 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs size:S
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Gathin23/cleanyourtv#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày