zacharywhitley opened a new issue, #20066:
URL: https://github.com/apache/tvm/issues/20066
## 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).
```python
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`](https://github.com/apache/tvm/blob/main/python/tvm/relax/frontend/onnx/onnx_frontend.py).
Under `keep_params_in_input=True`, initializers become `relax.Var`s
rather than `relax.Constant`s. 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.
```diff
--- 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.Constant`s
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](https://github.com/tegmentum/cognition). See sibling
reports for two related bugs (bug 3 has no user workaround).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]