[Bug][Relax][ONNX] Runtime Tile repeats with a zero-extent input fail in from_onnx with Divide by zero
维护者通常 3 天内回复
评估
调研方向
Start by running the reproducer, which calls from_onnx with shape_dict={"X": (0, 3)} and a runtime repeats input and fails with Divide by zero. The Tile converter in the Relax ONNX frontend calls topi.dyn_tile, defined in include/tvm/topi/transform.h, where the empty-output check misses a literal zero input extent and builds an indexmod by that extent. Done means import succeeds and yields an empty R.Tensor((0, 3)) result matching the expected shapes in the table.
由索引模型根据 Issue 内容生成。
描述
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
With float32 input X of shape [0, 3] and repeats supplied as an int64 graph input, Tile should produce an empty tensor. Each output dimension is the corresponding input dimension multiplied by its repeat count. ONNX Tile-13 specification
Independent controls for this exact model and input confirm the legal expected results (exact shape and dtype, float32):
| repeats | expected | numpy.tile |
ONNX ReferenceEvaluator | ORT CPU |
|---|---|---|---|---|
| [1, 1] | (0, 3) | (0, 3) | (0, 3) | (0, 3) |
| [2, 1] | (0, 3) | (0, 3) | (0, 3) | (0, 3) |
| [1, 0] | (0, 0) | (0, 0) | (0, 0) | (0, 0) |
Actual behavior
The model passes onnx.checker.check_model(model, full_check=True). When the static extent is made visible to the importer with shape_dict={"X": (0, 3)}, from_onnx aborts before any compilation:
RuntimeError: Check failed: pb->value != 0 (0 vs. 0) : Divide by zero
The failure occurs during import. Two controls isolate the combination of a static zero extent and runtime repeats.
| Case | X shape in Relax IR | from_onnx |
|---|---|---|
runtime repeats + shape_dict={'X': (0,3)} |
not produced (fails) | FAILED: Divide by zero |
runtime repeats, no shape_dict |
R.Tensor((v, 3)), v a shape var |
OK |
constant repeats initializer + shape_dict={'X': (0,3)} |
R.Tensor((0, 3)) |
OK |
The same exception was reproduced in two fresh Python processes.
Environment
- TVM
0.28.dev0, commit3d89c4991c5a37492f470800231a5ea8f57a95c6, LLVM 21.1.8, CPU - Linux x86-64 (WSL2), Python 3.10
- ONNX 1.21.0, ONNX Runtime 1.23.2, NumPy 1.26.4
- ONNX opset 13, IR version 8
Steps to reproduce
import numpy as np
import onnx
from onnx import TensorProto as T, helper as h
from onnx.reference import ReferenceEvaluator
from tvm.relax.frontend.onnx import from_onnx
node = h.make_node("Tile", ["X", "S"], ["Y"])
x = h.make_tensor_value_info("X", T.FLOAT, [0, 3])
s = h.make_tensor_value_info("S", T.INT64, [2]) # runtime repeats
y = h.make_tensor_value_info("Y", T.FLOAT, ["N", "M"])
graph = h.make_graph([node], "tile_zero", [x, s], [y])
model = h.make_model(graph, opset_imports=[h.make_opsetid("", 13)], ir_version=8)
onnx.checker.check_model(model, full_check=True)
X = np.zeros((0, 3), dtype=np.float32)
S = np.array([1, 1], dtype=np.int64)
print(ReferenceEvaluator(model).run(None, {"X": X, "S": S})[0].shape) # (0, 3)
# Forces the static zero extent to survive import instead of becoming a shape var:
from_onnx(model, shape_dict={"X": (0, 3)}, keep_params_in_input=False) # RuntimeError: Divide by zero
Additional context
The dynamic Tile converter calls topi.dyn_tile with symbolic output dimensions. Its empty-output check cannot resolve these dimensions to zero. It then constructs indexmod(indices[i], x->shape[i]), where the first input extent is the literal zero. The traceback ends in constant folding of this modulo expression. dyn_tile at the tested commit
Related issues
- #18752 concerns support for runtime Tile repeats. This reproducer reaches
topi.dyn_tileand fails when the input has a static zero extent. - #19922 also reports divide-by-zero with a zero-sized dimension, during compilation of a reshape from the PyTorch frontend. This reproducer fails while constructing the Tile expression during ONNX import.
Triage
- needs-triage
- 主要语言
- Python
- 星标
- 13.9k
- 派生
- 4.1k
- 平均合并
- 4 天 22 小时
- 30 天内合并 PR
- 22
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/tvm 的其他 Issue
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is None可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensors未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 3 天内回复
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradients可能已有人在做 @pierceluu10 于 5 天前认领。 未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputs可能已有人在做 @tandede 于 9 天前认领。 未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 3 天内回复
-
needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 92/100
Techiebutler/freeframe#687 ·
维护者通常 1 天内回复
-
bug verbose GC
难度 2/5 1-3 小时 新手友好度 74/100
IBM/javacore-analyser#677 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 2 天内回复
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
难度 2/5 1-3 小时 新手友好度 75/100
NousResearch/hermes-agent#163932 · 1 条评论 ·
维护者通常 1 天内回复
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's file可能已有人在做 @Beehtrix 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
zilliztech/memsearch#907 · 1 条评论 ·
维护者通常 1 天内回复