-
Notifications
You must be signed in to change notification settings - Fork 104
Description
split_predict pass generates an invalid ONNX model (missing tensor elem_type) — fails onnx.checker and cannot be loaded by ONNX Runtime
Describe the bug
Hi ONNX Optimizer maintainers, thanks for the project!
When optimizing a valid ONNX model named model.onnx using only the split_predict pass, the resulting model.opt.onnx becomes invalid ONNX. It fails onnx.checker.check_model() with:
onnx.onnx_cpp2py_export.checker.ValidationError: Field 'elem_type' of 'type' is required but missing.
and ONNX Runtime fails to load it:
onnxruntime.capi.onnxruntime_pybind11_state.Fail: ... failed: Invalid tensor data type 0.
This suggests the pass may be producing incomplete/incorrect type information (elem_type) for some tensor(s) in the optimized graph.
Environment
OS: Ubuntu 20.04 LTS
Python: 3.9.6
onnx: 1.19.0
onnxruntime: 1.19.2
onnxoptimizer: 0.3.13
To Reproduce
- Download and unzip the attached archive, then
cdinto the extracted directory
tar -xzvf split_predict_repro.tar.gz
cd split_predict_repro
- Create a Python environment (Python 3.9.6) and install dependencies:
python3.9 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements.txt
- Run the split_predict pass on the case model and save model.opt.onnx:
python optimize_model.py --case ./case_00051_seed20654888
This script loads model.onnx and runs optimizer.optimize(model, ["split_predict"]), then saves model.opt.onnx.
- Validate the optimized model with ONNX checker:
python ./check_model.py
check_model.py loads ./case_00051_seed20654888/model.opt.onnx and runs checker.check_model(m).
- Try to run the optimized model with ONNX Runtime using stored oracle inputs:
python ./run_optimized_model.py
This script creates an InferenceSession from ./case_00051_seed20654888/model.opt.onnx and feeds inputs from oracle.pkl.
Expected behavior
- model.opt.onnx should remain a valid ONNX model after split_predict optimization.
- onnx.checker.check_model() should pass.
- ONNX Runtime should be able to create an InferenceSession for model.opt.onnx.
Actual behavior
ONNX checker fails:
onnx.onnx_cpp2py_export.checker.ValidationError: Field 'elem_type' of 'type' is required but missing.
ONNX Runtime fails to load:
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model ... failed: Invalid tensor data type 0.
Attachments
I’m attaching:
- requirements.txt (dependency versions)
- optimize_model.py (runs split_predict and saves model.opt.onnx)
- check_model.py (runs ONNX checker on model.opt.onnx)
- run_optimized_model.py (loads model.opt.onnx via ORT and runs with oracle.pkl)
- the minimal failing folder ./case_00051_seed20654888 containing model.onnx, oracle.pkl, and the generated model.opt.onnx.
Thanks for your help!