Skip to content

[Bug][Relax][ONNX] Split rejects valid zero-length outputs through repeated split boundaries #20848

Open

Description

@Yuhx141

Problem

An ONNX Split with explicit output lengths [1, 0, 2] and a nonempty three-element input passes full ONNX checking, ONNX Runtime CPU execution and the ONNX reference implementation. NumPy independently gives output lengths 1, 0 and 2. The Relax build instead fails with split_indices must be sorted. The all-empty [0, 0, 0] case fails similarly. The [1, 1, 1] control builds and runs.

ONNX Split-18 permits nonnegative explicit split lengths whose sum matches the input axis. The script checks both an empty input and a nonempty input containing an empty partition.

Minimal reproduction

Use an LLVM-enabled TVM environment with onnx==1.22.0, numpy==2.5.4 and onnxruntime==1.29.0. Save the following as repro.py and run:

OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 python repro.py

No downloaded model, private package or external input file is required. The script constructs and checks the models, saves the generated models/inputs under artifacts/, and asserts the observed failure as well as its controls. It exits successfully only when those checks reproduce the reported behavior.

from pathlib import Path
import hashlib
import numpy as np
import onnx
import onnxruntime as ort
import tvm
from onnx import TensorProto as T, helper as h, numpy_helper as nh
from onnx.reference import ReferenceEvaluator
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx


def make(nodes, inputs, outputs, initializers=(), opset=18):
    model = h.make_model(h.make_graph(nodes, "repro", inputs, outputs, list(initializers)),
                         opset_imports=[h.make_opsetid("", opset)], ir_version=10)
    onnx.checker.check_model(model, full_check=True)
    return model


def sources(model, feeds, expected):
    artifacts = Path("artifacts")
    artifacts.mkdir(exist_ok=True)
    identity = hashlib.sha256(model.SerializeToString()).hexdigest()
    onnx.save(model, artifacts / (identity + ".onnx"))
    np.savez(artifacts / (identity + "-inputs.npz"), **feeds)
    options = ort.SessionOptions()
    options.intra_op_num_threads = options.inter_op_num_threads = 1
    options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
    actual = ort.InferenceSession(model.SerializeToString(), options,
                                 providers=["CPUExecutionProvider"]).run(None, feeds)
    reference = ReferenceEvaluator(model).run(None, feeds)
    for values in (actual, reference):
        for a, b in zip(values, expected, strict=True):
            np.testing.assert_allclose(a, b, rtol=1e-5, atol=1e-6)


def tvm_run(model, feeds):
    mod = from_onnx(model, keep_params_in_input=False)
    names = [value.name for value in model.graph.input]
    executable = relax.build(mod, target="llvm", relax_pipeline="default")
    result = relax.VirtualMachine(executable, tvm.cpu())["main"](
        *[tvm.runtime.tensor(feeds[name]) for name in names])
    return [result.numpy()] if hasattr(result, "numpy") else [v.numpy() for v in result]


for parts in ([0, 0, 0], [1, 0, 2], [1, 1, 1]):
    x = np.arange(sum(parts), dtype="float32")
    expected = np.split(x, np.cumsum(parts)[:-1])
    model = make([h.make_node("Split", ["x", "parts"], ["a", "b", "c"], axis=0)],
                 [h.make_tensor_value_info("x", T.FLOAT, [len(x)])],
                 [h.make_tensor_value_info(name, T.FLOAT, [size])
                  for name, size in zip(("a", "b", "c"), parts)],
                 [nh.from_array(np.array(parts, dtype="int64"), "parts")])
    sources(model, {"x": x}, expected)
    print("parts", parts, "ORT/Reference/NumPy shapes", [a.shape for a in expected])
    try:
        actual = tvm_run(model, {"x": x})
    except Exception as error:
        assert 0 in parts and "split_indices must be sorted" in str(error), str(error)
        print("TVM", str(error).splitlines()[-1])
    else:
        assert 0 not in parts, "Reported failure did not reproduce"
        for a, b in zip(actual, expected, strict=True):
            np.testing.assert_array_equal(a, b)
        print("nonempty control passed")

Key output

parts [0, 0, 0] ORT/Reference/NumPy shapes [(0,), (0,), (0,)]
TVM Check failed: idx_node->value > back_node->value (0 vs. 0) : split_indices must be sorted
parts [1, 0, 2] ORT/Reference/NumPy shapes [(1,), (0,), (2,)]
TVM Check failed: idx_node->value > back_node->value (1 vs. 1) : split_indices must be sorted
parts [1, 1, 1] ORT/Reference/NumPy shapes [(1,), (1,), (1,)]
nonempty control passed

Causal analysis

The Split converter converts output lengths to cumulative split boundaries. A legal zero-length output necessarily produces a repeated boundary (or a boundary at zero). The TOPI split implementation requires each boundary to be strictly greater than the previous one. Thus the lowering imposes a stronger condition than the ONNX source contract. The adapter or underlying split implementation needs to preserve empty outputs rather than reject their boundaries.

Related work and discovery scope

#14660 reports a Relay DynamicToStatic failure of the even-division condition. This report uses explicit lengths including zero and reaches the different strict-order condition on repeated boundaries in Relax/TOPI. Targeted searches did not find an earlier report covering this mechanism.

The original observation came from a graph-testing workflow. The self-contained script above is a subsequently constructed minimal diagnostic, not a byte-identical replay of a historical generated model. No global novelty claim is made.

Environment

Linux x86_64 CPU, LLVM target; Python 3.12.3, TVM 0.28.dev0, ONNX 1.22.0, NumPy 2.5.4, ORT 1.29.0, tvm-ffi 0.1.14.post2.dev22+gdf463f9bd.

The exact source revision used to build the installed TVM binaries is unknown. The current-source links below are a separate static inspection at 2bf0532998d4dc7879cb342e873608b90c1d4497; that revision was not built or executed for this report. The observed runtime results refer to these loaded binary identities:

  • libtvm_compiler.so SHA256 574a573fe994e5eda7352ddd8d685e64e45c7934bdeeaab57a5a272a77792ab1
  • libtvm_runtime.so SHA256 4175916fc0ce6266c912629d2255094b94087425c6ab53ffd5e004d4c292c828
  • libtvm_runtime_extra.so SHA256 79c93351fca12dd7851964890cea7da65dd2b2e0e64e5c28bfed56c878b70817
  • libtvm_ffi.so SHA256 12072d0ccd9d5cb2c6dac80d42f4217ab50dbf795db03197000614a7a770a816

Reproducer SHA256: fbcdc04ff6a42ff38806da6828618167b32d37d2aca3d657ba8a4c36f7d49e90. Model and input hashes can be computed from the files saved by the script. No compiler/library rebuild or environment upgrade was used for the reported checks.

Activity

  1. dundysm commented on Oct 31, 2026

    @dundysm

    hi; i'd like to take this one. topi split requires strictly increasing indices, so a zero-length part trips the check. plan: in the onnx Split converter, when an explicit split has a zero-length part, emit one strided_slice per output instead of relax split (non-empty splits keep the current lowering); plus tests for [1, 0, 2] and an all-empty input. pr shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions