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

Aperta
#21,058 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@tandede ci sta già lavorando.

Dal 25/11/2026.

  • #21059 di @tandede — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
40/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
13.9k
Fork
4.1k
Merge medio
4g 22h
PR unite (30g)
22

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/tvm

Tutte le issue di apache/tvm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.