[Bug] ApproxLeastCommonMultiple hardcodes Int32, crashing has_reshape_pattern on int64 shapes above INT32_MAX elements
Maintainer thường phản hồi trong vòng 3 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
- 55/100
Hướng nghiên cứu
Start in src/arith/iter_affine_map.cc at ApproxLeastCommonMultiple, especially the IntImm::Int32 construction identified in the report. Trace the integer types through the LCM calculation and the callers PadDividendToDivisor and SplitFloorModConst. Reproduce with the provided int64 shape example using relax.analysis.has_reshape_pattern, then confirm it returns a bool without raising ValueError; also check RewriteDataflowReshape handles the case.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 😸
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.analysis.has_reshape_pattern and the RewriteDataflowReshape pass should handle well-formed modules containing large int64 tensor shapes without raising internal errors.
Specifically:
relax.analysis.has_reshape_pattern should return a bool.
RewriteDataflowReshape should either rewrite the call_tir or leave it unchanged.
Neither operation should raise an internal ValueError for a well-formed module using int64 shape extents.
Tensor dimensions and element counts exceeding INT32_MAX should not cause failures in arithmetic analysis when they are representable as int64.
Actual behavior
tvm::arith::ApproxLeastCommonMultiple constructs the least common multiple (LCM) as an int32 literal, even when its inputs and surrounding expressions use int64.
The problematic code is located at src/arith/iter_affine_map.cc:1768:
auto const_lcm = IntImm::Int32(LeastCommonMultiple(p1.second, p2.second));
LeastCommonMultiple returns int64_t, but its result is unconditionally wrapped in IntImm::Int32.
When the computed LCM exceeds the signed 32-bit integer range, the IntImm constructor raises a ValueError.
The failure is reachable through:
The public relax.analysis.has_reshape_pattern API.
The RewriteDataflowReshape pass in the default relax.build pipeline.
Error output:
File ".../python/tvm/relax/analysis/analysis.py", line 390, in has_reshape_pattern
return _ffi_api.has_reshape_pattern(func)
File ".../src/relax/analysis/tir_op_pattern_kind.cc", line 575, in HasReshapePattern
return ReshapeDetector::Detect(src_buffer, dst_buffer, func->body);
...
File ".../src/arith/iter_affine_map.cc", line 2139, in IterMapRewriter::Mutate_(FloorModNode)
PrimExpr remainder = SplitFloorModConst(preprocessed->args[0], preprocessed->base, b);
File ".../src/arith/iter_affine_map.cc", line 2088, in SplitFloorModConst
auto pair = PadDividendToDivisor(lhs, base, rhs);
File ".../src/arith/iter_affine_map.cc", line 1811, in PadDividendToDivisor
ApproxLeastCommonMultiple(info.padding_factor, divisor * split->lower_factor, analyzer_);
File ".../src/arith/iter_affine_map.cc", line 1768, in ApproxLeastCommonMultiple
auto const_lcm = IntImm::Int32(LeastCommonMultiple(p1.second, p2.second));
File ".../include/tvm/ir/expr.h", line 564, in IntImm::Int32
return IntImm(PrimType::Int(32), value, span);
File ".../src/ir/expr.cc", line 664, in IntImm::IntImm
TVM_FFI_CHECK_LT(value, 1LL << (bits - 1), ValueError)
ValueError: Check failed: value < 1LL << (bits - 1) (2147483648 vs. 2147483648) :
Literal value 2147483648 exceeds maximum of int32
The failure is deterministic and reproduces consistently (3/3 runs).
Environment
TVM version: 0.26.dev0
Commit: 8312a17f8734ddfd56e5f3977cd5df25b83ec49f
[REFACTOR][Arith] Evaluate iterator domains through Var maps (#20354)
2026-09-15
OS: Ubuntu 20.04.6 LTS
Kernel: 5.15.0-139-generic
Compiler: GCC 13.1.0
Target: llvm (host)
CPU: Intel Xeon Gold 6326
Build: Standard CMake build with USE_LLVM=ON
Steps to reproduce
The following minimal example reproduces the failure through the public relax.analysis.has_reshape_pattern API.
No tensor allocation is required. The failure occurs while analyzing the PrimFunc index expressions.
import tvm
from tvm.script import ir as I
from tvm.script import tirx as T
M = 2**31 # One element past INT32_MAX
@I.ir_module
class Module:
@T.prim_func(private=True, s_tir=True)
def copy_kernel(
src: T.Buffer((T.int64(M),), "float32"),
dst: T.Buffer((T.int64(M),), "float32"),
):
T.func_attr({"tirx.noalias": True})
for i in range(T.int64(M)):
with T.sblock("T_copy"):
v = T.axis.spatial(T.int64(M), i)
T.reads(src[v % T.int64(M)])
T.writes(dst[v])
dst[v] = src[v % T.int64(M)]
print(
tvm.relax.analysis.has_reshape_pattern(
Module["copy_kernel"]
)
)
Reproduction results:
Input shape: (2147483648,)
Shape dtype: int64
Tensor dtype: float32
Tensor allocation: Not required
Failure location: ApproxLeastCommonMultiple
Exception: ValueError
Reproducibility: 3/3 runs
The same failure was observed through the RewriteDataflowReshape pass during relax.build.
The first failing shape discovered by the fuzzer was:
Input shape: (62370, 1,Reproduction results:
Input shape: (2147483648,)
Shape dtype: int64
Tensor dtype: float32
Tensor allocation: Not required
Failure location: ApproxLeastCommonMultiple
Exception: ValueError
Reproducibility: 3/3 runs
The same failure was observed through the RewriteDataflowReshape pass during relax.build.
The first failing shape discovered by the fuzzer was:
Input shape: (62370, 1, 1, 62370)
Output shape: (3890016900,)
3890016900 = 62370^2
The element count exceeds the maximum signed 32-bit integer value:
INT32_MAX = 2147483647 1, 62370)
Output shape: (3890016900,)
3890016900 = 62370^2
The element count exceeds the maximum signed 32-bit integer value:
INT32_MAX = 2147483647
Triage
needs-triage
type: bug
- Ngôn ngữ chính
- Python
- Star
- 13.9k
- Fork
- 4.1k
- Merge trung bình
- 4 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 22
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
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NoneCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ 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 3 ngày
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsĐang mởneeds-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsCó thể đã có người làm @pierceluu10 đã nhận 5 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 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsCó thể đã có người làm @tandede đã nhận 9 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 70/100
Maintainer thường phản hồi trong vòng 3 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
apache/tvm#21043 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
Techiebutler/freeframe#687 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug verbose GC
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
IBM/javacore-analyser#677 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 2 ngày
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
NousResearch/hermes-agent#163932 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's fileCó thể đã có người làm @Beehtrix đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#907 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày