[Bug][Relax][ONNX] Runtime Tile repeats with a zero-extent input fail in from_onnx with Divide by zero

未关闭
#21,058 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@tandede 已经在做这个了。

开始于 2026年11月25日。

  • #21059 来自 @tandede —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
40/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
compilers

调研方向

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 内容生成。

描述

needs-triage type: bug

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, commit 3d89c4991c5a37492f470800231a5ea8f57a95c6, 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_tile and 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/tvm 的其他 Issue

查看 apache/tvm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。