For integer division by zero, TVM should either handle the case safely or report a controlled runtime error instead of terminating the process with SIGFPE.
The model compiles successfully, but calling the Relax VM crashes the subprocess with exit code -8:
stdout: calling vm[main]
exit : -8
import subprocess
import sys
import textwrap
SCRIPT = textwrap.dedent("""\
import numpy as np
import onnx
from onnx import helper, TensorProto
import tvm
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx
node = helper.make_node("Div", ["a", "b"], ["y"])
graph = helper.make_graph(
[node],
"g",
[
helper.make_tensor_value_info("a", TensorProto.INT32, [4]),
helper.make_tensor_value_info("b", TensorProto.INT32, [4]),
],
[helper.make_tensor_value_info("y", TensorProto.INT32, [4])],
)
model = helper.make_model(
graph,
opset_imports=[helper.make_opsetid("", 18)],
)
model.ir_version = 9
mod = from_onnx(model, keep_params_in_input=False)
with tvm.transform.PassContext(opt_level=3):
ex = tvm.compile(mod, target=tvm.target.Target("llvm"))
vm = relax.VirtualMachine(ex, tvm.cpu())
a = np.array([42, 99, -50, 7], dtype=np.int32)
b = np.array([3, 0, 0, 1], dtype=np.int32)
print("calling vm[main]", flush=True)
out = vm["main"](
tvm.runtime.tensor(a, tvm.cpu()),
tvm.runtime.tensor(b, tvm.cpu()),
)
out = out[0] if isinstance(out, (list, tuple)) else out
print("returned:", out.numpy().tolist())
""")
proc = subprocess.run(
[sys.executable, "-c", SCRIPT],
capture_output=True,
text=True,
timeout=60,
)
print("stdout:", proc.stdout)
print("stderr:", proc.stderr)
print("exit :", proc.returncode)
Expected behavior
TVM Relax should not crash the Python process when executing an imported ONNX
Divmodel with integer inputs.For integer division by zero, TVM should either handle the case safely or report a controlled runtime error instead of terminating the process with
SIGFPE.Actual behavior
The model compiles successfully, but calling the Relax VM crashes the subprocess with exit code
-8:This happens when the divisor tensor contains zero values for an
INT32ONNXDivmodel.Environment
TVM: 0.14 environment / Relax ONNX frontend
Python: 3.11
Target: llvm
OS: Linux
Steps to reproduce
Triage