Skip to content

[Bug][Relax][ONNX] Split._impl_v13 rejects graph-initializer split operand under keep_params_in_input=True #20066

Description

@zacharywhitley

Summary

Split._impl_v13 errors on a splits operand that arrived as a
relax.Var bound to a graph initializer under
keep_params_in_input=True. The data is fully static; the isinstance
check is too strict.

Environment

TVM 0.25.0.post1 (pip), macOS arm64, Python 3.11.

Reproducer

Model: owensong/Inflect-Nano-v2 on Hugging Face (Apache-2.0).

import onnx, onnxsim
from tvm.relax.frontend.onnx import from_onnx

model = onnx.load("encoder.onnx")
model, _ = onnxsim.simplify(
    model,
    overwrite_input_shapes={"tokens": [1, 64], "lengths": [1], "length_scale": []},
)
mod = from_onnx(model, keep_params_in_input=True)  # the recommended path

Failure

ValueError: Dynamic Split not yet supported

At python/tvm/relax/frontend/onnx/onnx_frontend.py:2378.
Under keep_params_in_input=True, initializers become relax.Vars
rather than relax.Constants. The check
isinstance(splits, relax.Constant) fails even when the Var is
bound to a relax.const.

Suggested patch

Follow a Var back to its constant binding before the isinstance
check.

--- a/python/tvm/relax/frontend/onnx/onnx_frontend.py
+++ b/python/tvm/relax/frontend/onnx/onnx_frontend.py
@@ Split._impl_v13
+        # Under keep_params_in_input=True, splits may be a Var bound to a Constant.
+        if isinstance(splits, relax.Var):
+            binding = bb.lookup_binding(splits)
+            if isinstance(binding, relax.Constant):
+                splits = binding
         if not isinstance(splits, relax.Constant):
             raise ValueError("Dynamic Split not yet supported")

(bb.lookup_binding is illustrative — the exact spelling depends on
which builder API is in scope at that point in the frontend.)

User workaround

keep_params_in_input=False — initializers become relax.Constants
directly, satisfying the isinstance check. Trade-off: params fold
into the module body rather than being module-level Vars, changing
downstream analyses.

Discovered by

Compiling Inflect nano encoder from
cognition. See sibling
reports for two related bugs (bug 3 has no user workaround).

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