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).
Summary
Split._impl_v13errors on asplitsoperand that arrived as arelax.Varbound to a graph initializer underkeep_params_in_input=True. The data is fully static; theisinstancecheck is too strict.
Environment
TVM
0.25.0.post1(pip), macOS arm64, Python 3.11.Reproducer
Model:
owensong/Inflect-Nano-v2on Hugging Face (Apache-2.0).Failure
At
python/tvm/relax/frontend/onnx/onnx_frontend.py:2378.Under
keep_params_in_input=True, initializers becomerelax.Varsrather than
relax.Constants. The checkisinstance(splits, relax.Constant)fails even when theVarisbound to a
relax.const.Suggested patch
Follow a
Varback to its constant binding before the isinstancecheck.
(
bb.lookup_bindingis illustrative — the exact spelling depends onwhich builder API is in scope at that point in the frontend.)
User workaround
keep_params_in_input=False— initializers becomerelax.Constantsdirectly, 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).